Open jafin opened 2 years ago
@jafin : Your update do not work if format: string
is not defined
for e.g. below case:
type: array
items:
type: string
I can confirm the issue @jafin is running into. It seems to be caused by https://github.com/OpenAPITools/openapi-generator/blob/807250a4300f3a4fed65f990e7055b34047222e1/modules/openapi-generator/src/main/resources/csharp/modelOneOf.mustache#L38
I believe we can fix this by removing the code within the isPrimitiveType
conditional block.
-this.ActualInstance = actualInstance{{^model.isNullable}}{{^isPrimitiveType}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isPrimitiveType}}{{#isPrimitiveType}}{{#isArray}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isArray}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isFreeFormObject}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isFreeFormObject}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isString}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isString}}{{/isPrimitiveType}}{{/model.isNullable}};
+this.ActualInstance = actualInstance{{^model.isNullable}}{{^isPrimitiveType}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isArray}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isArray}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isFreeFormObject}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isFreeFormObject}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isString}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isString}}{{/isPrimitiveType}}{{/model.isNullable}};
if anyone would like to contribute or sponsor a fix, please reply to let us know. thank you.
@wing328 I would like to. I'll ping you when I have a PR.
Bug Report Checklist
Description
A template that contains
oneOf
logic for a not nullable primitives generates invalid code.openapi-generator version
5.4 and ff7c2bdb591dd8fb6dd1c39dbe88367dbea4042d
OpenAPI declaration file content or url
Part of schema relating to this bug report:
Full schema: https://gist.github.com/jafin/5b06f1a09e8a8c983bf25d61c47c1f4e
Generation Details
Checking non nullable primitive for null.
existing (compile error)
for primitives should not have the conditional check, i.e.
XML Comments should be escaped to accomodate to Generic <> Types
existing
better
Getter for Generic Type has an invalid method name
existing (won't compile)
should maybe be:
Steps to reproduce
Generate csharp code:
Related issues/PRs
Suggest a fix