Schema Kenerator
The schema-kenerator project consists of multiple artifacts that are used together with the goal to extract information from types and generate different schemas. It is designed as a pipeline of individual steps to be highly configurable and flexible to match any situation.
Features
- Analyze Java and Kotlin types using reflection or Kotlinx.Serialization
- complex class configurations
- recursion
- collections, maps, enums
- inheritance
- type parameters
- annotations
- nullability and default values
- inline types
- ...
- Enhance types with additional information
- Generate schemas
- Highly configurable and customizable schema generation pipeline by adding new processing steps and creating own modules
Installation
For installation instructions, see the modules overview page.
Example
class MyExampleClass(
val someText: String,
val someNullableInt: Int?,
val someBoolList: List<Boolean>,
)
val jsonSchema = initial<String>()
.analyzeTypeUsingReflection() //(1)!
.generateJsonSchema() //(2)!
.withTitle(TitleType.SIMPLE) //(3)!
.compileInlining() //(4)!
- Analyze the type using reflection and extract information
- Generate (independent) json schemas for each associated type (here:
MyExampleClass
,Int
,Boolean
andList<Boolean>
) - Add the simple/short name of the type as the title to the schema
- Combine the individual schemas into a single schema for
MyExampleClass
by inlining all referenced types.
{
"title": "MyExampleClass",
"type": "object",
"required": ["someBoolList", "someText"],
"properties": {
"someBoolList": {
"title": "List<Boolean>",
"type": "array",
"items": {
"title": "Boolean",
"type": "boolean"
}
},
"someNullableInt": {
"title": "Int",
"type": "integer",
"minimum": -2147483648,
"maximum": 2147483647
},
"someText": {
"title": "String",
"type": "string"
}
}
}