Skip to content

openapi: an allOf entry's keyword is read for the position only where a list names it, and any other is kept #2210

In progress

Description

@OmarAlJarrah

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:

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, patternProperties and additionalProperties; prefixItems and items; contains, minContains and maxContains; if, then and else (JSON Schema 2020-12 Core and Validation, at each keyword); and at OpenAPI 3.0 nullable with type.
  • Scoped to its object. unevaluatedProperties, unevaluatedItems, $id and the anchors are never read from another conjunct, which the comment on foldKeywords already 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

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

  1. added
    type:bug
    priority:P3
    on Nov 24, 2026
  2. OmarAlJarrah commented on Nov 30, 2026

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at acf4512, which closes this on merge. specrules.KeywordReach classes 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_EveryKeywordOfEveryDialectHasOne holds 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, Entry and Entries carry encoding: {name: base64} beside minLength: 1, as Flat does, keep nothing, and draw no report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P3type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions