From ec5d15e12ff9301057097808cf90938698d94525 Mon Sep 17 00:00:00 2001 From: Sakari Bergen Date: Wed, 16 Dec 2020 15:10:19 +0200 Subject: [PATCH] Fix csharp-netcore enum var name underscore handling --- .../languages/CSharpNetCoreClientCodegen.java | 3 +- .../CSharpNetCoreClientCodegenTest.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpNetCoreClientCodegenTest.java diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java index 9d5691561591..12e3e15bb85d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java @@ -787,8 +787,7 @@ public String toEnumVarName(String value, String datatype) { } // string - String var = value.replaceAll("_", " "); - //var = WordUtils.capitalizeFully(var); + String var = value.replaceAll(" ", "_"); var = camelize(var); var = var.replaceAll("\\W+", ""); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpNetCoreClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpNetCoreClientCodegenTest.java new file mode 100644 index 000000000000..0d28f8f255a4 --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpNetCoreClientCodegenTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openapitools.codegen.csharp; + +import org.openapitools.codegen.languages.CSharpNetCoreClientCodegen; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class CSharpNetCoreClientCodegenTest { + + @Test + public void testToEnumVarName() throws Exception { + final CSharpNetCoreClientCodegen codegen = new CSharpNetCoreClientCodegen(); + codegen.processOpts(); + + Assert.assertEquals(codegen.toEnumVarName("FooBar", "string"), "FooBar"); + Assert.assertEquals(codegen.toEnumVarName("fooBar", "string"), "FooBar"); + Assert.assertEquals(codegen.toEnumVarName("foo-bar", "string"), "FooBar"); + Assert.assertEquals(codegen.toEnumVarName("foo_bar", "string"), "FooBar"); + Assert.assertEquals(codegen.toEnumVarName("foo bar", "string"), "FooBar"); + + // The below cases do not work currently, camelize doesn't support uppercase + // Assert.assertEquals(codegen.toEnumVarName("FOO-BAR", "string"), "FooBar"); + // Assert.assertEquals(codegen.toEnumVarName("FOO_BAR", "string"), "FooBar"); + } +}