Skip to content
Open
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
1 change: 1 addition & 0 deletions bin/configs/kotlin-spring-boot-x-kotlin-implements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ additionalProperties:
Pet: com.some.pack.WithId
Category: [ com.some.pack.CategoryInterface ]
Dog: [ com.some.pack.Canine ]
Order: [ "com.some.pack.BoundedRepo<kotlin.Long>", "com.some.pack.VariantSource<kotlin.collections.List<Tag>>", "com.some.pack.TwoBounds<kotlin.Int>" ]
schemaImplementsFields:
Pet: id
Category: [ name, id ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,43 @@ public void generateSerializableModelWithXimplementsSkip() throws Exception {
);
}

@Test(description = "generic interfaces are emitted verbatim via x-kotlin-implements and schemaImplements")
public void generateModelsImplementingGenericInterfaces() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(KotlinSpringServerCodegen.SCHEMA_IMPLEMENTS, Map.of(
"Dog", "com.some.pack.Repo<Cat>",
"Bird", List.of("com.some.pack.Pair<kotlin.String, com.other.pack.Bar>", "com.some.pack.Plain"),
"Fish", List.of("com.some.pack.Outer<kotlin.collections.List<com.other.pack.Bar>>", "com.some.pack.Nullable<Dog?>")
));

ClientOptInput input = new ClientOptInput()
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/generic-interfaces-implements.yaml"))
.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();

String modelDir = outputPath + "/src/main/kotlin/org/openapitools/model/";
assertFileContains(Paths.get(modelDir + "Cat.kt"),
") : com.some.pack.Pair<kotlin.String, com.other.pack.Bar>, com.some.pack.Repo<Dog> {");
assertFileContains(Paths.get(modelDir + "Dog.kt"), ") : com.some.pack.Repo<Cat> {");
assertFileContains(Paths.get(modelDir + "Bird.kt"),
") : com.some.pack.Pair<kotlin.String, com.other.pack.Bar>, com.some.pack.Plain {");
assertFileContains(Paths.get(modelDir + "Fish.kt"),
") : com.some.pack.Nullable<Dog?>, com.some.pack.Outer<kotlin.collections.List<com.other.pack.Bar>> {");
}

@Test
public void generateSerializableModelWithSchemaImplements() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: 3.0.0
info:
title: Generic interfaces
version: 1.0.0
paths: {}
components:
schemas:
Cat:
type: object
x-kotlin-implements:
- com.some.pack.Repo<Dog>
- "com.some.pack.Pair<kotlin.String, com.other.pack.Bar>"
properties:
name:
type: string
Dog:
type: object
properties:
name:
type: string
Bird:
type: object
properties:
name:
type: string
Fish:
type: object
properties:
name:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ components:
type: string
Tag:
type: object
x-kotlin-implements: [ "com.some.pack.GenericRepo<Category>", "com.some.pack.GenericPair<kotlin.String, org.openapitools.model.Category>" ]
properties:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface GenericPair<T, U>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface GenericRepo<T>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class Tag(
@field:JsonSetter(nulls = Nulls.SKIP)
@param:JsonProperty("name")
@get:JsonProperty("name") val name: kotlin.String? = null
) : java.io.Serializable {
) : com.some.pack.GenericPair<kotlin.String, org.openapitools.model.Category>, com.some.pack.GenericRepo<Category>, java.io.Serializable {

companion object {
private const val serialVersionUID: kotlin.Long = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface BoundedRepo<T : Number>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface GenericPair<T, U>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface GenericRepo<T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface TwoBounds<T> where T : Number, T : Comparable<T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.some.pack

interface VariantSource<out T>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class Order(
@field:JsonSetter(nulls = Nulls.SKIP)
@param:JsonProperty("complete")
@get:JsonProperty("complete") val complete: kotlin.Boolean? = false
) : java.io.Serializable {
) : com.some.pack.BoundedRepo<kotlin.Long>, com.some.pack.TwoBounds<kotlin.Int>, com.some.pack.VariantSource<kotlin.collections.List<Tag>>, java.io.Serializable {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class Tag(
@field:JsonSetter(nulls = Nulls.SKIP)
@param:JsonProperty("name")
@get:JsonProperty("name") val name: kotlin.String? = null
) : java.io.Serializable {
) : com.some.pack.GenericPair<kotlin.String, org.openapitools.model.Category>, com.some.pack.GenericRepo<Category>, java.io.Serializable {

companion object {
private const val serialVersionUID: kotlin.Long = 1
Expand Down
Loading