From 419ee1cc79f372d6ac8a66c888179c2e44178e1d Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 25 Sep 2017 15:23:27 +0800 Subject: [PATCH] Add class prefix to tag with numbers (#6561) * add class prefix to tag with numbers, update java to default tag name * update codegen test --- .../src/main/java/io/swagger/codegen/DefaultCodegen.java | 2 +- .../io/swagger/codegen/languages/AbstractJavaCodegen.java | 5 ----- .../src/test/java/io/swagger/codegen/CodegenTest.java | 3 ++- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 61a4dc1ba61..aa3c3f318a9 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -3502,7 +3502,7 @@ public String sanitizeTag(String tag) { // tag starts with numbers if (tag.matches("^\\d.*")) { - tag = "_" + tag; + tag = "Class" + tag; } return tag; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java index 13310ecc5c3..64460b2f5fc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java @@ -1229,11 +1229,6 @@ public void writePropertyBack(String propertyKey, boolean value) { additionalProperties.put(propertyKey, value); } - @Override - public String sanitizeTag(String tag) { - return camelize(sanitizeName(tag)); - } - /** * Output the Getter name for boolean property, e.g. isActive * diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index ef54ec0fc79..53adbaea006 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -17,11 +17,12 @@ public class CodegenTest { public void sanitizeTagTest() { final DefaultCodegen codegen = new DefaultCodegen(); Assert.assertEquals(codegen.sanitizeTag("foo"), "Foo"); + Assert.assertEquals(codegen.sanitizeTag("$foo!"), "Foo"); Assert.assertEquals(codegen.sanitizeTag("foo bar"), "FooBar"); Assert.assertEquals(codegen.sanitizeTag("foo_bar"), "FooBar"); Assert.assertEquals(codegen.sanitizeTag("foo1 bar2"), "Foo1Bar2"); Assert.assertEquals(codegen.sanitizeTag("foo bar 1"), "FooBar1"); - Assert.assertEquals(codegen.sanitizeTag("1foo"), "_1foo"); + Assert.assertEquals(codegen.sanitizeTag("1foo"), "Class1foo"); } @Test(description = "test camelize")