diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 56e5debcdcb5..904ee97303e1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2632,6 +2632,8 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map(); if (composed.getAllOf() != null) { int modelImplCnt = 0; // only one inline object allowed in a ComposedModel diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinModelCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinModelCodegenTest.java index 59e42b4c1c01..d212680d3ab0 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinModelCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinModelCodegenTest.java @@ -6,6 +6,7 @@ import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.DefaultGenerator; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.languages.AbstractKotlinCodegen; import org.openapitools.codegen.languages.KotlinClientCodegen; import org.openapitools.codegen.languages.KotlinServerCodegen; @@ -110,4 +111,61 @@ public void mutableArrayWithUniqueItems(AbstractKotlinCodegen codegen) throws IO assertFileContains(Paths.get(outputPath + "/src/main/kotlin/models/UniqueArray.kt"), "var array: kotlin.collections.MutableSet"); } + + + private String generateModelsWIP(String inputFile) throws IOException { + KotlinClientCodegen codegen = new KotlinClientCodegen(); + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + codegen.setOutputDir(output.getAbsolutePath()); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("kotlin") + .setOutputDir(output.getAbsolutePath()) + .setInputSpec(inputFile) + .addInlineSchemaOption("RESOLVE_INLINE_ENUMS", "true"); + codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "models"); + + 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(configurator.toClientOptInput()).generate(); + return outputPath; + } + + @Test + public void dataClassGenerationNotWorkingWithAllOfInSchema() throws IOException { + String outputPath = generateModelsWIP("src/test/resources/3_1/issue_wip.yaml"); + + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/client/models/GetStuffFromPath200ResponseInner.kt"), + "val aBooleanCheck: kotlin.Boolean? = null,", + "val condition: kotlin.String? = null,", + "val purpose: kotlin.collections.List? = null" + ); + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/client/models/GetStuffFromPath200ResponseInnerPurposeInner.kt"), + "FIRST(\"FIRST\"),", + "SECOND(\"SECOND\"),", + "THIRD(\"THIRD\");" + ); + } + + @Test + public void dataClassGenerationWorkingWithoutAllOfInSchema() throws IOException { + + String outputPath = generateModelsWIP("src/test/resources/3_1/issue_wip_working_without_all_of.yaml"); + + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/client/models/GetStuffFromPath200ResponseInner.kt"), + "val aBooleanCheck: kotlin.Boolean? = null,", + "val condition: kotlin.String? = null,", + "val purpose: kotlin.collections.List? = null" + ); + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/client/models/GetStuffFromPath200ResponseInnerPurposeInner.kt"), + "FIRST(\"FIRST\"),", + "SECOND(\"SECOND\"),", + "THIRD(\"THIRD\");" + ); + } } diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_wip.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_wip.yaml new file mode 100644 index 000000000000..913c0eae470b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/issue_wip.yaml @@ -0,0 +1,51 @@ +openapi: 3.1.0 +info: + title: Title + description: Description + version: 1.0.0 +servers: + - url: / +paths: + /v1/path: + get: + summary: A path + description: Stuff happens on this path + operationId: getStuffFromPath + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + title: AListOfThings + items: + type: object + allOf: + - if: + properties: + aBooleanCheck: + const: false + then: + required: + - condition + - if: + properties: + aBooleanCheck: + const: true + then: + required: + - purpose + properties: + aBooleanCheck: + type: boolean + condition: + type: string + purpose: + type: array + items: + type: string + enum: + - FIRST + - SECOND + - THIRD \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_wip_working_without_all_of.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_wip_working_without_all_of.yaml new file mode 100644 index 000000000000..b93c8fde5223 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/issue_wip_working_without_all_of.yaml @@ -0,0 +1,36 @@ +openapi: 3.1.0 +info: + title: Title + description: Description + version: 1.0.0 +servers: + - url: / +paths: + /v1/path: + get: + summary: A path + description: Stuff happens on this path + operationId: getStuffFromPath + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + title: AListOfThings + items: + type: object + properties: + aBooleanCheck: + type: boolean + condition: + type: string + purpose: + type: array + items: + type: string + enum: + - FIRST + - SECOND + - THIRD \ No newline at end of file