Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: C# codegen does not generate all fields when using dependecies with oneOf #2562

Open
Chalolennox opened this issue Apr 13, 2024 · 0 comments
Labels

Comments

@Chalolennox
Copy link

Chalolennox commented Apr 13, 2024

Input Format: JSON Schema Draft 07

Output Language: C#

CLI, npm, or app.quicktype.io: app.quicktype.io
Version:

Description

when I combine dependecies keyword with oneOf keyword, some field are not generated in the output C# code.

Input Data

 {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Conditional Properties Example",
    "type": "object",
    "properties": {
        "acceptsTerms": {
            "type": "boolean",
            "title": "Do you accept the terms and conditions?"
        },
        "userDetails": {
            "type": "object",
            "properties": {
                "firstName": {
                    "type": "string",
                    "title": "First Name"
                },
                "lastName": {
                    "type": "string",
                    "title": "Last Name"
                },
                "email": {
                    "type": "string",
                    "format": "email",
                    "title": "Email Address"
                }
            },
            "required": [
                "firstName",
                "lastName",
                "email"
            ]
        }
    },
    "dependencies": {
        "acceptsTerms": {
            "oneOf": [
                {
                    "properties": {
                        "acceptsTerms": {
                            "const": true
                        },
                        "userDetails": {
                            "type": "object",
                            "properties": {
                                "comment": {
                                    "type": "string",
                                    "title": "comment"
                                }
                            }
                        }
                    },
                    "required": [
                        "userDetails"
                    ]
                },
                {
                    "properties": {
                        "acceptsTerms": {
                            "const": false
                        }
                    }
                }
            ]
        }
    }
} 

Expected Behaviour / Output

Property "Comment" should be inserted

// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var test = Test.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class Test
    {
        [JsonProperty("acceptsTerms", NullValueHandling = NullValueHandling.Ignore)]
        public virtual bool? AcceptsTerms { get; set; }

        [JsonProperty("userDetails", NullValueHandling = NullValueHandling.Ignore)]
        public virtual UserDetails UserDetails { get; set; }
    }

    public partial class UserDetails
    {
        [JsonProperty("email")]
        public virtual string Email { get; set; }

        [JsonProperty("firstName")]
        public virtual string FirstName { get; set; }

        [JsonProperty("lastName")]
        public virtual string LastName { get; set; }

        [JsonProperty("comment")]
        public virtual string Comment { get; set; }

    }

    public partial class Test
    {
        public static Test FromJson(string json) => JsonConvert.DeserializeObject<Test>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this Test self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }

    ............
}

Current Behaviour / Output

Property "Comment" is missing.

// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var test = Test.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class Test
    {
        [JsonProperty("acceptsTerms", NullValueHandling = NullValueHandling.Ignore)]
        public virtual bool? AcceptsTerms { get; set; }

        [JsonProperty("userDetails", NullValueHandling = NullValueHandling.Ignore)]
        public virtual UserDetails UserDetails { get; set; }
    }

    public partial class UserDetails
    {
        [JsonProperty("email")]
        public virtual string Email { get; set; }

        [JsonProperty("firstName")]
        public virtual string FirstName { get; set; }

        [JsonProperty("lastName")]
        public virtual string LastName { get; set; }
    }

    public partial class Test
    {
        public static Test FromJson(string json) => JsonConvert.DeserializeObject<Test>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this Test self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }
    ............
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant