-
Notifications
You must be signed in to change notification settings - Fork 39
V2 Kotlinx Multiplatform Encoder Example
Lukas Ruegner edited this page Jun 2, 2024
·
1 revision
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.
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)
}
//...
}
}
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"
}
}
- Getting Started
- Configuration
- Documenting Routes
- Multiple Api-Specs
- Examples
- Changelog
Documentation for previous versions: