From d3212dbebaea544a53f2ff2c220abbe754f691bf Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Wed, 4 Jul 2018 17:56:44 +0200 Subject: [PATCH] Sanitize pipe in var name --- .../src/main/java/org/openapitools/codegen/DefaultCodegen.java | 3 +++ .../org/openapitools/codegen/java/AbstractJavaCodegenTest.java | 1 + 2 files changed, 4 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index eee5950de687..54636bd75b86 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3631,6 +3631,9 @@ public String sanitizeName(String name, String removeCharRegEx) { // input-name => input_name name = name.replaceAll("-", "_"); + // a|b => a_b + name = name.replace("|", "_"); + // input name and age => input_name_and_age name = name.replaceAll(" ", "_"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index a1203a02e389..63f655e85627 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -73,6 +73,7 @@ public void convertVarName() throws Exception { Assert.assertEquals(fakeJavaCodegen.toVarName("nam$$e"), "nam$$e"); Assert.assertEquals(fakeJavaCodegen.toVarName("user-name"), "userName"); Assert.assertEquals(fakeJavaCodegen.toVarName("user_name"), "userName"); + Assert.assertEquals(fakeJavaCodegen.toVarName("user|name"), "userName"); } @Test