Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,8 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<S

// TODO revise the logic below to set discriminator, xml attributes
if (supportsInheritance || supportsMixins) {
// FIXME Comment out the next line, and allVars will be used in the template to generate the missing fields.
// Why is m.allVars being reset in this case?
m.allVars = new ArrayList<>();
if (composed.getAllOf() != null) {
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<kotlin.String>");
}


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<GetStuffFromPath200ResponseInnerPurposeInner>? = 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<GetStuffFromPath200ResponseInnerPurposeInner>? = null"
);
assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/client/models/GetStuffFromPath200ResponseInnerPurposeInner.kt"),
"FIRST(\"FIRST\"),",
"SECOND(\"SECOND\"),",
"THIRD(\"THIRD\");"
);
}
}
51 changes: 51 additions & 0 deletions modules/openapi-generator/src/test/resources/3_1/issue_wip.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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