[BUG] [csharp-netcore] Generating invalid null default values for enum parameters in API
Created by: kimsey0
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
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/openapi-generator-cli@cli-4.2.0 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
withenum
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)