Skip to content

openapi: decide whether a 3.0 array's missing items is judged per allOf entry or per conjunction #2048

In progress

Description

@OmarAlJarrah

Problem

At OpenAPI 3.0, items "MUST be present if the type is array" (3.0.3, Schema Object). The compiler reports a type: array without items as an openapi/missing-array-items warning, but for an allOf it draws that warning at one entry only: the one the allOf lowers from. Which entry that is decides the verdict, so conjunctions that write the same type: array and the same items get different answers by where the items sits:

openapi: 3.0.3
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    X: {type: array, items: {type: string}}
    Ref: {allOf: [{$ref: '#/components/schemas/X'}, {type: array}]}
    H: {allOf: [{type: array}, {items: {type: string}}]}
    J: {allOf: [{type: array}, {type: array, items: {type: string}}]}
    K: {allOf: [{type: array, items: {type: string}}, {type: array}]}
    B: {allOf: [{type: array}, {type: array}]}
$ morphic compile --diag-limit 0 spec.yaml 2>&1 >/dev/null | grep 'warning openapi/missing-array-items' | sed -E 's/: OpenAPI 3.0 requires.*//'
warning openapi/missing-array-items spec.yaml#/components/schemas/H/allOf/0
warning openapi/missing-array-items spec.yaml#/components/schemas/B/allOf/0
  • H warns at allOf/0, though the conjunction as a whole declares items: the second entry's items constrains the same elements.
  • J and K are silent, though each has an entry that is a type: array writing no items (J/allOf/0, K/allOf/1), which 3.0's text holds to the rule as it holds H/allOf/0.
  • B warns at allOf/0 and never at allOf/1, the same declaration beside it.
  • Ref, the same shape beside a $ref, is silent: docs/compilers/openapi.md#missing-array-items reads the conjunction there ("a type: array leaves the elements to it").

So the entry that lowers decides the report (J and K lower from the entry that writes items, H and B from one that does not), and the unit of the rule is the entry in one spelling and the conjunction in the other. The rule's text says an inline allOf branch "that merges in place or restates what a refinement names, is not reported", and "the branch a refinement lowers from is reported as the position it is", so each result above follows its letter. The text does not say whether a conjunction that writes items anywhere is to be reported at all, or whether every array entry is.

The question is what the result should be, and the two readings that make it consistent differ in what they report:

  • Per schema object, as 3.0's text states the requirement: H/allOf/0, J/allOf/0, K/allOf/1 and both entries of B (and A below), each at its own pointer. A twin entry is then reported as the first is.
  • Per conjunction, as Ref is already read: H, J, K silent, since the conjunction writes items; B reported once, at the schema or at its first entry. The warning's own claim, "so only its other keywords constrain its elements", is then true of what it names.

With three entries, {allOf: [{type: array}, {type: array}, {items: {type: string}}]} (A), main reports allOf/0 only, the entry the allOf lowers from, which is the case where the two readings differ most: per schema object it is allOf/0 and allOf/1, per conjunction it is silent. #1996 at afb9140 leaves every result above as it is, and moves the report for {allOf: [{type: array}, {type: array, minItems: 1}]} from allOf/0 to allOf/1, the entry its election lowers from.

Cause

schemaBody (compilers/openapi/internal/schema/schema.go) calls missingArrayItems (array.go) for each schema it lowers as a body, so the report is drawn at a position and at the one entry an allOf lowers as a body, the entry it elects; an entry merged in place is never a body and is not read. missingArrayItemsBesideRef is the one reader of a conjunction, for the keywords beside a $ref, through the admission reading (newAdmission); no caller asks an allOf of inline entries whether any entry writes items (morphic @9562ea46d).

Direction

A draft, with a real choice between the two readings above. Per conjunction needs the admission reading (newAdmission, as missingArrayItemsBesideRef already uses it) for inline entries too, and makes the 3.0 requirement a statement about what the schema as a whole constrains, which is how the rule treats a $ref. Per schema object needs the report at each array entry the lowering merges, which the rule currently exempts, and a statement that a warning at an entry a conjunct elsewhere covers is correct because 3.0 says so of the object. Either way docs/compilers/openapi.md#missing-array-items says which, and a case holds H, J, K and B to it.

Out of scope

Related: #2039, #1996

Priority: P4, rule 2 (the warning is about a document violating 3.0's text, and what it reports is diagnostic volume and placement). jq '[.. | objects | select(.type == "array" and (has("items") | not))] | length' openapi.json → 0: no schema of the golden spec is an array without items (spec @8b1a4518, morphic @9562ea46d).

Activity

  1. added
    type:feature
    priority:P4
    on Nov 17, 2026
  2. OmarAlJarrah commented on Nov 30, 2026

    @OmarAlJarrah
    MemberAuthor

    Decided and fixed in #2354 at acf4512, which closes this on merge: per conjunction (docs/compilers/openapi.md#missing-array-items). One openapi/missing-array-items warning is drawn at the position where no conjunct, a $ref's target included, writes items. With the spec here, H, J, K, A and Ref draw none, and B draws one, at B. A position composing a target that draws its own is reported too: RefY: {allOf: [{$ref: Y}, {type: array}]} over Y: {type: array} draws one at RefY beside Y's.

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:P4type:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions