-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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][C#] Model properties are generated as non-nullable after 4.1.0 release #3725
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Note that this seems to be an issue for both the csharp and csharp-netcore generators |
@414004738 please try |
Hi @wing328. Thanks for the response. Manually adding |
PM me via Slack when you've time. |
Shouldn't the property also be DateRange:
type: object
properties:
start:
type: string
format: date-time
end:
type: string
format: date-time
required:
- start If the generated |
For reference, Autorest uses |
Is the change in behaviour a feature or bug? We're planning to move to the Thanks |
@rizwansaeed The previous implementation was based on OAS v2, which does not support nullable (later it's supported via x-nullable) |
@kevinoid no, I didn't say that. Please open a new issue with minimal spec to reproduce the issue as this issue refers to the change in the type: nullable by default to nullable depending on the |
Bug Report Checklist
Description
In version 4.0.3, when using an OpenAPI 2.0 input, model properties were generated as nullable. For example, see that the date-time property in the FormatTest class was generated as a DateTime? type in 4.0.3:
https://github.com/OpenAPITools/openapi-generator/blob/v4.0.3/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/FormatTest.cs#L172
But in 4.1.0, the same property is generated as a non-nullable DateTime type:
https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/FormatTest.cs#L172
This is a problem because if a service returns null for these properties in a response, the JSON deserialization fails.
Is there a way to generate nullable properties using an OpenAPI 2.0 input?
openapi-generator version
4.1.0
OpenAPI declaration file content or url
https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml#L1301
Command line used for generation
See https://github.com/OpenAPITools/openapi-generator/blob/v4.1.0/bin/csharp-petstore-netcore-project.sh#L30
Steps to reproduce
Look at the generated samples in Github for version 4.0.3 and 4.1.0 and compare the types of the properties in the generated models.
Related issues/PRs
I believe this may have been introduced by these pull requests:
#3530
#3537
Suggest a fix
I think the changes made in the above pull requests should only affect OpenAPI 3.0 generation.
The text was updated successfully, but these errors were encountered: