Skip to content

Commit 6be6040

Browse files
committed
Add a test
1 parent ca5c2ec commit 6be6040

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,36 @@ public void testIntArrayToEnum() throws IOException {
644644
TestUtils.assertFileContains(modelKt, "enum class DaysOfWeek(val value: kotlin.Int)");
645645
}
646646

647+
@Test(description = "convert an empty model to object")
648+
public void emptyModelKotlinxSerializationTest() throws IOException {
649+
final Schema<?> schema = new ObjectSchema()
650+
.description("an empty model");
651+
final DefaultCodegen codegen = new KotlinClientCodegen();
652+
codegen.processOpts();
653+
654+
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("EmptyModel", schema);
655+
codegen.setOpenAPI(openAPI);
656+
657+
File output = Files.createTempDirectory("test").toFile();
658+
output.deleteOnExit();
659+
660+
final CodegenConfigurator configurator = new CodegenConfigurator()
661+
.setGeneratorName("kotlin")
662+
.setAdditionalProperties(new HashMap<>() {{
663+
put(CodegenConstants.MODEL_PACKAGE, "model");
664+
put(SERIALIZATION_LIBRARY, "kotlinx_serialization");
665+
}})
666+
.setInputSpec("src/test/resources/3_0/kotlin/empty-model.yaml")
667+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
668+
669+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
670+
DefaultGenerator generator = new DefaultGenerator();
671+
generator.opts(clientOptInput).generate();
672+
673+
final Path modelKt = Paths.get(output + "/src/main/kotlin/model/EmptyModel.kt");
674+
TestUtils.assertFileNotContains(modelKt, "data class EmptyModel");
675+
}
676+
647677
private static class ModelNameTest {
648678
private final String expectedName;
649679
private final String expectedClassName;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Test Empty Model
4+
version: 1.0.0
5+
paths: {}
6+
components:
7+
schemas:
8+
Response:
9+
type: "object"
10+
properties:
11+
result_or_error:
12+
nullable: true
13+
discriminator:
14+
propertyName: "_type"
15+
mapping:
16+
result: "#/components/schemas/EmptyModel"
17+
error: "#/components/schemas/Error"
18+
oneOf:
19+
- $ref: "#/components/schemas/EmptyModel"
20+
- $ref: "#/components/schemas/Error"
21+
EmptyModel:
22+
type: object
23+
properties:
24+
_type:
25+
required:
26+
- "_type"
27+
type: string
28+
default: "result"
29+
additionalProperties: false
30+
Error:
31+
type: object
32+
required:
33+
- "code"
34+
properties:
35+
code:
36+
type: integer
37+
_type:
38+
required:
39+
- "_type"
40+
type: string
41+
default: "error"
42+
additionalProperties: false

0 commit comments

Comments
 (0)