diff --git a/.secrets.baseline b/.secrets.baseline index c530710..d360059 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -75,7 +75,18 @@ "name": "TwilioKeyDetector" } ], - "results": {}, + "results": { + "certificates/ibminter.pem": [ + { + "hashed_secret": "b3723414cb4a90ac8c2bc504ea01923fe5fccc8a", + "is_secret": false, + "is_verified": false, + "line_number": 28, + "type": "Artifactory Credentials", + "verified_result": null + } + ] + }, "version": "0.13.1+ibm.62.dss", "word_list": { "file": null, diff --git a/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestAnEnumProperty.java b/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestAnEnumProperty.java index b442e7c..caf374b 100644 --- a/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestAnEnumProperty.java +++ b/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestAnEnumProperty.java @@ -23,7 +23,7 @@ public void TestCanSerialiseTheEnumWithValue1() throws Exception { BeanWithEnumPropertyAnEnumProperty enumUnderTest = BeanWithEnumPropertyAnEnumProperty.STRING_1; Gson gson = new GsonBuilder().setPrettyPrinting().create(); String serialisedForm = gson.toJson(enumUnderTest); - assertThat(serialisedForm).contains("\"STRING_1\""); + assertThat(serialisedForm).contains("\"string1\""); } @Test @@ -31,6 +31,6 @@ public void TestCanSerialiseTheEnumWithValue2() throws Exception { BeanWithEnumPropertyAnEnumProperty enumUnderTest = BeanWithEnumPropertyAnEnumProperty.STRING_2; Gson gson = new GsonBuilder().setPrettyPrinting().create(); String serialisedForm = gson.toJson(enumUnderTest); - assertThat(serialisedForm).contains("\"STRING_2\""); + assertThat(serialisedForm).contains("\"string2\""); } } diff --git a/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestBeanWithEnumProperty.java b/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestBeanWithEnumProperty.java index 080d3ac..1956495 100644 --- a/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestBeanWithEnumProperty.java +++ b/openapi2beans/JavaChecker/src/test/java/dev/galasa/openapi2beans/example/TestBeanWithEnumProperty.java @@ -24,6 +24,6 @@ public void TestCanSerialiseTheBean() throws Exception { BeanWithEnumProperty beanUnderTest = new BeanWithEnumProperty(enumProperty); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String serialisedForm = gson.toJson(beanUnderTest); - assertThat(serialisedForm).contains("\"anEnumProperty\": \"STRING_1\""); + assertThat(serialisedForm).contains("\"anEnumProperty\": \"string1\""); } } diff --git a/openapi2beans/pkg/embedded/templates/JavaEnumTemplate.mustache b/openapi2beans/pkg/embedded/templates/JavaEnumTemplate.mustache index 369f14f..2861859 100644 --- a/openapi2beans/pkg/embedded/templates/JavaEnumTemplate.mustache +++ b/openapi2beans/pkg/embedded/templates/JavaEnumTemplate.mustache @@ -5,12 +5,16 @@ */ package {{JavaPackage.Name}}; +import com.google.gson.annotations.SerializedName; + {{#Description}} // {{&.}} {{/Description}} public enum {{Name}} { {{#EnumValues}} - {{ConstFormatName}}{{#StringFormat}} ("{{&.}}"){{/StringFormat}}{{^IsFinal}},{{/IsFinal}}{{#IsFinal}};{{/IsFinal}} + {{#StringFormat}}@SerializedName("{{&.}}"){{/StringFormat}} + {{ConstFormatName}}{{#StringFormat}}("{{&.}}"){{/StringFormat}}{{^IsFinal}}, +{{/IsFinal}}{{#IsFinal}};{{/IsFinal}} {{/EnumValues}} private final String outputName; diff --git a/openapi2beans/pkg/generator/package2java_test.go b/openapi2beans/pkg/generator/package2java_test.go index 895bd96..01f79a2 100644 --- a/openapi2beans/pkg/generator/package2java_test.go +++ b/openapi2beans/pkg/generator/package2java_test.go @@ -84,7 +84,7 @@ func assertConstantsGeneratedOk(t *testing.T, generatedFile string, constDataMem func assertEnumFileGeneratedOk(t *testing.T, generatedFile string, javaEnum *JavaEnum) { assert.Contains(t, generatedFile, "package "+TARGET_JAVA_PACKAGE) assert.Contains(t, generatedFile, "public enum "+javaEnum.Name) - valueTemplate := `%s ("%s"),` + valueTemplate := `%s("%s"),` for _, value := range javaEnum.EnumValues { assert.Contains(t, generatedFile, fmt.Sprintf(valueTemplate, value.ConstFormatName, value.StringFormat)) diff --git a/openapi2beans/pkg/generator/yaml2java_test.go b/openapi2beans/pkg/generator/yaml2java_test.go index ea692e4..c93ca3f 100644 --- a/openapi2beans/pkg/generator/yaml2java_test.go +++ b/openapi2beans/pkg/generator/yaml2java_test.go @@ -846,8 +846,11 @@ components: }`) generatedEnumFile := openGeneratedFile(t, mockFileSystem, "dev/wyvinar/generated/MyBeanNameMyEnum.java") expectedEnumFile := `public enum MyBeanNameMyEnum { - STRING_1 ("string1"), - STRING_2 ("string2"); + @SerializedName("string1") + STRING_1("string1"), + + @SerializedName("string2") + STRING_2("string2"); %s }` @@ -897,7 +900,8 @@ components: }`) generatedEnumFile := openGeneratedFile(t, mockFileSystem, "dev/wyvinar/generated/MyBeanNameMyEnum.java") expectedEnumFile := `public enum MyBeanNameMyEnum { - RAND_VALUE_1 ("randValue1"); + @SerializedName("randValue1") + RAND_VALUE_1("randValue1"); %s }`