You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The nullable mark ? is the problem. I removed it, and the swagger.json file lost the following. So, for now, I will just make sure I do not use that annotation in my DTO classes.
Thanks for your report @mattiasw2. oneOf is currently not yet supported, see #4434. However, I checked it and it does not work when the oneOf is inline in that PR. You would have to create a new schema in components for it.
Two questions:
Why do you actually need a oneOf here. You only have one case;
Is there a reason you use nullable instead of required here?
When I look at the specification of OneOf at https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/ it seems to me that adding a OneOf with just one option is useless. I think in this case, you can just remove the OneOf and replace the expression by the single $ref inside.
Yes exactly. That's why I wonder why it is generated like take. Nevertheless it should work though. It should create a custom type with only one variant.
@pekunicki I choose to not use the C# 8 nullable feature in my API. The reason I created this ticket is that Typescript handled it, and in the long-term I want ELM to support it too, since for a language like ELM, not-nullable is really important and useful.
Activity
auto-labeler commentedon Nov 11, 2019
👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
mattiasw2 commentedon Nov 11, 2019
Notice that
string?are correctly handled:mattiasw2 commentedon Nov 11, 2019
The nullable mark ? is the problem. I removed it, and the swagger.json file lost the following. So, for now, I will just make sure I do not use that annotation in my DTO classes.
eriktim commentedon Nov 12, 2019
Thanks for your report @mattiasw2.
oneOfis currently not yet supported, see #4434. However, I checked it and it does not work when theoneOfis inline in that PR. You would have to create a new schema in components for it.Two questions:
oneOfhere. You only have one case;nullableinstead ofrequiredhere?For now using
nullableand$refshould work.mattiasw2 commentedon Nov 13, 2019
The OneOf is generated by NSwag. I added this question there.
RicoSuter/NSwag#2435
mattiasw2 commentedon Nov 13, 2019
When I look at the specification of OneOf at https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/ it seems to me that adding a OneOf with just one option is useless. I think in this case, you can just remove the OneOf and replace the expression by the single $ref inside.
eriktim commentedon Nov 16, 2019
Yes exactly. That's why I wonder why it is generated like take. Nevertheless it should work though. It should create a custom type with only one variant.
mattiasw2 commentedon Nov 16, 2019
I think Rico from Nswag has says it should look like this, but I am not sure.
Currently, your generated code will be non-compilable, since the name of the type name includes & and ;
OneOf<PContactInfo>
pekunicki commentedon Mar 18, 2020
Hi All, @mattiasw2 did you maybe find some workaround for that?
This oneOf for one nullable referenced object is slightly confusing.
mattiasw2 commentedon Mar 18, 2020
@pekunicki I choose to not use the C# 8 nullable feature in my API. The reason I created this ticket is that Typescript handled it, and in the long-term I want ELM to support it too, since for a language like ELM, not-nullable is really important and useful.
pekunicki commentedon Mar 19, 2020
@mattiasw2 thanks, It seems like a more complex discussion, i.e. whether referenced objects can have nullable prop on the same level. See #5180