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

AdditionalProperties is generated both as bool and Dictionary #1459

Open
AnderssonPeter opened this issue Dec 9, 2021 · 9 comments
Open

Comments

@AnderssonPeter
Copy link

AnderssonPeter commented Dec 9, 2021

Hi when generating classes for this schema it generates the class Andelisamfallighet with the following

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.6.2.0 (Newtonsoft.Json v9.0.0.0)")]

    public partial record Andelisamfallighet
    {

        [System.Text.Json.Serialization.JsonPropertyName("title")]
        public string Title { get; set; } = default!;


        [System.Text.Json.Serialization.JsonPropertyName("type")]
        public string Type { get; set; } = default!;


        [System.Text.Json.Serialization.JsonPropertyName("properties")]
        public Anonymous81 Properties { get; set; } = default!;


        [System.Text.Json.Serialization.JsonPropertyName("not")]
        public Geometrirequest Not { get; set; } = default!;


        [System.Text.Json.Serialization.JsonPropertyName("additionalProperties")]
        public bool AdditionalProperties { get; set; } = default!;



        private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();

        [System.Text.Json.Serialization.JsonExtensionData]
        public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
        {
            get { return _additionalProperties; }
            set { _additionalProperties = value; }
        }

    }

And using the following settings:

{
        Namespace = @namespace,
        ClassStyle = CSharpClassStyle.Poco,
        JsonLibrary = CSharpJsonLibrary.SystemTextJson,
        GenerateNativeRecords = true,
        GenerateNullableReferenceTypes = true,
    }

As you can see AdditionalProperties is generated twice, and this causes a compilation error.

Is the schema invalid or does the generator do something invalid?

@RicoSuter
Copy link
Owner

Looks strange, it's treating schema properties as actual model properties.. I think the schema is wrong... but needs investigation.

@AnderssonPeter
Copy link
Author

I'm not that familiar with json schemas but using https://jsonschemalint.com/#!/version/draft-07/markup/json it validates if i change from $schema to schema, could that be the source of the issue?

@AnderssonPeter
Copy link
Author

Changing from $schema to schema didn't change anything.

@RicoSuter
Copy link
Owner

could that be the source of the issue?

NJsonSchema does not really care for the content of the "schema" property.

RicoSuter added a commit that referenced this issue Dec 10, 2021
@AnderssonPeter
Copy link
Author

If you tell me when you build a new nuget package, ill verify that it works as intended.

Thanks for the fast fix!!

@RicoSuter
Copy link
Owner

RicoSuter commented Dec 10, 2021

Not sure this is actually the fix, but this was another problem with this schema...
You can try with the preview nuget feed (v11 preview) https://www.myget.org/feed/Packages/njsonschema

@AnderssonPeter
Copy link
Author

I have no idea how to use myget, I tried to add <add key="NJsonSchema MyGet" value="https://www.myget.org/F/njsonschema/api/v3/index.json" /> to my nuget.config, but I find no packages in that feed.

@AnderssonPeter
Copy link
Author

AnderssonPeter commented Dec 13, 2021

Checked out the repo and changed branch to patches/fix-toolchain-version-output and tried it that way, but as you said it didn't resolve the issue.

One small question how do I use a JsonInheritanceConverter when generating code, I'm guessing that my output would be better if it would use the field/property Type and typ as discriminator..

@AnderssonPeter
Copy link
Author

Found #13 guessing that without that implemented the output of this schema will always be subpar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants