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

Wrong schema generation of type in a Generic List Attribute #348

Open
CArOgNa opened this issue May 23, 2024 · 0 comments
Open

Wrong schema generation of type in a Generic List Attribute #348

CArOgNa opened this issue May 23, 2024 · 0 comments

Comments

@CArOgNa
Copy link

CArOgNa commented May 23, 2024

I have a trouble generating a schema for List property, i.e.:

        public string str { get; set; } = "";
        public List<string> strList { get; set; } = null; 

the generated schema is:

    "str": {
      "type": [
        "string",
        "null"
      ]
    },
    "strList": {
      "$id": "System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      }
    },

using this peace of code:
I generate the schema using this code:

            JSchemaGenerator generator = new JSchemaGenerator();
            generator.GenerationProviders.Add(new StringEnumGenerationProvider());
            generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.FullTypeName;
            return generator.Generate(type).ToString(Newtonsoft.Json.Schema.SchemaVersion.Draft2019_09);

The expected schema is something like this:

    "str": {
      "type": [
        "string",
        "null"
      ]
    },
    "strList": {
      "$id": "System.Collections.Generic.List`1[string]",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      }
    },

so is seems that type used in generic List attribute, the SchemaIdGenerationHandling.FullTypeName generator parameter is loosed and "SchemaIdGenerationHandling.AssemblyQualifiedName" used.

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