From 4e82b74cd5aa71ff7b3bb8fd20c63bee6f12de3f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 10 Apr 2022 09:37:09 +0800 Subject: [PATCH] fix warning in cref for list (#12096) --- .../codegen/languages/AbstractCSharpCodegen.java | 15 +++++++++++++++ .../resources/csharp-netcore/modelAnyOf.mustache | 2 +- .../resources/csharp-netcore/modelOneOf.mustache | 4 ++-- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- .../Org.OpenAPITools/Model/PolymorphicProperty.cs | 2 +- 9 files changed, 24 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index c0c24b50e4e..bc39b898fa8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -19,6 +19,8 @@ package org.openapitools.codegen.languages; import com.google.common.collect.ImmutableMap; import com.samskivert.mustache.Mustache.Lambda; +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; @@ -36,6 +38,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.io.Writer; import java.util.*; import static org.openapitools.codegen.utils.StringUtils.camelize; @@ -399,6 +402,18 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co // This either updates additionalProperties with the above fixes, or sets the default if the option was not specified. additionalProperties.put(CodegenConstants.INTERFACE_PREFIX, interfacePrefix); + + // add lambda for mustache templates + additionalProperties.put("lambdaCref", new Mustache.Lambda() { + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + String content = fragment.execute(); + content = content.trim().replace("<", "{"); + content = content.replace(">", "}"); + content = content.replace("{string}", "{String}"); + writer.write(content); + } + }); } @Override 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 f216a991130..d889a3e1fda 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/modelAnyOf.mustache @@ -19,7 +19,7 @@ {{#anyOf}} /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of {{{.}}}. public {{classname}}({{{.}}} actualInstance) diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/modelOneOf.mustache index 2a22ad49259..272b6cf9318 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/modelOneOf.mustache @@ -21,7 +21,7 @@ {{^isNull}} /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of {{dataType}}. public {{classname}}({{{dataType}}} actualInstance) @@ -277,4 +277,4 @@ return false; } } -{{/model}} \ No newline at end of file +{{/model}} diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 553857009b3..0ce4e18eb2e 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 383dcdde859..4e8c938e2e9 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -73,7 +73,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 553857009b3..0ce4e18eb2e 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 553857009b3..0ce4e18eb2e 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 553857009b3..0ce4e18eb2e 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/PolymorphicProperty.cs index 553857009b3..0ce4e18eb2e 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/PolymorphicProperty.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/PolymorphicProperty.cs @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Model /// /// Initializes a new instance of the class - /// with the class + /// with the class /// /// An instance of List<string>. public PolymorphicProperty(List actualInstance)