From 8e79b28cd00ff9a57f0cc28da28e9666b87e3915 Mon Sep 17 00:00:00 2001 From: frantuma Date: Wed, 24 Apr 2019 10:09:38 +0200 Subject: [PATCH] fix handling of boolean additionalProperties --- .../v3/service/GeneratorServiceTest.java | 47 ++++++++++++++++++- .../src/test/resources/3_0_0/swos92.yaml | 43 +++++++++++++++++ pom.docker.xml | 4 +- pom.xml | 4 +- pom.xml.bash | 4 +- pom.xml.shippable | 4 +- 6 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 modules/swagger-codegen/src/test/resources/3_0_0/swos92.yaml diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java index 836f44dad82..9e21d10b3fe 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java @@ -124,7 +124,29 @@ public void testGeneratorServiceJavaClient3() { .spec(loadSpecAsNode("3_0_0/petstore.json", false, false)) .options( new Options() - .outputDir(getTmpFolder().getAbsolutePath()) + .outputDir(getTmpFolder().getAbsolutePath()) + .artifactId("swagger-petstore-jersey2") + .library("jersey2") + .addAdditionalProperty("useRuntimeException", true) + .addAdditionalProperty("useRxJava", true) + ); + List files = new GeneratorService().generationRequest(request).generate(); + Assert.assertFalse(files.isEmpty()); + } + + @Test(description = "test boolean additional properties") + public void testGeneratorServiceBooleanAdditionalProperties() throws Exception { + + String path = getTmpFolder().getAbsolutePath(); + GenerationRequest request = new GenerationRequest(); + request + .codegenVersion(GenerationRequest.CodegenVersion.V3) + .type(GenerationRequest.Type.CLIENT) + .lang("java") + .spec(loadSpecAsNode("3_0_0/swos92.yaml", true, false)) + .options( + new Options() + .outputDir(path) .artifactId("swagger-petstore-jersey2") .library("jersey2") .addAdditionalProperty("useRuntimeException", true) @@ -132,6 +154,13 @@ public void testGeneratorServiceJavaClient3() { ); List files = new GeneratorService().generationRequest(request).generate(); Assert.assertFalse(files.isEmpty()); + for (File f: files) { + String relPath = f.getAbsolutePath().substring(path.length()); + if ("/src/main/java/io/swagger/client/model/Product.java".equals(relPath)) { + Assert.assertTrue(FileUtils.readFileToString(f).contains("Map foo = null")); + } + } + } @Test(description = "test generator service with java client 2.0") @@ -188,6 +217,22 @@ protected JsonNode loadSpecAsNode(final String file, boolean yaml, boolean v2) { } } + protected OpenAPI deserializeOpenAPI(final String file, boolean yaml, boolean v2) { + InputStream in = null; + String s = ""; + try { + in = getClass().getClassLoader().getResourceAsStream(file); + if (yaml) { + return io.swagger.v3.core.util.Yaml.mapper().readValue(in, OpenAPI.class); + } + return io.swagger.v3.core.util.Json.mapper().readValue(in, OpenAPI.class); + } catch (Exception e) { + throw new RuntimeException("could not load file " + file); + } finally { + IOUtils.closeQuietly(in); + } + } + private static OpenAPI parseOpenAPI(String path) { final ParseOptions options = new ParseOptions(); options.setFlatten(Boolean.TRUE); diff --git a/modules/swagger-codegen/src/test/resources/3_0_0/swos92.yaml b/modules/swagger-codegen/src/test/resources/3_0_0/swos92.yaml new file mode 100644 index 00000000000..f5555bbe6d3 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/3_0_0/swos92.yaml @@ -0,0 +1,43 @@ +openapi: 3.0.0 +info: + version: "v2.0" + title: Test +paths: + /product: + get: + operationId: getProduct + summary: Gets a Product by ID. + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Product' + put: + operationId: updateProduct + summary: Updates a Product by ID. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Product' + responses: + '201': + description: Created +components: + schemas: + Product: + type: object + properties: + name: + type: object + additionalProperties: + type: string + active: + type: boolean + example: true + foo: + type: object + additionalProperties: true diff --git a/pom.docker.xml b/pom.docker.xml index 691a0e72df2..c8d11e7f29b 100644 --- a/pom.docker.xml +++ b/pom.docker.xml @@ -1071,9 +1071,9 @@ 1.0.8-SNAPSHOT - 2.0.7 + 2.0.8-SNAPSHOT 1.5.22 - 2.0.11 + 2.0.12-SNAPSHOT 1.0.44 2.9.8 2.11.1 diff --git a/pom.xml b/pom.xml index 7a2071b9a23..52b77cb824a 100644 --- a/pom.xml +++ b/pom.xml @@ -1162,9 +1162,9 @@ 1.0.8-SNAPSHOT - 2.0.7 + 2.0.8-SNAPSHOT 1.5.22 - 2.0.11 + 2.0.12-SNAPSHOT 1.0.44 2.9.8 2.11.1 diff --git a/pom.xml.bash b/pom.xml.bash index 20fbed4de30..cad53d92a4c 100644 --- a/pom.xml.bash +++ b/pom.xml.bash @@ -1059,9 +1059,9 @@ 1.0.8-SNAPSHOT - 2.0.7 + 2.0.8-SNAPSHOT 1.5.22 - 2.0.11 + 2.0.12-SNAPSHOT 1.0.44 2.9.8 2.11.1 diff --git a/pom.xml.shippable b/pom.xml.shippable index c0d8b4ea8fe..361e0ff5684 100644 --- a/pom.xml.shippable +++ b/pom.xml.shippable @@ -1061,9 +1061,9 @@ 1.0.8-SNAPSHOT - 2.0.7 + 2.0.8-SNAPSHOT 1.5.22 - 2.0.11 + 2.0.12-SNAPSHOT 1.0.44 2.9.8 2.11.1