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.
- 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
A wiki with documentation is available here.
Examples showcasing and explaining the functionalities and use cases of this project can be found here.
See modules wiki page for installation instructions.
class MyExampleClass(
val someText: String,
val someNullableInt: Int?,
val someBoolList: List<Boolean>,
)
val jsonSchema = initial<String>()
// Analyze the type using reflection and extract information
.analyzeTypeUsingReflection()
// Generate (independent) json schemas for each associated type (here: `MyExampleClass`, `Int`, `Boolean` and `List<Boolean>`)
.generateJsonSchema()
// Add the simple/short name of the type as the title to the schema
.withTitle(TitleType.SIMPLE)
// Combine the individual schemas into a single schema for `MyExampleClass` by inlining all referenced types.
.compileInlining()
{
"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"
}
}
}