Repository navigation
Description
Problem
With #1996 (at 6630476), an inline allOf entry writing an enum with members lowers the position as the Enum (the entry's value set decides it, with a warning when the conjuncts share no value). An entry writing enum: [] is not elected: the position composes a Model, keeping the entry's enum and, where the $ref names a scalar, the $ref verbatim too. Beside the allOf, the same enum: [] is a closed Enum with no member.
openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
schemas:
O: {type: object, properties: {a: {type: string}}}
S: {type: string}
EntryObj: {allOf: [{$ref: '#/components/schemas/O'}, {enum: []}]}
WrapObj: {allOf: [{$ref: '#/components/schemas/O'}], enum: []}
EntryStr: {allOf: [{$ref: '#/components/schemas/S'}, {enum: []}]}
WrapStr: {allOf: [{$ref: '#/components/schemas/S'}], enum: []}
EntryFull: {allOf: [{$ref: '#/components/schemas/S'}, {enum: [a]}]}$ morphic compile --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
warning openapi/degraded-construct spec.yaml#/components/schemas/EntryObj: the conjuncts of this allOf share no value (allOf/0: object, allOf/1: no value), so no instance satisfies this schema, which a composition cannot state
info openapi/degraded-construct spec.yaml#/components/schemas/EntryObj/allOf/1: this allOf lowered to a node of kind "model", which has no home for enum written on this inline branch; kept verbatim under Unmodeled
warning openapi/empty-enum spec.yaml#/components/schemas/WrapObj: enum declares no member, so this position accepts no value; lowered as a closed enum with no members
info openapi/degraded-construct spec.yaml#/components/schemas/WrapObj: this position declares allOf beside its enum, and JSON Schema conjoins them where only one can be the value; it lowered as the enum, with allOf kept verbatim under Unmodeled
warning openapi/degraded-construct spec.yaml#/components/schemas/EntryStr: the conjuncts of this allOf share no value (allOf/0: string, allOf/1: no value), so no instance satisfies this schema, which a composition cannot state
info openapi/degraded-construct spec.yaml#/components/schemas/EntryStr/allOf/1: this allOf lowered to a node of kind "model", which has no home for enum written on this inline branch; kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/EntryStr/allOf/0: the schema this $ref names is not an object alone, and a model composes only models, so the $ref is kept verbatim under Unmodeled
warning openapi/empty-enum spec.yaml#/components/schemas/WrapStr: enum declares no member, so this position accepts no value; lowered as a closed enum with no members
info openapi/degraded-construct spec.yaml#/components/schemas/WrapStr: this position declares allOf beside its enum, and JSON Schema conjoins them where only one can be the value; it lowered as the enum, with allOf kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/EntryFull/allOf/0: the value set of this allOf narrows this $ref, and one node holds one value set, so the $ref is kept verbatim under Unmodeled; what its target says of the position still reaches it
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("schemas/(Entry|Wrap)[A-Za-z]+$")) | {id: (.key | split("/") | last), kind: .value.kind, base: (.value.base.target // null | if . then split("/") | last else null end), members: (.value.members | length), unmodeled: (.value.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"EntryFull","kind":"enum","base":null,"members":1,"unmodeled":{"openapi:$ref":"degraded_lowering"}}
{"id":"EntryObj","kind":"model","base":"O","members":0,"unmodeled":{"openapi:enum":"degraded_lowering"}}
{"id":"EntryStr","kind":"model","base":null,"members":0,"unmodeled":{"openapi:$ref":"degraded_lowering","openapi:enum":"degraded_lowering"}}
{"id":"WrapObj","kind":"enum","base":null,"members":0,"unmodeled":{"openapi:$ref":"degraded_lowering"}}
{"id":"WrapStr","kind":"enum","base":null,"members":0,"unmodeled":{"openapi:$ref":"degraded_lowering"}}EntryObj is a Model over O and EntryStr a Model with no base, for schemas no instance satisfies; a consumer that reads Model takes either for a usable object type. The warning says no instance satisfies them, but the IR does not (WrapObj, WrapStr and Plain: {type: object, enum: []} are the empty Enum of docs/ir/enums.md#the-empty-enum). On main (at 9562ea4) the entry spelling composes for an enum with members over an object $ref as well, and draws only an info, so #1996 moves every case but the empty one. openapi: 3.0.3 lowers each alike, with the same two openapi/empty-enum warnings.
What the specifications say of enum: []: JSON Schema 2020-12 (Validation §6.1.2) says the array "SHOULD have at least one element", and its meta-schema accepts an empty one, so at 3.1 the document is valid and the position admits no value. OpenAPI 3.0 takes enum from the draft its Schema Object names, whose validation text requires at least one element, so at 3.0.3 the document is invalid; the compiler draws the same warning at both versions rather than an error, and this issue does not ask to change that.
Not #2064 and not #2063: those are an entry whose $ref names nothing, and an entry whose own type and oneOf share no kind. Here the $ref resolves and the entry writes one keyword.
Cause
decide (compilers/openapi/internal/schema/refinement.go) returns no refinement where the conjuncts share no value (disjoint), which docs/compilers/openapi.md#allof-refinement records as item 5 of its list: such an allOf stays a composition, and "beside an allOf that composes, the value set wins that election". That is why the beside-the-allOf spelling is the Enum and the entry spelling is a Model. Observed at 6630476, #1996 elects an entry's value set with members although the conjuncts share no value, and an empty one it does not; the branch's code was not read for why.
Direction
A draft. Elect an empty value set on an entry as one with members is, so the position is the empty Enum of the other spellings, with the openapi/empty-enum warning. The alternative is to record the asymmetry as the rule: a conjunction that admits nothing composes when written as entries, and a Model over O stays the IR of a schema no object satisfies, which the warning alone tells a consumer.
Out of scope
- An entry whose
$refnames nothing (openapi: a value set on an allOf entry beside a $ref naming nothing composes a model, where beside the $ref it is the value set #2064) and an entry whosetypeandoneOfshare no kind (openapi: an allOf entry whose own type and union share no kind composes a model, where beside the allOf the position is a use of its target #2063). - Whether
enum: []at 3.0 is refused as invalid; it is a warning at both versions today.
Priority: P3, rule 3 (off the golden spec; valid-spec functionality a later emitter needs). jq '[.. | objects | select(has("enum") and (.enum | type == "array") and (.enum | length == 0))] | length' openapi.json → 0, and the same selecting only entries of an allOf → 0 (cloudflare/api-schemas@8b1a4518; #1996 at 6630476).
Activity
OmarAlJarrah commentedon Nov 30, 2026
Fixed in #2354 at c0ff23b, which closes this on merge. An
enum: []beside a$refto a schema stating a type or a set is now the closed emptyEnumits flat twin gives, in every spelling:EntryStr,WrapStr,{$ref: S, enum: []}and{type: string, enum: []}are each the closed emptyEnumofstring, keeping nothing, with oneopenapi/empty-enumwarning where theenum: []is written.EntryObjandWrapObj, over an object, are alike the closed emptyEnumofany.