😸 kt-schema

Runtime Reflection

Table of contents
note

If your classes are @Serializable, use the Serialization-Based Generator instead — it works on all platforms without reflection.

For JVM-only scenarios with classes you don’t own or can’t annotate, use ReflectionClassJsonSchemaGenerator and ReflectionFunctionCallingSchemaGenerator with Kotlin reflection.

Why Runtime Generation?

Primary use case: Third-party library classes

The compile-time (KSP) approach requires you to annotate classes with @Schema, which isn’t possible for:

Runtime generation solves this by using reflection to analyze any class at runtime.

important

Limitations:

Usage

kotlin
// Works with ANY class, even from third-party libraries
import com.thirdparty.library.User  // Not your code!

val generator = me.kpavlov.kt.schema.generator.json.ReflectionClassJsonSchemaGenerator.Default
val schema: JsonSchema = generator.generateSchema(User::class)
val schemaString: String = generator.generateSchemaString(User::class)

Add dependency: me.kpavlov.kt.schema:kt-schema-generator-json:<version>

See Also