SchemaGenerator

class SchemaGenerator(warn: (String) -> Unit)(source)

Generates OpenAPI 3.1 (JSON Schema) schemas from Kotlin IR types, mirroring how the ktkit runtime serializes values with kotlinx.serialization:

  • @Serializable classes become named component schemas referenced with $ref.

  • Property names respect @SerialName, @Transient properties are omitted.

  • Properties inherited from @Serializable superclasses are included (base-class first).

  • Generic classes get one component per instantiation (e.g. PageOfTestDto), with type parameters substituted by the concrete type arguments.

  • Sealed hierarchies become oneOf over the concrete leaves with an @type discriminator (ktkit's classDiscriminator).

  • Nullable types allow null; properties with default values are not required.

All named schemas end up in components; one generator instance is used per handler class so the collected components land in that handler's fragment.

Constructors

Link copied to clipboard
constructor(warn: (String) -> Unit)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Named component schemas collected while generating (component key → schema).

Functions

Link copied to clipboard

Registers ktkit's standard ApiError schema as a component and returns a $ref to it. The descriptions follow RFC 9457 (Problem Details for HTTP APIs) — keep them in sync with the @OpenApiInfo annotations on io.github.smyrgeorge.ktkit.api.rest.ApiError.

Link copied to clipboard
fun enumParamSchema(cls: IrClass): JsonNode.Obj

An enum schema listing the Kotlin entry names — what Var.asEnum() (enumValueOf) accepts.

Link copied to clipboard
fun schemaFor(type: IrType?): JsonNode.Obj