Skip to content

Commit 9165605

Browse files
committed
add unit test for adding x-kotlin-implements
1 parent b8223dd commit 9165605

3 files changed

Lines changed: 1070 additions & 0 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/validations/oas/ModelVendorExtensionAdd.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.openapitools.codegen.validations.oas;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import lombok.Getter;
45
import lombok.Setter;
56

@@ -11,6 +12,7 @@ public class ModelVendorExtensionAdd {
1112

1213
@Getter
1314
@Setter
15+
@JsonProperty("class")
1416
private Map<String, List<String>> clazz = new HashMap<>();
1517

1618
@Getter

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,39 @@ public void generateSerializableModelWithRemovedXimplements() throws Exception {
13121312
);
13131313
}
13141314

1315+
@Test
1316+
public void generateSerializableModelWithExternallyAddedXimplements() throws Exception {
1317+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
1318+
output.deleteOnExit();
1319+
String outputPath = output.getAbsolutePath().replace('\\', '/');
1320+
1321+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
1322+
codegen.setOutputDir(output.getAbsolutePath());
1323+
codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true);
1324+
codegen.additionalProperties().put(MODEL_VENDOR_EXTENSION_ADD, Map.of("Dog", Map.of("class", Map.of("x-kotlin-implements", List.of("com.some.pack.Fetchable"), "x-kotlin-implements-fields", List.of("likesFetch")))));
1325+
1326+
ClientOptInput input = new ClientOptInput()
1327+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/petstore-without-x-kotlin-implements.yaml"))
1328+
.config(codegen);
1329+
DefaultGenerator generator = new DefaultGenerator();
1330+
1331+
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
1332+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
1333+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
1334+
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false");
1335+
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
1336+
1337+
generator.opts(input).generate();
1338+
1339+
Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Dog.kt");
1340+
assertFileContains(
1341+
path,
1342+
"@get:JsonProperty(\"likesFetch\", required = true) override val likesFetch: kotlin.Boolean,",
1343+
") : Pet, com.some.pack.Fetchable, java.io.Serializable {",
1344+
"private const val serialVersionUID: kotlin.Long = 1"
1345+
);
1346+
}
1347+
13151348
@Test
13161349
public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exception {
13171350
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();

0 commit comments

Comments
 (0)