RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

How to use numeric discriminator value? #772

Open fubar-coder opened 5 years ago

fubar-coder commented 5 years ago

How can I use the JsonInheritanceConverter when I want to use numeric discriminator values? It seems that the JsonInheritanceConverter only supports string values.

RicoSuter commented 5 years ago

Does Swagger/OpenAPI even allow numeric discriminator values?

abbotware commented 4 years ago

I was about to ask if enums are supported

@RicoSuter - looks like it is supposed to be a string: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#discriminatorObject

FYI - I use EF Core and it allows a custom discriminators (https://docs.microsoft.com/en-us/ef/core/modeling/inheritance) I wind up making an this an enum for type safety

I was looking at carrying over this same enum into rest API models -

I think as far as inheritance in OpenAPI is concerned, you have to follow the spec - You can't try to control it (like you are able to in EF Core). Just let the nswag serializer implement the specification (assuming its correct)

RicoSuter commented 3 years ago

I'd expect that enum work with a StringEnumConverter