-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
System.Text.JSON polymorphic behaviour not supported #2571
Comments
Ideally, Swashbuckle would be able to infer what it needs from the new attributes. Currently, there's a need to duplicate
|
Eventually, i've made the NuGet package that solves my problem.
Obviously, the solution is not perfect as it requires knowledge about assemblies containing polymorphic contracts and obligates a developer to build hierarchy according to certain limitations. More information provided in repository of package: |
It's relatively straightforward to use |
@benlongo not really. We cannot specify the type of discriminator and map it to allowed values in some kind of enum with corresponding defaults. |
Well, STJ deserialization doesn't actually put the discriminator value into a property, so enum-valued type discriminators would be a thing of the past. The docs on customizing the type discriminator name also state:
Related issue: dotnet/runtime#72170 |
FYI This should work in DotSwashbuckle |
Beginning with .NET 7, System.Text.Json supports polymorphic type hierarchy serialization and deserialization with attribute annotations.
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism
But if we configure swagger to use polymorphism it does not add information about derived type to docs.
As I think, the problem is that [JsonDerivedType] adds implicit discriminator property which can be seen in json string only.
So, it is interesting to know the plans for support of this feature in library.
The text was updated successfully, but these errors were encountered: