Skip to content

openapi: a oneOf beside an allOf whose entry writes an anyOf lowers apart from the two on one schema #2110

In progress

Description

@OmarAlJarrah

Problem

A oneOf and an anyOf conjoin wherever they are written. Written with one beside an allOf and the other on an entry of it, they lower apart from the same two written on one schema, and from the same two on two entries:

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    T: {type: object, properties: {a: {type: string}}}
    Flat:
      type: object
      properties: {a: {type: string}}
      oneOf: [{required: [a]}]
      anyOf: [{properties: {x: {type: string}}}, {properties: {y: {type: string}}}]
    Entries:
      allOf:
        - {$ref: '#/components/schemas/T'}
        - {oneOf: [{required: [a]}]}
        - {anyOf: [{properties: {x: {type: string}}}, {properties: {y: {type: string}}}]}
    Mixed:
      allOf:
        - {$ref: '#/components/schemas/T'}
        - {anyOf: [{properties: {x: {type: string}}}, {properties: {y: {type: string}}}]}
      oneOf: [{required: [a]}]
$ morphic compile --verify --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/degraded-construct spec.yaml#/components/schemas/Mixed/allOf/1: this allOf lowered to a node of kind "model", which has no home for anyOf written on this inline branch; kept verbatim under Unmodeled
info openapi/validation-only-keyword spec.yaml#/components/schemas/Mixed: validation-only keyword "oneOf" kept verbatim under Unmodeled
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("^t/openapi/components/schemas/(Flat|Entries|Mixed)$")) | .value | {id: .name.source, kind, variants: [.variants[]?.type.target | sub("^t/"; "")], unmodeled: (.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"Entries","kind":"union","variants":["composed/components/schemas/Entries/allOf/2/anyOf/0","composed/components/schemas/Entries/allOf/2/anyOf/1"],"unmodeled":{}}
{"id":"Flat","kind":"union","variants":["composed/components/schemas/Flat/oneOf/0"],"unmodeled":{}}
{"id":"Mixed","kind":"model","variants":[],"unmodeled":{"openapi:anyOf":"degraded_lowering","openapi:oneOf":"validation_only"}}

(The findings shown are Mixed's; the other two schemas draw their own.) Mixed is a Model keeping both unions: no Union is built, though the anyOf's branches declare shape and the other two spellings distribute a union. The same holds with the keywords the other way round (anyOf beside the allOf, oneOf on an entry) and one allOf deeper, beside every kind of body.

Expected: one result for one conjunction, the one docs/compilers/openapi.md#competing-keywords gives the two written on one schema.

Direction

A draft. The rule for a oneOf and an anyOf together is implemented once for each place they can be written: on one schema, beside an allOf, on its entries. The mixed spellings fall between those implementations, and each implementation can drift from the others on a pair none of its tests writes. Read every spelling through ONE implementation: a union written beside an allOf is one more conjunct of that allOf, and a schema writing both unions with no allOf is the same conjunction with no entries, so the election, the null of the pair, the reading of two unions sharing no value and the kept union's reason each exist once. The alternative, a fourth implementation for the mixed spellings, adds one more copy to keep in step.

Out of scope

Related: #2011

Priority: P3, rule 3 (off the golden spec). jq '[.. | objects | select((.allOf|type)=="array" and (has("oneOf") or has("anyOf")) and ([.allOf[]|select(type=="object" and (has("oneOf") or has("anyOf")))]|length)>=1)] | length' openapi.json → 0: no schema writes a union beside an allOf one of whose entries writes a union (spec @8b1a4518, morphic @80340b71b).

Activity

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

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at e7b8705, which closes this on merge. Two unions conjoin and are read together wherever written. With the spec here, Mixed is now the Union the anyOf's branches distribute into, keeping the oneOf as validation_only, as Flat and Entries are, where it was a Model keeping both unions. The schema cases' reason for this issue is gone, as no recorded finding stands under it.

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