[BUG] [csharp-netcore] Invalid expressions are generated using ??
Created by: vaindil
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
The csharp-netcore generator generates invalid C# if an enum is set as required in a definition. With the enum property name present in the "required" object inside the definition of ObjectCreateArgs
, the C# below is generated as a constructor for ObjectCreateArgs
:
public ObjectCreateArgs(ObjectType objectType = default(ObjectType))
{
// to ensure "objectType" is required (not null)
this.ObjectType = objectType ?? throw new ArgumentNullException("snip");;
}
This is invalid C# because objectType
is not nullable, therefore the null coalescing operator can't be used with it.
openapi-generator version
4.2.3
OpenAPI declaration file content or url
Click here (rename extension to .json)
Command line used for generation
java -jar openapi-generator-cli.jar generate -i swagger.json -g csharp-netcore -o test-csharp
Steps to reproduce
Run the above command.
Suggest a fix
Enums are not nullable unless declared with ?
like other types, so they should be treated as such.