[BUG][CSHARP-NETCORE] OneOf generator for not nullable primitives generates invalid code.
Created by: jafin
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request
Description
A template that contains oneOf
logic for a not nullable primitives generates invalid code.
openapi-generator version
5.4 and ff7c2bdb
OpenAPI declaration file content or url
Part of schema relating to this bug report:
PolymorphicProperty:
oneOf:
- type: boolean
- type: string
- type: object
- type: array
items:
$ref: '#/components/schemas/StringArrayItem'
StringArrayItem:
type: string
format: string
Full schema: https://gist.github.com/jafin/5b06f1a09e8a8c983bf25d61c47c1f4e
Generation Details
Checking non nullable primitive for null.
existing (compile error)
public PolymorphicProperty(bool actualInstance)
{
//...
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
for primitives should not have the conditional check, i.e.
public PolymorphicProperty(bool actualInstance)
{
//...
this.ActualInstance = actualInstance;
}
XML Comments should be escaped to accomodate to Generic <> Types
existing
/// <summary>
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
/// with the <see cref="List<string>" /> class
/// </summary>
/// <param name="actualInstance">An instance of List<string>.</param>
better
/// <summary>
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
/// with the <see cref="List<string>" /> class
/// </summary>
/// <param name="actualInstance">An instance of List<string>.</param>
Getter for Generic Type has an invalid method name
existing (won't compile)
public List<string> GetList<string>()
should maybe be:
public List<string> GetListString()
Steps to reproduce
Generate csharp code:
java -jar openapi-generator-cli.jar generate -i firefly-iii-1.5.5.yaml -g csharp-netcore --library httpclient