fix(compilers/openapi): elect an alias tag by byte order - #455
Open
fuad-daoud wants to merge 1 commit into
Open
Conversation
A discriminator mapping may spell several keys for one subtype — an alias tag — and Model.DiscriminatorValue holds one. The subtype took whichever key was written first, so two documents differing only in the order of two mapping lines lowered differently, with no diagnostic in either (GitHub #410). A mapping is unordered, so its key order is not a property of the document. The subtype now takes the smallest key in byte order, whichever was written first. The base's Discriminator.Mapping keeps every key, so the election narrows what the subtype's field shows and loses nothing, and it is reported at the subtype as an info degraded-construct so a reader knows the tag set is wider than the field. ir-design's OpenAPI lowering row records the rule. A conformance fixture declares the keys larger-first — the order a first-key-wins reading gets wrong — so the order-invariance oracle meets the shape from now on, which no committed spec had let it do. Closes #410 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJZJ8HaugGZTjzVueafLAT
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.
Summary
A discriminator mapping may spell several keys for one subtype — an alias tag — and
Model.DiscriminatorValueholds one. The subtype took whichever key was written first, so two documents differing only in the order of two mapping lines lowered differently, with no diagnostic in either (#410). A mapping is unordered, so its key order is not a property of the document, and this is the class of order-dependence the order-invariance oracle exists to reject — it just never met the shape, because no committed spec declared two keys for one target.The subtype now takes the smallest key in byte order, whichever was written first. That is an election rule rather than a heuristic: which key the author "meant" is not knowable, either is valid on the wire, and the base's
Discriminator.Mappingkeeps every key, so the routing table an emitter needs for deserialization is intact. The election narrows what the subtype's field shows and loses nothing, and it is reported at the subtype as aninfoopenapi/degraded-constructnaming every key, so a reader knows the tag set is wider than the field.ir-design.md's OpenAPI lowering row records the rule beside the other election rules (const/enum/allOf,oneOfoveranyOf).mappingTagsForis the only site that picks from a mapping;discriminatorMappingkeeps every key anddiscriminatorDefaultis single-valued by construction, so there is no second site of the mechanism.Test plan
TestAllOf_DiscriminatorAliasTagIsOrderInvariant(new,internal/schema): the issue's document in both key orders, the larger-first order included — the one a first-key-wins reading gets wrong. Red before the fix on that order, green after.discriminator-alias-mapping.yaml, witnessingtagged-unions, declared larger-first for the same reason. Planting first-key-wins back reddens all three guards: the unit test, the golden, andmorphic-harness, which now reportsorder-dependent type registryon the fixture — so the oracle meets this shape from now on.make gatepasses: lint 0 issues, coverage at 100%, fuzz, bench-smoke.Closes #410
🤖 Generated with Claude Code
https://claude.ai/code/session_01TJZJ8HaugGZTjzVueafLAT