Skip to content

openapi: an empty enum on an allOf entry composes a model, where an enum with members and the same enum beside the allOf do not #2066

In progress

Description

@OmarAlJarrah

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

Related: #2064, #2063, #1996

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

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

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at c0ff23b, which closes this on merge. An enum: [] beside a $ref to a schema stating a type or a set is now the closed empty Enum its flat twin gives, in every spelling:

    S: {type: string}
    EntryStr: {allOf: [{$ref: '#/components/schemas/S'}, {enum: []}]}
    WrapStr: {allOf: [{$ref: '#/components/schemas/S'}], enum: []}

    EntryStr, WrapStr, {$ref: S, enum: []} and {type: string, enum: []} are each the closed empty Enum of string, keeping nothing, with one openapi/empty-enum warning where the enum: [] is written. EntryObj and WrapObj, over an object, are alike the closed empty Enum of any.

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