Skip to content

openapi: an items on an allOf entry beside a declared array is kept, where beside the allOf it types the list #2039

In progress

Description

@OmarAlJarrah

Problem

items applies to the elements of the array it is written beside, so an allOf entry writing it constrains the array the position declares as much as the same items written beside the allOf. The two spellings lower apart:

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    Beside: {type: array, items: {type: string}}
    Entry: {type: array, allOf: [{items: {type: string}}]}
    EntryPrefix: {type: array, allOf: [{prefixItems: [{type: string}]}]}
    EntryFormat: {type: string, allOf: [{format: uuid}]}
    EntryProps: {type: object, allOf: [{properties: {a: {type: string}}}]}
$ morphic compile --verify --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/degraded-construct spec.yaml#/components/schemas/Entry/allOf/0: this allOf lowered to a use of one of its conjuncts, which has no home for what this inline branch adds; the branch (items) is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/EntryPrefix/allOf/0: this allOf lowered to a use of one of its conjuncts, which has no home for what this inline branch adds; the branch (prefixItems) is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/EntryFormat/allOf/0: this allOf lowered to a use of one of its conjuncts, which has no home for what this inline branch adds; the branch (format) is 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, elem: (.value.elem.target // null), base: (.value.base.target // null), props: [.value.properties[]?.name.source], kept: (.value.unmodeled // {} | keys)}' ir.json
{"id":"Beside","kind":"list","elem":"t/prim/string","base":null,"props":[],"kept":[]}
{"id":"Entry","kind":"list","elem":"t/prim/any","base":null,"props":[],"kept":["openapi:allOf/0"]}
{"id":"EntryFormat","kind":"scalar","elem":null,"base":"t/prim/string","props":[],"kept":["openapi:allOf/0"]}
{"id":"EntryPrefix","kind":"list","elem":"t/prim/any","base":null,"props":[],"kept":["openapi:allOf/0"]}
{"id":"EntryProps","kind":"model","elem":null,"base":null,"props":["a"],"kept":[]}

Beside is a list of strings. Entry is a list of the top type: the element type is not read, and the entry is kept whole under Unmodeled["openapi:allOf/0"]. EntryPrefix is likewise a list of the top type where a tuple of one string is meant, and EntryFormat a plain string that says nothing of uuid. EntryProps, the contrast, reads the entry's properties as the position's.

Expected: Entry lowers as Beside does, a list of string, and EntryPrefix and EntryFormat as {type: array, prefixItems: [{type: string}]} and {type: string, format: uuid} do, with nothing kept for what each consumed.

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", because "a schema built from two would stand at a pointer naming neither". That holds for entries that each leave the kind out, as in its {allOf: [{type: integer}, {format: int32}]}. It does not hold here, where the position itself names the kind, so the schema the keyword qualifies is the position's own.

Cause

A refinement folds a keyword of a branch only into a principal that already says it (docs/compilers/openapi.md#allof-refinement), and docs/compilers/openapi.md#allof-inline-residue lists what a branch merges and folds: properties, required, a bare type: object, bounds and annotations. items, prefixItems and format are in neither list, so a branch writing one is kept whole (morphic @9562ea46d).

Direction

A draft: read a branch's items, prefixItems or format as written beside the allOf where the position, or the principal the refinement elects, names the kind they qualify, and keep the branch only where they disagree with what the principal already says. Two entries that each leave the kind out stay as the rule says.

Out of scope

Related: #1998, #1855, #1067

Priority: P3, rule 3 (off the golden spec; valid-spec functionality a later emitter needs). An allOf inline entry writing items, prefixItems or format and no type:

$ jq '[.. | objects | select((.allOf | type) == "array") | .allOf[] | select(type == "object" and (has("$ref") | not) and (has("type") | not) and (has("items") or has("prefixItems") or has("format")))] | length' openapi.json
0

(spec @8b1a4518, morphic @9562ea46d).

Activity

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

    @OmarAlJarrah
    MemberAuthor

    Another keyword at the same cause: a type list on an inline entry. The in-place merge of an inline entry reads type: object alone, so a list that also admits null is not read, and the entry is kept where the same list beside the allOf is consumed.

    openapi: 3.1.0
    info: {title: t, version: "1"}
    paths: {}
    components:
      schemas:
        T: {type: object, properties: {a: {type: string}}}
        Wrap: {allOf: [{$ref: '#/components/schemas/T'}], type: [object, "null"]}
        Entry: {allOf: [{$ref: '#/components/schemas/T'}, {type: [object, "null"]}]}
    $ morphic compile --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
    info openapi/degraded-construct spec.yaml#/components/schemas/Entry/allOf/1: inline allOf branch is merged in place, and nothing reads the rest of it; the branch (type) is kept verbatim under Unmodeled
    exit 0
    $ jq -c '.types | to_entries[] | select(.key | test("schemas/(Wrap|Entry)$")) | {id: (.key | split("/") | last), kind: .value.kind, base: (.value.base.target | split("/") | last), unmodeled: (.value.unmodeled // {} | map_values(.reason))}' ir.json
    {"id":"Entry","kind":"model","base":"T","unmodeled":{"openapi:allOf/1":"degraded_lowering"}}
    {"id":"Wrap","kind":"model","base":"T","unmodeled":{}}

    Both schemas admit exactly what T admits: T declares type: object, so the null the list adds is refused in either spelling. Wrap is the Model over T with nothing kept; Entry is the same Model keeping the entry with an info (morphic @9562ea46d). With #1996 the entry's keyword is kept under openapi:type in place of openapi:allOf/1, and the two spellings still differ.

  3. OmarAlJarrah commented on Nov 28, 2026

    @OmarAlJarrah
    MemberAuthor

    Another site of this mechanism: writing type: array on an allOf entry beside items or prefixItems on the enclosing schema (e.g. {"items": {"type": "string"}, "allOf": [{"type": "array"}]}), as well as writing type on an allOf entry beside any collection or object applicator on the enclosing schema. Both spellings will lower identically with the flat array/object spelling under #2211.

  4. OmarAlJarrah commented on Nov 30, 2026

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at acf4512, which closes this on merge. A node built from one conjunct now takes items, prefixItems and format off whichever conjunct writes them. With the spec here, Entry is a List of string as Beside is, EntryPrefix a Tuple, and EntryFormat a uuid, each keeping nothing and drawing no report. From the comments: {allOf: [{$ref: T}, {type: [object, "null"]}]} merges the list and keeps nothing, as Wrap does, and {items: {type: string}, allOf: [{type: array}]} is a List of string.

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