-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
[BUG] ELM: C# 8 nullable feature creates uncompilable (Maybe OneOf<PContactInfo>) #4450
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Notice that
|
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. Two questions:
For now using |
The OneOf is generated by NSwag. I added this question there. |
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. |
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> |
Hi All, @mattiasw2 did you maybe find some workaround for that? |
@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. |
@mattiasw2 thanks, It seems like a more complex discussion, i.e. whether referenced objects can have nullable prop on the same level. See #5180 |
Bug Report Checklist
No, it is the complete swagger.json
Yes
4.2.0
Yes.
Description
As of C# 8, nullable references types have an anotation '?', and unless it is there, the reference cannot be null.
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
I have a plain DTO like this,
and the problem is
It is actually exactly the same as
in C# 7 and earlier, i.e. since there is no [Required], that field can be null.
openapi-generator version
4.2.0
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-4.2.0.jar generate -g elm -i swagger.json -o src/Swagger/
Steps to reproduce
Just generate and look at the code. There is a warning for another problem,
swagger.zip
[main] INFO o.o.codegen.DefaultGenerator - Model ExcelFormattingBase not generated since it's a free-form object
but you can ignore that. I can simplify those objects.
Suggest a fix
Just make it be treated as if neither ? or [Required] is not there.
The text was updated successfully, but these errors were encountered: