Skip to content

Commit

Permalink
Fix csharp-netcore enum var name underscore handling (#8213)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbergen authored Jan 4, 2021
1 parent a812bf1 commit ee2f0e0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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+", "");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

This comment has been minimized.

Copy link
@cvgaviao

cvgaviao Jan 14, 2021

Hi @sbergen , you have introduced an issue here. Note that the package name is different from the location of the file.

it should be org.openapitools.codegen.csharpnetcore or you change the location to org.openapitools.codegen.csharp

This comment has been minimized.

Copy link
@sbergen

sbergen Jan 15, 2021

Author Contributor

Sorry, that was a copy-paste mistake, fix here: #8451


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");
}
}

0 comments on commit ee2f0e0

Please sign in to comment.