Repository navigation
Description
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
- What one union beside a scalar body lowers to (openapi: decide whether a union beside a scalar body is the union or the scalar keeping it #2108).
- The nullable-inference policy widening a
$reffrom a union's null by spelling (openapi: a union's null beside a $ref widens the reference only where the union is written beside it #2109).
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
test(compilers/openapi): cite an open issue for each pair excuse
test(internal/harness): drop the reasons no case finding gives
docs(compilers/openapi): state the landed union rules in place of Status
OmarAlJarrah commentedon Nov 30, 2026
Fixed in #2354 at e7b8705, which closes this on merge. Two unions conjoin and are read together wherever written. With the spec here,
Mixedis now theUniontheanyOf's branches distribute into, keeping theoneOfasvalidation_only, asFlatandEntriesare, where it was aModelkeeping both unions. The schema cases' reason for this issue is gone, as no recorded finding stands under it.