Skip to content

SMILEY4/schema-kenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Schema Kenerator

Version Checks Passing 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
    • complex class configurations
    • recursion
    • collections, maps, enums
    • inheritance
    • type parameters
    • annotations
    • nullability and default values
    • inline types
    • ...
  • Enhance types with additional information
    • Jackson annotations
    • Swagger annotations
    • Javax/Jakarta validation annotations
    • ...
  • Generate schemas
  • Highly configurable and customizable schema generation pipeline by adding new processing steps and creating own modules

Documentation

A wiki with documentation is available here.

Examples showcasing and explaining the functionalities and use cases of this project can be found here.

Installation

See modules wiki page for installation instructions.

Example

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"
    }
  }
}

About

Analyze kotlin types, extract information and generate schemas

Topics

Resources

License

Stars

Watchers

Forks

Contributors 7

Languages