From fde1e1ad750ae685829d36e88836963cdc2b5193 Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 18:47:24 -0400 Subject: [PATCH 1/8] New Test Case Added to AndroidClientCodegenTest --- .../android/AndroidClientCodegenTest.java | 19 +++++++++++++++++++ .../AbstractJavaCodegenExampleValuesTest.java | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/android/AndroidClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/android/AndroidClientCodegenTest.java index f5ede0eb5a92..f7fab835e1fa 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/android/AndroidClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/android/AndroidClientCodegenTest.java @@ -70,4 +70,23 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker"); } + @Test + public void testHideGenerationTimestampDisabled() throws Exception { + final AndroidClientCodegen codegen = new AndroidClientCodegen(); + codegen.additionalProperties().put("hideGenerationTimestamp", false); + codegen.processOpts(); + + Assert.assertEquals(codegen.additionalProperties().get("hideGenerationTimestamp"), Boolean.FALSE); + Assert.assertFalse(codegen.isHideGenerationTimestamp()); + } + + @Test + public void testHideGenerationTimestampEnabled() throws Exception { + final AndroidClientCodegen codegen = new AndroidClientCodegen(); + codegen.additionalProperties().put("hideGenerationTimestamp", true); + codegen.processOpts(); + + Assert.assertEquals(codegen.additionalProperties().get("hideGenerationTimestamp"), Boolean.TRUE); + Assert.assertTrue(codegen.isHideGenerationTimestamp()); + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenExampleValuesTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenExampleValuesTest.java index d9f451a462e0..2cbe4c623646 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenExampleValuesTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenExampleValuesTest.java @@ -153,5 +153,17 @@ public String getHelp() { public String getArtifactVersion() { return this.artifactVersion; } + @Test + void customExampleForEnumValue() { + final AbstractJavaCodegen fakeJavaCodegen = new P_AbstractJavaCodegen(); + final CodegenParameter p = new CodegenParameter(); + p.allowableValues = Collections.singletonMap("values", Arrays.asList("first", "second")); + p.dataType = "WrappedEnum"; + p.example = "CustomEnumValue"; + + fakeJavaCodegen.setParameterExampleValue(p); + // Custom example value should not be modified + Assert.assertEquals(p.example, "CustomEnumValue"); + } } } From 63c0b4f2028b7b4be625c2ed0856d5cc9532d6ed Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 18:48:42 -0400 Subject: [PATCH 2/8] New Test Case Added to GenApiControllerTest --- .../codegen/online/api/GenApiControllerTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java b/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java index 262e0eba6603..05d72f7b1a83 100644 --- a/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java +++ b/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java @@ -124,5 +124,12 @@ public void generateWIthForwardedHeaders() throws Exception { .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.CONTENT_LENGTH, not(0))); } - + @Test + public void generateClientWithInvalidOpenAPIUrl() throws Exception { + String invalidOpenAPIUrl = "https://example.com/invalid_openapi.json"; // Provide an invalid URL + mockMvc.perform(post("http://test.com:1234/api/gen/clients/java") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"openAPIUrl\": \"" + invalidOpenAPIUrl + "\"}")) + .andExpect(status().isBadRequest()); + } } From 05677e54408cc7ca1c8a5e5d5fa81a51a3605520 Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 18:49:31 -0400 Subject: [PATCH 3/8] New Test Case Added to BirdAndCategoryTest --- .../openapitools/client/model/BirdAndCategoryTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java index 205f5cff0cda..0ab51f45ba98 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java +++ b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java @@ -34,7 +34,11 @@ public class BirdAndCategoryTest { */ @Test public void testBirdAndCategory() { - // TODO: test BirdAndCategory + birdAndCategory.setSize("Small"); + assertEquals("Small", birdAndCategory.getSize()); + + birdAndCategory.setSize("Large"); + assertEquals("Large", birdAndCategory.getSize()); } /** @@ -42,7 +46,7 @@ public void testBirdAndCategory() { */ @Test public void sizeTest() { - // TODO: test size + } /** From ee9eb96c5d07b4bc8becd936bbdd59909775fdcf Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 18:50:19 -0400 Subject: [PATCH 4/8] New Test Case Added to WorkflowSettingsTest --- .../codegen/config/WorkflowSettingsTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/openapi-generator-core/src/test/java/org/openapitools/codegen/config/WorkflowSettingsTest.java b/modules/openapi-generator-core/src/test/java/org/openapitools/codegen/config/WorkflowSettingsTest.java index 33638f767356..626e02aca94b 100644 --- a/modules/openapi-generator-core/src/test/java/org/openapitools/codegen/config/WorkflowSettingsTest.java +++ b/modules/openapi-generator-core/src/test/java/org/openapitools/codegen/config/WorkflowSettingsTest.java @@ -120,4 +120,23 @@ public void defaultValuesCanBeChangedBuilder(){ WorkflowSettings defaults = WorkflowSettings.newBuilder().build(); assertOnChangesToDefaults(defaults); } + @Test + public void customOutputDirIsSet() { + WorkflowSettings settings = WorkflowSettings.newBuilder() + .withOutputDir("custom/output/directory") + .build(); + + assertEquals(settings.getOutputDir(), Paths.get("custom/output/directory").toAbsolutePath().toString()); + } + + @Test + public void customGlobalPropertiesAreSet() { + WorkflowSettings settings = WorkflowSettings.newBuilder() + .withGlobalProperty("customKey", "customValue") + .build(); + + Map properties = settings.getGlobalProperties(); + assertEquals(properties.size(), 1, "Global Properties map should allow custom entries"); + assertEquals(properties.getOrDefault("customKey", ""), "customValue"); + } } \ No newline at end of file From a470f30613d50089369136eda9b5810f1ac60a8e Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 20:18:00 -0400 Subject: [PATCH 5/8] Modified GenApiControllerTest --- .../openapitools/codegen/online/api/GenApiControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java b/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java index 05d72f7b1a83..8df33829c926 100644 --- a/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java +++ b/modules/openapi-generator-online/src/test/java/org/openapitools/codegen/online/api/GenApiControllerTest.java @@ -126,7 +126,7 @@ public void generateWIthForwardedHeaders() throws Exception { } @Test public void generateClientWithInvalidOpenAPIUrl() throws Exception { - String invalidOpenAPIUrl = "https://example.com/invalid_openapi.json"; // Provide an invalid URL + String invalidOpenAPIUrl = "https://test.com:1234/invalid_openapi.json"; mockMvc.perform(post("http://test.com:1234/api/gen/clients/java") .contentType(MediaType.APPLICATION_JSON) .content("{\"openAPIUrl\": \"" + invalidOpenAPIUrl + "\"}")) From 70324a7c1f2eed92800ae499060a0bca2754b9b7 Mon Sep 17 00:00:00 2001 From: Mann Date: Sun, 5 Nov 2023 20:19:37 -0400 Subject: [PATCH 6/8] Added Test case in JavascriptClientCodegenTest --- .../codegen/javascript/JavascriptClientCodegenTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java index 8514e36b803c..7b5e0ca5de77 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/javascript/JavascriptClientCodegenTest.java @@ -169,4 +169,13 @@ public void testIsJsonIsXmlInProduces() throws Exception { } } + @Test(description = "test additional properties for code generation") + public void testAdditionalProperties() throws Exception { + final JavascriptClientCodegen codegen = new JavascriptClientCodegen(); + codegen.additionalProperties().put("customProperty", "customValue"); + codegen.processOpts(); + + Assert.assertEquals(codegen.additionalProperties().get("customProperty"), "customValue"); + } + } From 2d99bee5d525dd4d7fb4b53c3086071b4387afeb Mon Sep 17 00:00:00 2001 From: Mann Date: Mon, 6 Nov 2023 23:27:14 -0400 Subject: [PATCH 7/8] Modified BirdAndCategoryTest --- .../openapitools/client/model/BirdAndCategoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java index 0ab51f45ba98..d5c3e319075a 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java +++ b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java @@ -34,11 +34,11 @@ public class BirdAndCategoryTest { */ @Test public void testBirdAndCategory() { - birdAndCategory.setSize("Small"); - assertEquals("Small", birdAndCategory.getSize()); + model.setSize("Small"); + assertEquals("Small", model.getSize()); - birdAndCategory.setSize("Large"); - assertEquals("Large", birdAndCategory.getSize()); + model.setSize("Large"); + assertEquals("Large", model.getSize()); } /** From ab9545570d20b32fe7a33f2d8f603da371853ebd Mon Sep 17 00:00:00 2001 From: Mann Date: Tue, 7 Nov 2023 00:39:15 -0400 Subject: [PATCH 8/8] Modified BirdAndCategoryTest --- .../org/openapitools/client/model/BirdAndCategoryTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java index d5c3e319075a..9237871cfb7f 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java +++ b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/model/BirdAndCategoryTest.java @@ -34,11 +34,7 @@ public class BirdAndCategoryTest { */ @Test public void testBirdAndCategory() { - model.setSize("Small"); - assertEquals("Small", model.getSize()); - model.setSize("Large"); - assertEquals("Large", model.getSize()); } /**