RicoSuter / NJsonSchema

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

Polymorphic Schema Generation #1706

Open Yoztastic opened 2 months ago

Yoztastic commented 2 months ago

https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance

Using System.Text.Json

[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")] as advised above does not compile for the reason JsonConverter constructor takes a single parameter.

It appears more likely it should be something like

[JsonInheritanceConverter(typeof(MyInheritingType), "discriminator")]

However this does not have the desired effect the schema only includes the base type

"$ref": "#/components/schemas/MyBaseType"

Where I would be expecting

"oneOf": [ { "$ref": "#/components/schemas/MyInheritingType" } ]

Or something similar.

Does https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance still represent upto data documentation?

Is there something else I need to get this to work?

BTW I am using NJsonSchema transitively Via FastEndpoints and using .net8.