-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
[NSwag 14/NJsonSchema11] JsonPolymorhic/JsonDerivedType TypeDiscriminatorPropertyName with enum/int values breaks #1666
Comments
Is the following the property that you want to assign the discriminator value to? public EDocumentItemType DocumentItemType { get; } System.Text.Json, by design, cannot map discriminator values to runtime properties. There is an open proposal, however. The System.Text.Json docs explicitly state:
Effectively this issue is blocked until dotnet/runtime#91274 is implemented. Until then enum-valued type discriminators with System.Text.Json are not possible. |
Thanks @schnerring for replying 🙏 In NSwag13, and in .Net 7 this is supported. I do agree on your reading that the NJsonSchema/src/NJsonSchema.Tests/Generation/SystemTextJson/SystemTextJsonInheritanceTests.cs Line 79 in 3585d60
JsonDerivedType is a string. The integer option is not tested
The other solution is trying to revert back to our custom deserializer middleware. |
That would probably be a good issue. ;)
I'll have to rebase my STJ PR #1595, and will have a look if it's possible to support integers, too. |
I'm not 100% sure, but I think we could support integer type discriminators using OpenAPI specification extensions, which is how it's currently done for enums when using Newtonsoft.Json. By default, the discriminator mapping field is of type |
since you've created a new PR, did you check it in #1675 too? |
No, it was out of scope for that PR. |
just tested this with 14.1.0/11.0.2 and this problem nswag version and this problem persists. |
Expected Behavior
A derived class with a custom
TypeDiscriminator
property name, which is based on anenum
(therefore the cast will be of typeint
) will be cast properly in nswagin NSwag 13.2.0, this is generated properly:
Actual Behavior
when this is trying to be generated with nswag 14, this is resulting in the following error:
Steps to Reproduce the Problem
the test here (
NJsonSchema/src/NJsonSchema.Tests/Generation/SystemTextJson/SystemTextJsonInheritanceTests.cs
Line 80 in 3585d60
Specifications
The text was updated successfully, but these errors were encountered: