Skip to main content

kontracts

Type-safe JSON Schema DSL for Kotlin used by Konditional for structured value validation.

When to Use This Module

You should use kontracts when you need to:

  • Define custom structured values in feature flags with type-safe validation
  • Express JSON Schema constraints using Kotlin's type system instead of raw JSON
  • Validate configuration payloads at the JSON boundary with explicit schemas
  • Ensure custom value types have compile-time schema definitions

What You Get

  • Type-inferred DSL: Define schemas with schemaRoot { ::property of { ... } }
  • Compile-time safety: Schema structure follows data class structure
  • Runtime validation: Validate JSON against schemas at the configuration boundary
  • Explicit constraints: Minimum, maximum, patterns, and custom validation rules

Alternatives

Without this module, you would need to:

  • Write untyped JSON Schema definitions as raw JSON or YAML strings
  • Manually ensure schema definitions stay in sync with Kotlin data classes
  • Build custom validation logic for every structured value type

Installation

dependencies {
implementation(project(":kontracts"))
}

Guarantees

  • Guarantee: Schemas are expressed as Kotlin types, not untyped JSON strings.

  • Mechanism: Type-inferred DSL (schemaRoot { ::property of { ... } }).

  • Boundary: Runtime JSON validation is explicit; schema correctness does not imply correct business logic.

Next steps