Closed crystalcodesoftware closed 6 years ago
Sorry, itchy fingers.
Currently there is no way to achieve this. If the converter does not exist, then the discriminator property is not set, however, inheritance should be generated if the base type is used somewhere. It should be simple to externally define a discriminator...
Just checked this. If you enable GenerateKnownTypes then all required schemas should be generated. The problem is however that the "discriminator" property is missing so the (generated) deserializer does not know how to determine the actual type.
To completely fix this, we have two problems:
Interesting. Unless I'm mistaken, I don't believe the generated schema contained type information about the derived types; I'll have to have another look though.
I'm going to play with this a bit more and determine concretely where I found it breaking down on my end. A global JsonInheritanceConverter
was sort of what I was thinking (though perhaps not "global", so much as DI managed)
I've added this capability, just check the unit tests... The new DiscriminatorSchemaProcessor can only be defined in code. Currently it's not possible to define it in NSwagStudio
I asked a question on Stack Overflow pertaining to this issue, and I've drilled through the source, but I can't find anywhere a feature/workaround for this exists.
A quick copy/paste from the question:
Is there a way to retrofit closed types with
[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")]
?