Skip to content

Commit c4b60df

Browse files
committed
changed model generator in order not to generate lists as named types, but only to define them locally
1 parent 26454c5 commit c4b60df

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/main/kotlin/com/papsign/ktor/openapigen/OpenAPIGen.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.papsign.ktor.openapigen.modules.CachingModuleProvider
44
import com.papsign.ktor.openapigen.modules.schema.*
55
import com.papsign.ktor.openapigen.openapi.ExternalDocumentation
66
import com.papsign.ktor.openapigen.openapi.OpenAPI
7+
import com.papsign.ktor.openapigen.openapi.Schema
78
import com.papsign.ktor.openapigen.openapi.Schema.SchemaRef
89
import com.papsign.ktor.openapigen.openapi.Server
910
import io.ktor.application.ApplicationCallPipeline
@@ -85,14 +86,17 @@ class OpenAPIGen(
8586
}
8687
if (predefined != null)
8788
return predefined
88-
schemas.getOrPut(type) {
89-
val (name, schema) = super.get(type, master)
90-
schemas[type] = schema
91-
names[type] = name
92-
api.components.schemas[name] = schema
93-
schema
89+
val current = schemas[type]
90+
if (current != null) {
91+
val name = names[type]!!
92+
return NamedSchema(name, SchemaRef<Any>("#/components/schemas/$name"))
9493
}
95-
val name = names[type]!!
94+
val (name, schema) = super.get(type, master)
95+
if (schema is Schema.SchemaArr<*>) return NamedSchema(name, schema)
96+
97+
schemas[type] = schema
98+
names[type] = name
99+
api.components.schemas[name] = schema
96100
return NamedSchema(name, SchemaRef<Any>("#/components/schemas/$name"))
97101
}
98102
}

src/test/kotlin/TestServer.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ object TestServer {
139139
respond(StringResponse(params.a))
140140
}
141141

142+
route("list") {
143+
get<StringParam, List<StringResponse>>(
144+
info("String Param Endpoint", "This is a String Param Endpoint"),
145+
example = listOf(StringResponse("Hi"))
146+
) { params ->
147+
respond(listOf(StringResponse(params.a)))
148+
}
149+
}
150+
142151
route("sealed") {
143152
post<Unit, Base, Base>(
144153
info("Sealed class Endpoint", "This is a Sealed class Endpoint"),

0 commit comments

Comments
 (0)