Naming Bindings¶
schema2class keeps wire names in the IR as schemaName and generated Kotlin
identifiers as kotlinName. For schemas with abbreviated wire fields, JSON
Schema generation can apply friendlier Kotlin names without changing the source
schema.
Precedence¶
For JSON Schema, generated names currently resolve in this order:
- Programmatic
NamingStrategy - External binding file
- Schema extensions:
x-object-namefor properties,x-object-typefor types - Sanitized conventions from
title - Wire key fallback
Property and type names are independent. For array properties, schema2class uses
the item title when available and pluralizes it, so an array whose item title is
IntersectionState becomes intersectionStates.
Binding File¶
Use Type.property = friendlyName for properties and SchemaType = FriendlyType
for types:
# names.conf
Payload.rg = region
Payload.sl = intersectionStateList
Payload = FriendlyPayload
The left side may use either the source schema type name or the generated type name for property overrides. Binding files are consumer-local sidecars, so shared schemas do not need Kotlin-specific metadata.
CLI:
schema2class generate \
--input payload.schema.json=com.corp.payload \
--name-bindings names.conf \
--output build/generated/schema2class/kotlin
Gradle:
schema2class {
schemas {
create("payload") {
source = file("schemas/payload.schema.json")
packageName = "com.corp.payload"
nameBindings = file("schemas/names.conf")
}
}
}