Repository navigation
fix(schema): state .default() values in OpenAPI and Avro - #154
Merged
bbasinsk merged 1 commit intoDec 5, 2026
Merged
Conversation
A field declared `int().default(42)` decodes a missing value as 42, but OpenAPI listed it in `required` with no `default`, and its Avro field had no default, so a reader could not read data written before the field existed. Both generators now read the field's `absence()`: - OpenAPI: a `.default()` field leaves `required` and states its value as JSON. A `$ref` property states none, because OpenAPI 3.0 ignores keywords beside `$ref`. A NaN or infinite value is left out. - Avro: a `.default()` field states its value when Avro reads it back unchanged. Avro fills in every union in a default with its first branch, so a value on another branch, or a non-null value inside a nested `.optional()`, leaves the field without a default. Field types and union branch order do not change, so bytes already written read the same way. Refs COOK-1702 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: COOK-1702
Status: reported head
59b23a5· merge readiness ready · risk mediumPR report
bbasinsk/katalyst· PR #154 ·benbasinski97/cook-1702-openapi-and-avro-output-never-state→main· range9809207..59b23a5(merge-base9809207) · head59b23a5. There are no local-only changes.Merge readiness: ready · Risk: medium · head 59b23a5
buildpassed at59b23a5.claude-reviewis not required. It failed in 22 s, before it reviewed anything, as it did on fix(schema): honor wrapped optional fields in OpenAPI and Avro #142.SpecAdapter.ktandOpenAPI.kt(the generated OpenAPI spec)..default()fields, and consumers regenerate clients and register schemas from them. Bytes on the wire and union branch order do not change.$ref).Quality profile
absence()for each field, which removes the twoTODO(COOK-1702)markers. Avro keeps its rendered-type rule only for the null default (AvroSchema.kttoAvroField).avroDatum).toAvroSchema()types are unchanged. Avro's validating parser re-reads every stated default in the tests.Absencefrom #153 now decidesrequired,default, and the Avro default. No generator matchesSchema.Defaultto decide them../gradlew jvmTest testpassed on all modules locally. The new tests that cover stated defaults fail on the base. CIbuildpassed at the head.Blockers: none identified. Main residual risk: clients generated from the spec now treat
.default()fields as optional. Main verification gap: no generated client or OpenAPI validator ran against the new output.1. Delivered behavior
int().default(42)required, no default → not required,default: 42"default": 42. A reader fills in 42 for data written without the field.enumeration<Role>().default(MANAGER)default: "MANAGER""default": "MANAGER"list(person()).default(listOf(Customer(7, null)))(first union case)defaultstated[{"id":7,"email":null}], read back asCustomerlist(person()).default(listOf(Employee(…)))(not the first case), or a non-null value in a nested.optional()defaultstatedCustomer.double().default(NaN)default.default(r)rendered as$ref$ref.optional()fields$refproperty states no default, because OpenAPI 3.0 ignores keywords beside$ref. An inlined record (inlineRefs = true) states it. If COOK-1703 moves to 3.1, references can carrydefault, and this rule should be revisited there..default()field, which it rejected before.2. Change accounting
http-openapischema-avrohttp-openapischema-avro3. Maintainability and bug hotspots
AvroSchema.ktavroDatum). Classification: accepted tradeoff (the ticket's B4 allows "or the field has no Avro default"). Origin: introduced. A default that uses a later case gets no Avro default, so readers of old data still fail for that field, as before. Reordering branches would misread bytes already written, and the ticket forbids it.toAvroField). Classification: accepted tradeoff, from the feat(schema)!: allow one .optional() or .default() per schema #153 review. Origin: pre-existing. This keeps the null default for unions led by anempty()case, whichabsence()reads asRequired..optional()or.default()emits"required": [], which is invalid in OpenAPI 3.0. COOK-1703 tracks this.4. Concept changes and retirement
SchemaObjectgainsdefault: JsonElement?.TODO(COOK-1702)markers. OpenAPIrequirednow excludesAbsence.Defaultas well asAbsence.Null.avroDatum, which converts a value to Avro's default form or rejects it.jsonDefaultandisFiniteinSpecAdapter.kt.5. Review and verification evidence
./gradlew jvmTest test59b23a5tree (before a refactor that only inlined a helper), local./gradlew :schema-avro:jvmTest :http-openapi:jvmTest59b23a5, localAvroSchema.ktfrom the basebuild(required)59b23a559b23a5claude-reviewfailed before it reviewed anything.DefaultSchemaObjectTest"default field is not required and states its default"http-openapi59b23a5AvroDefaultTest"reader with a default fills in data written before the field existed"schema-avro59b23a5AvroDefaultTest"values written by the previous schema read back unchanged" plus "stating a default changes no field type"schema-avro59b23a5AvroDefaultTest"default Avro would read as another union branch is not stated"schema-avro59b23a559b23a5AvroSchemaTestand the field-type testschema-avro59b23a5http-openapi59b23a56. Human attention
Human-review list (generated OpenAPI spec):
SpecAdapter.kt:requiredanddefaultcome fromabsence()for each record field.OpenAPI.kt:SchemaObject.default.Outstanding:
What
A
.default()field now leaves OpenAPIrequiredand states itsdefault. In Avro it gets a field default whenever Avro reads that default back unchanged.Why
int().default(42)decodes a missing value as42in every decoder. The generated output did not say so:How to verify
Run
./gradlew :schema-avro:jvmTest :http-openapi:jvmTest. The tests are inAvroDefaultTestandDefaultSchemaObjectTest.Out of scope
$refsiblings and the emptyrequiredarray (COOK-1703).Risk + rollback
To roll back, revert the PR. No field type or union branch order changes.
🤖 Generated with Claude Code