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

AllowAdditionalProperties - not working #1689

Open
careless6666 opened this issue Apr 4, 2024 · 0 comments
Open

AllowAdditionalProperties - not working #1689

careless6666 opened this issue Apr 4, 2024 · 0 comments

Comments

@careless6666
Copy link

i have a sample model

public class RootConfig
{
    /// <summary>
    /// Configure s2s options
    /// </summary>
    public S2SOptions S2SAuth { get; set; }    
    }

and code for generation

public class Program
{
    public static void Main(string[] args)
    {
        // var generator = new JsonSchemaGenerator(new SystemTextJsonSchemaGeneratorSettings());
        // var schema = generator.Generate(typeof(S2SOptions));
        // Console.WriteLine(schema.ToJson());

        var settings = new SystemTextJsonSchemaGeneratorSettings()
        {

        };
        var schema = new JsonSchema
        {
            AllowAdditionalProperties = true
        }; 
        var resolver = new JsonSchemaResolver(schema, settings); // used to add and retrieve schemas from the 'definitions'
        var generator = new JsonSchemaGenerator(settings);

        generator.Generate(schema, typeof(RootConfig), resolver); // generate root schema

        Console.WriteLine(schema.ToJson());
        File.WriteAllText("platformSchema.json", schema.ToJson());
    }
}

It is generate json schema with additionalProperties:false on root, but i expected that it will be true

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "RootConfig",
  "type": "object",
  "description": "Common class with contains all json configurable options",
  "additionalProperties": false,
  "properties": {
    "S2SAuth": {
      "description": "Configure s2s options",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/definitions/S2SOptions"
        }
      ]
    },
...

How set up true for additionalProperties on top level?

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

1 participant