https://github.com/smiley4/schema-kenerator
Analyze kotlin types, extract information and generate schemas
https://github.com/smiley4/schema-kenerator
json-schema kotlin kotlinx-serialization openapi reflection schema swagger
Last synced: 22 days ago
JSON representation
Analyze kotlin types, extract information and generate schemas
- Host: GitHub
- URL: https://github.com/smiley4/schema-kenerator
- Owner: SMILEY4
- License: apache-2.0
- Created: 2023-12-09T07:47:25.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2025-04-07T15:26:56.000Z (about 2 months ago)
- Last Synced: 2025-05-03T11:02:46.902Z (about 1 month ago)
- Topics: json-schema, kotlin, kotlinx-serialization, openapi, reflection, schema, swagger
- Language: Kotlin
- Homepage: https://smiley4.github.io/schema-kenerator/
- Size: 5.27 MB
- Stars: 22
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Schema Kenerator
[](https://search.maven.org/search?q=g:io.github.smiley4%20a:schema-kenerator-*)
[](https://github.com/SMILEY4/schema-kenerator/actions/workflows/checks.yml)
[](https://github.com/SMILEY4/schema-kenerator/blob/develop/LICENSE)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](https://github.com/Kotlin/kotlinx.serialization)
- complex class configurations
- recursion
- collections, maps, enums
- inheritance
- type parameters
- annotations
- nullability and default values
- inline types
- ...
- Enhance types with additional information
- [Jackson](https://github.com/FasterXML/jackson) annotations
- [Swagger](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations) annotations
- Javax/Jakarta validation annotations
- ...
- Generate schemas
- [JSON schema](https://json-schema.org/)
- [Swagger schema](https://swagger.io/docs/specification/v3_0/data-models/data-models/)
- Highly configurable and customizable schema generation pipeline by adding new processing steps and creating own modules## Documentation
A wiki with documentation is available [here](https://smiley4.github.io/schema-kenerator/latest).
Examples showcasing and explaining the functionalities and use cases of this project can be found [here](https://github.com/SMILEY4/schema-kenerator/tree/develop/schema-kenerator-examples/src/test/kotlin/io/github/smiley4/schemakenerator/examples).
## Installation
See [modules](https://smiley4.github.io/schema-kenerator/latest/modules/) wiki page for installation instructions.
## Example
```kotlin
class MyExampleClass(
val someText: String,
val someNullableInt: Int?,
val someBoolList: List,
)
```
```kotlin
val jsonSchema = initial()
// Analyze the type using reflection and extract information
.analyzeTypeUsingReflection()
// Generate (independent) json schemas for each associated type (here: `MyExampleClass`, `Int`, `Boolean` and `List`)
.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()
```
```json
{
"title": "MyExampleClass",
"type": "object",
"required": ["someBoolList", "someText"],
"properties": {
"someBoolList": {
"title": "List",
"type": "array",
"items": {
"title": "Boolean",
"type": "boolean"
}
},
"someNullableInt": {
"title": "Int",
"type": "integer",
"minimum": -2147483648,
"maximum": 2147483647
},
"someText": {
"title": "String",
"type": "string"
}
}
}
```