Bug Report Checklist
Description
When using the csharp-netcore generator, OpenAPI Generator will generate code that uses null as the default value for enum parameters. null is not a valid value for enums in C#.
It should instead generate default operator applied to the enum type, e.g., default(MyEnum). This is the behavior when using the csharp generator. (The default literal could be used, but is only available from C# 7.1.)
openapi-generator version
Version 4.2.0. (Also recreated in 4.1.3, 4.1.0, 4.0.3, and 4.0.0.)
OpenAPI declaration file content or url
https://gist.github.com/kimsey0/fe44536ff332ded4cf1346dfc0449888
Command line used for generation
npx -p @openapitools/[email protected] openapi-generator generate -i ./nullenumbug.json -g csharp-netcore -o ./nullenumbug
Steps to reproduce
- Create a OpenAPI declaration file containing an endpoint with a parameter of type
string with enum values.
- Run OpenAPI Generator with this file as input and using the csharp-netcore generator.
- Try to compile the output.
- Observe the compile errors of the type:
Error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'MyEnum' (39, 31)
Related issues/PRs
Suggest a fix
Bug Report Checklist
Description
When using the csharp-netcore generator, OpenAPI Generator will generate code that uses
nullas the default value for enum parameters.nullis not a valid value for enums in C#.It should instead generate
defaultoperator applied to the enum type, e.g.,default(MyEnum). This is the behavior when using the csharp generator. (Thedefaultliteral could be used, but is only available from C# 7.1.)openapi-generator version
Version 4.2.0. (Also recreated in 4.1.3, 4.1.0, 4.0.3, and 4.0.0.)
OpenAPI declaration file content or url
https://gist.github.com/kimsey0/fe44536ff332ded4cf1346dfc0449888
Command line used for generation
npx -p @openapitools/[email protected] openapi-generator generate -i ./nullenumbug.json -g csharp-netcore -o ./nullenumbugSteps to reproduce
stringwithenumvalues.Error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'MyEnum' (39, 31)Related issues/PRs
Suggest a fix