Closed n3phtys closed 3 years ago
After debugging the plugin down to swagger-core, there is a half acceptable possibility OOTB:
@io.swagger.v3.oas.annotations.media.Schema(
oneOf = [MyValues.Aa::class, MyValues.Bb::class, MyValues::Cc::class]
)
sealed class MyValues {
object Aa : MyValues()
object Bb : MyValues()
data class Cc(val str: String) : MyValues()
}
This does add the oneOf() definition to the MyValues schema, but
JavalinModelResolver.kt
by using something like annotatedType.getRawClass().kotlin.sealedSubclasses()
)
Assume entities are built using sealed classes to model algebraic data types in Kotlin:
While the OpenAPI plugin's DSL correctly identifies the classes Aa, Bb, Cc, as well as MyValues, and adds them as OAS Schemata, the inheritance relationship between 'MyValues' and its children is not. In a perfect world, MyValues would be recognized as a
oneOf()
composition of its three children. I know Kotlin sealed class are compile time knowledge, therefore making automatic retrieval of this type of relationship during runtime nearly impossible.Can I give the OpenAPI plugin some manual help / pointers via the DSL? As in: Can I manually overwrite the definition it outputs for MyValues; adding the
oneOf
relationship manually to it, while keeping the rest of the automatically generated specification?Full source code for example:
Leads to following OpenAPI spec: