diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/yaml/YamlGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/yaml/YamlGeneratorTest.java index c264a8a251c..cc4e74ade5d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/yaml/YamlGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/yaml/YamlGeneratorTest.java @@ -17,6 +17,7 @@ package org.openapitools.codegen.yaml; +import io.swagger.v3.oas.models.OpenAPI; import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.DefaultGenerator; import org.openapitools.codegen.TestUtils; @@ -85,4 +86,36 @@ public class YamlGeneratorTest { output.deleteOnExit(); } + + @Test + public void testIssue9086() throws Exception { + Map properties = new HashMap<>(); + properties.put(OpenAPIYamlGenerator.OUTPUT_NAME, "issue_9086.yaml"); + + File output = Files.createTempDirectory("issue_9086").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("openapi-yaml") + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/2_0/issue_9086.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(clientOptInput).generate(); + Assert.assertEquals(files.size(), 5); + TestUtils.ensureContainsFile(files, output, "issue_9086.yaml"); + + TestUtils.ensureContainsFile(files, output, "README.md"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator-ignore"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/FILES"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/VERSION"); + + OpenAPI generated = TestUtils.parseSpec(new File(output, "issue_9086.yaml").getPath()); + OpenAPI expected = TestUtils.parseSpec("src/test/resources/2_0/issue_9086_expected.yaml"); + + // use #toString because the equals methods is a little stricter than necessary for this test + Assert.assertEquals(expected.toString(), generated.toString()); + } } diff --git a/modules/openapi-generator/src/test/resources/2_0/issue_9086.yaml b/modules/openapi-generator/src/test/resources/2_0/issue_9086.yaml new file mode 100644 index 00000000000..3210031ade3 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/2_0/issue_9086.yaml @@ -0,0 +1,34 @@ +swagger: '2.0' +info: + title: 'Buggy Api' + version: '1.0' +consumes: + - application/json +paths: + /foo/bar: + post: + responses: + '200': + description: ok + schema: + type: object + additionalProperties: false + properties: + n: + type: number + example: 1.23 + /foo/bar2: + post: + responses: + '200': + description: ok + schema: + $ref: '#/definitions/bar2' +definitions: + bar2: + type: object + additionalProperties: false + properties: + n: + type: number + example: 4.56 diff --git a/modules/openapi-generator/src/test/resources/2_0/issue_9086_expected.yaml b/modules/openapi-generator/src/test/resources/2_0/issue_9086_expected.yaml new file mode 100644 index 00000000000..cce682ee053 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/2_0/issue_9086_expected.yaml @@ -0,0 +1,40 @@ +openapi: 3.0.1 +info: + title: 'Buggy Api' + version: '1.0' +paths: + /foo/bar: + post: + responses: + '200': + description: ok + content: + '*/*': + schema: + $ref: '#/components/schemas/inline_response_200' + + /foo/bar2: + post: + responses: + '200': + description: ok + content: + '*/*': + schema: + $ref: '#/components/schemas/bar2' +components: + schemas: + bar2: + type: object + example: { n: 4.56 } + properties: + n: + type: number + example: 4.56 + inline_response_200: + type: object + example: { n: 1.23 } + properties: + n: + type: number + example: 1.23 diff --git a/pom.xml b/pom.xml index 5a8c00165ef..a78fee85d3c 100644 --- a/pom.xml +++ b/pom.xml @@ -1576,7 +1576,7 @@ 1.8 2.1.2 io.swagger.parser.v3 - 2.0.24 + 2.0.26 3.3.1 2.4 1.2