Repository navigation
Description
Problem
A keyword an inline allOf entry writes is read for the position holding the allOf only where one of four hand-written lists names it: foldKeywords and the cases of foldEntry (compilers/openapi/internal/schema/voices.go), valueConstraintKeywords and collectionBoundKeywords (constraints.go). A keyword none of them names is kept verbatim, whatever it says. So a schema keyword is kept by default, and each one that is read was added by hand.
openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
schemas:
Flat: {type: string, minLength: 1, contentEncoding: base64}
Entry: {type: string, allOf: [{minLength: 1, contentEncoding: base64}]}
Entries: {allOf: [{type: string}, {minLength: 1, contentEncoding: base64}]}$ morphic compile --verify --diagnostics-per-code-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/degraded-construct spec.yaml#/components/schemas/Entry/allOf/0/contentEncoding: contentEncoding is content-vocabulary data the IR holds in ir.Encoding, and this position lowered to a shape with no Encoding field; kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/Entries/allOf/1/contentEncoding: contentEncoding is content-vocabulary data the IR holds in ir.Encoding, and this position lowered to a shape with no Encoding field; kept verbatim under Unmodeled
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("schemas/[A-Za-z]+$")) | {id: (.key | split("/") | last), kind: .value.kind, encoding: (.value.encoding // null), constraints: (.value.constraints // null), kept: (.value.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"Entries","kind":"scalar","encoding":null,"constraints":{"minLength":1,"uniqueItems":false},"kept":{"openapi:contentEncoding":"no_ir_home"}}
{"id":"Entry","kind":"scalar","encoding":null,"constraints":{"minLength":1,"uniqueItems":false},"kept":{"openapi:contentEncoding":"no_ir_home"}}
{"id":"Flat","kind":"scalar","encoding":{"name":"base64"},"constraints":{"minLength":1,"uniqueItems":false},"kept":{}}minLength, which a list names, reaches the scalar in all three. contentEncoding, which none names, reaches it only written flat. Entry and Entries hold no Encoding and keep the keyword under no_ir_home, reported as a position that "lowered to a shape with no Encoding field", though the shape is the Scalar whose Encoding Flat fills. The reason and the report are both false of this input.
Sites of the same mechanism:
items,prefixItemsandformaton an entry of a position naming the kind: openapi: an items on an allOf entry beside a declared array is kept, where beside the allOf it types the list #2039.- A
formaton a conjunct other than an inline principal's: openapi: a format a conjunct writes beside an allOf principal is kept, not read #2107. - A
discriminatoron an entry beside thepropertiesdeclaring its tag: openapi: a discriminator on an inline allOf entry is kept verbatim where beside the allOf it is typed #2052. contentEncoding, shown above, which no issue holds.
Expected: what a keyword does on another conjunct follows from what the keyword is, stated once, and a keyword added to the rule table cannot default to kept.
Cause
foldEntry and folds (voices.go, morphic @9be567bdb) answer false for a keyword outside the lists. A keyword that does not fold is not among what the position's build reads, and what no build read is kept.
Direction
A draft. One table over the schema keywords of the rule table (specrules), each keyword in exactly one class:
- Read from any conjunct. It says the same wherever in the conjunction it is written: a bound,
format,contentEncoding,required, a note. - Moves with its group. JSON Schema defines it by keywords of its own schema object, so the group is read from one conjunct whole:
properties,patternPropertiesandadditionalProperties;prefixItemsanditems;contains,minContainsandmaxContains;if,thenandelse(JSON Schema 2020-12 Core and Validation, at each keyword); and at OpenAPI 3.0nullablewithtype. - Scoped to its object.
unevaluatedProperties,unevaluatedItems,$idand the anchors are never read from another conjunct, which the comment onfoldKeywordsalready says of the unevaluated keywords.
A test holds the table to every keyword of every dialect's rows, as the slot test holds specrules.Slot, so a new keyword fails until it is classed. Where two conjuncts write one keyword or group, today's rules stand, pending #2049.
Alternatives weighed:
- Adding each missing keyword to the lists as its issue is mended leaves the default as kept, and the next keyword unread.
- Reading every keyword as a conjunct of its own is not sound: a keyword of the second class changes what the schema admits when it is parted from its group.
docs/compilers/openapi.md#allof-refinement says a format or items written with no type "qualifies a kind and names none, so it decides nothing". The table replaces that sentence or restates it as the class it describes; either way the rule says so.
Out of scope
- A conjunction whose principal is a
$ref: what a use of a named type does with a keyword narrowing it. openapi: a format a conjunct writes beside an allOf principal is kept, not read #2107 holds that forformat, and the golden spec's sites of an entry'sitemsorformatare of this form. - Where a 3.0 array's missing
itemsis reported (openapi: decide whether a 3.0 array's missing items is judged per allOf entry or per conjunction #2048). - Which class
discriminatortakes, which openapi: a discriminator on an inline allOf entry is kept verbatim where beside the allOf it is typed #2052 settles.
Related: #2039, #2107, #2052, #2049, #2048, #2209
Priority: P3, rule 3 (off the golden spec; valid-spec functionality a later emitter needs). jq '[.. | objects | select((.allOf|type)=="array") | ([del(.allOf)] + [.allOf[] | objects | select(has("$ref")|not)])[] | select((has("type")|not) and (has("format") or has("items") or has("prefixItems") or has("contentEncoding") or has("contentMediaType") or has("discriminator")))] | length' openapi.json → 0: no inline conjunct of an allOf writes one of those keywords without a type of its own (spec @997ede33, morphic @9be567bdb).
Activity
test(compilers/openapi): hold keywords split across allOf to flat twins
OmarAlJarrah commentedon Nov 30, 2026
Fixed in #2354 at acf4512, which closes this on merge.
specrules.KeywordReachclasses every keyword of every dialect row as reaching any conjunct, moving with its group, or scoped to its own object, and a key no row defines is scoped to its object.TestKeywordReach_EveryKeywordOfEveryDialectHasOneholds the table to every row, so a keyword added to the rule table fails until it is classed. The fold set, the union's readers and the rule-consumed readers derive from it. With the spec here,EntryandEntriescarryencoding: {name: base64}besideminLength: 1, asFlatdoes, keep nothing, and draw no report.test(internal/harness): drop the reasons no case finding gives