V2 Kotlinx Multiplatform Encoder Example - SMILEY4/ktor-openapi-tools GitHub Wiki
The default schema-generator and json-serializer may not support kotlinx or multiplatform. This example shows how to replace these with one compatible with kotlinx and multiplatform.
jackson and victools/jsonschema-generator will be replaced with Kotlin.serialization and tillersystems/json-schema-serialization.
Replacing the Example Json-Serializer
Create a new Json-instance used for serializing. The same instance can also be used for schema-generation.
val json = Json {
prettyPrint = true
encodeDefaults = true
}
The default json-serializer is replaced with Kotlin.serialization
install(SwaggerUI) {
encoding {
exampleEncoder { type, value ->
json.encodeToString(serializer(type!!), value)
}
//...
}
}
Replacing the Schema-Generator
Create a new Json-instance used for schema-generation. The same instance can also be used for json-serialization.
val json = Json {
prettyPrint = true
encodeDefaults = true
}
The default schema-generator is replaced with tillersystems/json-schema-serialization
install(SwaggerUI) {
encoding {
//...
schemaEncoder { type ->
json.encodeToSchema(serializer(type), generateDefinitions = false)
}
schemaDefinitionsField = "definitions"
}
}