Skip to content

Commit

Permalink
Merge pull request #9402 from swagger-api/bool-additional-properties
Browse files Browse the repository at this point in the history
fix handling of boolean additionalProperties
  • Loading branch information
frantuma authored Apr 24, 2019
2 parents ef25d60 + 8e79b28 commit ce6e703
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,43 @@ 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<File> 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)
.addAdditionalProperty("useRxJava", true)
);
List<File> 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<String, Object> foo = null"));
}
}

}

@Test(description = "test generator service with java client 2.0")
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 43 additions & 0 deletions modules/swagger-codegen/src/test/resources/3_0_0/swos92.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pom.docker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,9 @@
</repositories>
<properties>
<swagger-codegen-generators-version>1.0.8-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.0.7</swagger-core-version>
<swagger-core-version>2.0.8-SNAPSHOT</swagger-core-version>
<swagger-core-version-v1>1.5.22</swagger-core-version-v1>
<swagger-parser-version>2.0.11</swagger-parser-version>
<swagger-parser-version>2.0.12-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.44</swagger-parser-version-v1>
<jackson-version>2.9.8</jackson-version>
<scala-version>2.11.1</scala-version>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,9 @@
</repositories>
<properties>
<swagger-codegen-generators-version>1.0.8-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.0.7</swagger-core-version>
<swagger-core-version>2.0.8-SNAPSHOT</swagger-core-version>
<swagger-core-version-v1>1.5.22</swagger-core-version-v1>
<swagger-parser-version>2.0.11</swagger-parser-version>
<swagger-parser-version>2.0.12-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.44</swagger-parser-version-v1>
<jackson-version>2.9.8</jackson-version>
<scala-version>2.11.1</scala-version>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,9 @@
</repositories>
<properties>
<swagger-codegen-generators-version>1.0.8-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.0.7</swagger-core-version>
<swagger-core-version>2.0.8-SNAPSHOT</swagger-core-version>
<swagger-core-version-v1>1.5.22</swagger-core-version-v1>
<swagger-parser-version>2.0.11</swagger-parser-version>
<swagger-parser-version>2.0.12-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.44</swagger-parser-version-v1>
<jackson-version>2.9.8</jackson-version>
<scala-version>2.11.1</scala-version>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml.shippable
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,9 @@
</repositories>
<properties>
<swagger-codegen-generators-version>1.0.8-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.0.7</swagger-core-version>
<swagger-core-version>2.0.8-SNAPSHOT</swagger-core-version>
<swagger-core-version-v1>1.5.22</swagger-core-version-v1>
<swagger-parser-version>2.0.11</swagger-parser-version>
<swagger-parser-version>2.0.12-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.44</swagger-parser-version-v1>
<jackson-version>2.9.8</jackson-version>
<scala-version>2.11.1</scala-version>
Expand Down

0 comments on commit ce6e703

Please sign in to comment.