Repository navigation
Description
Problem
docs/compilers/openapi.md#allof-inline-residue folds the keywords an inline allOf entry writes into the node the allOf lowers to (a bound among them) and says a branch that disagrees with any conjunct on one of those keywords "folds nothing, in every order": the whole entry is kept verbatim under Unmodeled. The unit is the entry, not the keyword, so a bound every conjunct states is dropped from Constraints when the same entries differ on an annotation:
openapi: 3.0.3
info: {title: t, version: "1"}
paths: {}
components:
schemas:
Agree: {allOf: [{type: string, minLength: 2, description: a}, {type: string, minLength: 2, description: a}]}
Differ: {allOf: [{type: string, minLength: 2, description: a}, {type: string, minLength: 2, description: b}]}
Beside: {allOf: [{type: string, minLength: 2, description: a}], description: b}
BesideNone: {allOf: [{type: string, minLength: 2}], description: b}$ morphic compile --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/degraded-construct spec.yaml#/components/schemas/Differ/allOf/0: the conjuncts of this allOf disagree on a keyword this inline branch writes, so nothing it writes folds; the branch (minLength, description) is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/Differ/allOf/1: the conjuncts of this allOf disagree on a keyword this inline branch writes, so nothing it writes folds; the branch (minLength, description) is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/Beside/allOf/0: the conjuncts of this allOf disagree on a keyword this inline branch writes, so nothing it writes folds; the branch (minLength, description) is kept verbatim under Unmodeled
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("openapi/components/schemas/(Agree|Differ|Beside|BesideNone)$")) | {id: (.key | split("/") | last), minLength: .value.constraints.minLength, description: .value.docs.description, kept: (.value.unmodeled // {} | keys)}' ir.json
{"id":"Agree","minLength":2,"description":"a","kept":[]}
{"id":"Beside","minLength":null,"description":"b","kept":["openapi:allOf/0"]}
{"id":"BesideNone","minLength":2,"description":"b","kept":[]}
{"id":"Differ","minLength":null,"description":null,"kept":["openapi:allOf/0","openapi:allOf/1"]}Differ is a Scalar over string with no minLength and no description, with both entries kept whole: the bound the two entries agree on is on neither the node nor its Constraints, and the description is dropped too. Beside loses the bound that BesideNone, the same entry without a description, keeps. The text the compiler keeps verbatim holds both values, so nothing is lost from the IR as a whole, but a consumer reading the node's Constraints for what the schema validates reads a string with no minimum, where every conjunct says 2. A description is an annotation: JSON Schema collects the two without one overriding the other (2020-12 §7.7), so it parts nothing about which strings the schema admits. minLength: 2 against minLength: 3 in two entries with no description folds to 3 as the rule says (a bound meets as maxLength: 3 beside maxLength: 5 does).
By design the rule keeps the entry whole where it disagrees on any one of the folded keywords, "so the source stays reconstructable rather than having to be reassembled from two places". That is a choice of unit rather than of content: folding minLength here and keeping the entry whole, as now, would still leave the source reconstructable.
#1996 at afb9140 compiles Differ and Beside as above (same diagnostics, same node).
Cause
The entry-wide verdict, "the conjuncts of this allOf disagree on a keyword this inline branch writes, so nothing it writes folds", is one decision per branch: one keyword in disagreement keeps every keyword the branch writes, those no conjunct disputes among them (docs/compilers/openapi.md#allof-inline-residue, morphic @9562ea46d).
Direction
A draft, with a real choice. The question is whether the unit of folding is the entry or the keyword.
- Fold per keyword. A keyword folds where no conjunct disputes it (every writer agrees, or only one conjunct writes it), and an entry is kept whole only for the keywords it could not fold, its consumed keywords included, as now.
Differthen hasminLength: 2on its node, the description disagreement unresolved and both entries kept;BesidehasminLength: 2and the description beside theallOf. The report names the keywords that disagreed, as it names the branch's keywords now. It costs a second reading of the rule (a keyword may fold from an entry that is also kept) and a change to what "folds nothing, in every order" promises, since the order-independence now has to hold per keyword. - Leave the unit. The rule stays as written, and its text says that an annotation disagreement keeps a bound with it. It costs a consumer the bound of a schema whose author wrote two descriptions.
A narrower variant of the first: only an annotation's disagreement (description, title, example, externalDocs) stops holding the validation keywords back, since an annotation does not part the admitted instances.
Out of scope
- Two bounds that disagree in value, which meet as the rule says.
items,formatandprefixItemson an entry, which the rule does not fold at all (openapi: an items on an allOf entry beside a declared array is kept, where beside the allOf it types the list #2039).
Priority: P3, rule 3 (off the golden spec; valid-spec functionality a later emitter needs). morphic compile --diag-limit 0 openapi.json >ir.json; jq '[.diagnostics[] | select(.message | test("disagree on a keyword this inline branch writes"))] | length' ir.json → 0 of the 4961 diagnostics: no allOf entry of the golden spec is kept for a disagreement (spec @8b1a4518, morphic @9562ea46d).
Activity
test(compilers/openapi): pin the reach decisions' issue rows
OmarAlJarrah commentedon Nov 30, 2026
Decided and fixed in #2354 at acf4512, which closes this on merge: a keyword folds by its own writers, and a group of keywords only whole. With the spec here,
DifferandBesideholdminLength: 2, asAgreeandBesideNonedo. Their entries stay kept whole for thedescriptionthey disagree on, and the report now says so: "… so what they disagree on does not fold, though what they agree on does; the entry (description) is kept verbatim under Unmodeled".