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

Array of nullable enums has IsStringEnumArray set to false (C#) #1660

Open
bollhals opened this issue Jan 4, 2024 · 0 comments
Open

Array of nullable enums has IsStringEnumArray set to false (C#) #1660

bollhals opened this issue Jan 4, 2024 · 0 comments

Comments

@bollhals
Copy link

bollhals commented Jan 4, 2024

Hey

I have a schema which I use to generate C# classes out of it.
One issue that I observed was that a schema with an array property of a nullable string enum does not set the ItemConverterType = typeof(Newtonsoft.Json.Converters.StringEnumConverter), due to IsStringEnumArray returning false, which it does not when I remove the nullable part.

Examples:

...
"properties": {
    "Nullable": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "oneOf": [
          {
            "type": "null"
          },
          {
            "$ref": "MyEnumDefinition.json"
          }
        ]
      }
    },
    "NotNullable": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "$ref": "MyEnumDefinition.json"
      }
    }
}
...

In the search of what's wrong, I stumbled upon its sibling (IsStringEnum) which interesstingly is slightly differently implemented.

IsStringEnum => _property.ActualTypeSchema.IsEnumeration && _property.ActualTypeSchema.Type.IsString()
IsStringEnumArray => _property.ActualTypeSchema.Item.ActualSchema.IsEnumeration && _property.ActualTypeSchema.Item.ActualSchema.Type.IsString()

So the first one uses the ActualTypeSchema while the 2nd uses ActualSchema for the item. When I debugged it, I saw that if the latter would use the ActualTypeSchema of the Item, my usecase would work as expected.

Any idea why ActualSchema is used instead of ActualTypeSchema?

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