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
When an entity has a nullable enumeration member, the C# code generator creates a default constructor that requires a non-nullable value for the member. This produces an error during deserialization when the serialized entity has a null value: Cannot convert null value to <enumeration type> because the constructor requires a non-null value.
/// <summary>/// Gets or Sets Bean/// </summary>[DataMember(Name="bean",EmitDefaultValue=true)]publicCoffeeBean?Bean{get;set;}/// <summary>/// Initializes a new instance of the <see cref="CoffeeEntity" /> class./// </summary>/// <param name="bean">bean.</param>publicCoffeeEntity(CoffeeBeanbean=default(CoffeeBean)){this.Bean=bean;}
Expected output (note nullable type in constructor)
/// <summary>/// Gets or Sets Bean/// </summary>[DataMember(Name="bean",EmitDefaultValue=true)]publicCoffeeBean?Bean{get;set;}/// <summary>/// Initializes a new instance of the <see cref="CoffeeEntity" /> class./// </summary>/// <param name="bean">bean.</param>publicCoffeeEntity(CoffeeBean?bean=default(CoffeeBean?)){this.Bean=bean;}
It looks like the expected output can be achieved by setting the required property of the member metadata to false so that this line of the template appends the ? to the type name.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When an entity has a nullable enumeration member, the C# code generator creates a default constructor that requires a non-nullable value for the member. This produces an error during deserialization when the serialized entity has a null value:
Cannot convert null value to <enumeration type>
because the constructor requires a non-null value.openapi-generator version
openapi-generator-cli-4.2.3
OpenAPI declaration file content or url
https://gist.github.com/simonhaines/3cf34ff70d5bf75e7d3d7009bc6979b6
Command line used for generation
java -jar openapi-generator-cli-4.2.3.jar generate -i spec.json -g csharp-netcore
Steps to reproduce
Actual output (extract from CoffeeEntity.cs)
Expected output (note nullable type in constructor)
Related issues/PRs
Maybe #4816
Suggest a fix
It looks like the expected output can be achieved by setting the
required
property of the member metadata to false so that this line of the template appends the?
to the type name.The text was updated successfully, but these errors were encountered: