From ef0c9baa490b7114b4207d800d6c365c023349d2 Mon Sep 17 00:00:00 2001 From: Karsten Thoms Date: Wed, 23 Feb 2022 23:32:58 +0100 Subject: [PATCH] [#11696] Add test case This change adds a test case that is reproducing the problem. The property 'category' of 'MyType' is considered to be a map, which is producing a put-method in pojo.mustache. The test case is disabled to allow the build passing until the issue gets fixed. --- .../java/spring/SpringCodegenTest.java | 31 ++++++++++++++++- .../test/resources/3_0/spring/issue_11696.yml | 33 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/test/resources/3_0/spring/issue_11696.yml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index cd7a9c95b6a2..96424be0b093 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -1076,7 +1076,6 @@ public void testIssue11323() throws IOException { SpringCodegen codegen = new SpringCodegen(); codegen.setOutputDir(output.getAbsolutePath()); - //codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); ClientOptInput input = new ClientOptInput(); input.openAPI(openAPI); @@ -1322,4 +1321,34 @@ public void shouldSetDefaultValueForMultipleArrayItems() throws IOException { .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\"")); } + + @Test(enabled = false) + // TODO Test case reproduces issue #11696. Enable when the issue is fixed. + public void testIssue11696() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/spring/issue_11696.yml", null, new ParseOptions()).getOpenAPI(); + + SpringCodegen codegen = new SpringCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + generator.opts(input).generate(); + + assertFileNotContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/MyType.java"), + "putCategoryItem"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/spring/issue_11696.yml b/modules/openapi-generator/src/test/resources/3_0/spring/issue_11696.yml new file mode 100644 index 000000000000..0f11ab9d14ee --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/spring/issue_11696.yml @@ -0,0 +1,33 @@ +openapi: 3.0.1 +info: + title: Test Issue #11696 + version: v1 +paths: + /test: + get: + responses: + '200': + description: default response + content: + '*/*': + schema: + $ref: '#/components/schemas/MyType' +components: + schemas: + MyType: + required: + - category + type: object + properties: + category: + type: object + description: |- + Type: Category
+ The category + allOf: + - $ref: '#/components/schemas/Category' + Category: + type: object + properties: + name: + type: string