From 1d8051e85774bb03cf3a4f7e0dafe4e46f1b782c Mon Sep 17 00:00:00 2001 From: Ikelio Date: Wed, 24 Aug 2022 18:32:36 +0200 Subject: [PATCH] fix: [csharp-netcore]: anyOf fixes for Primitive types (#13172) * fixed null-coalescing operator incorrectly used for primitive types with the same change than @jafin in https://github.com/OpenAPITools/openapi-generator/pull/11427 --- .../csharp-netcore/modelAnyOf.mustache | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache index a808b9c161a..7e318b309c9 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache @@ -1,3 +1,4 @@ +{{#model}} /// /// {{description}}{{^description}}{{classname}}{{/description}} /// @@ -22,20 +23,22 @@ } {{/isNullable}} - {{#anyOf}} + {{#composedSchemas.anyOf}} + {{^isNull}} /// /// Initializes a new instance of the class - /// with the class + /// with the class /// - /// An instance of {{{.}}}. - public {{classname}}({{{.}}} actualInstance) + /// An instance of {{dataType}}. + public {{classname}}({{{dataType}}} actualInstance) { - this.IsNullable = {{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}; + this.IsNullable = {{#model.isNullable}}true{{/model.isNullable}}{{^model.isNullable}}false{{/model.isNullable}}; this.SchemaType= "anyOf"; - this.ActualInstance = actualInstance{{^isNullable}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isNullable}}; + 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}}; } - {{/anyOf}} + {{/isNull}} + {{/composedSchemas.anyOf}} private Object _actualInstance; @@ -62,18 +65,20 @@ } } } - {{#anyOf}} + {{#composedSchemas.anyOf}} + {{^isNull}} /// - /// Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`, + /// Get the actual instance of `{{dataType}}`. If the actual instance is not `{{dataType}}`, /// the InvalidClassException will be thrown /// - /// An instance of {{{.}}} - public {{{.}}} Get{{{.}}}() + /// An instance of {{dataType}} + public {{{dataType}}} Get{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}{{#isArray}}{{#lambda.titlecase}}{{{dataFormat}}}{{/lambda.titlecase}}{{/isArray}}() { - return ({{{.}}})this.ActualInstance; + return ({{{dataType}}})this.ActualInstance; } - {{/anyOf}} + {{/isNull}} + {{/composedSchemas.anyOf}} /// /// Returns the string presentation of the object @@ -233,3 +238,4 @@ return false; } } +{{/model}} \ No newline at end of file