Skip to content

openapi: a $dynamicRef on the only entry of an allOf is reported as written beside another conjunct #2056

In progress

Description

@OmarAlJarrah

Problem

With #1996 (at 766a6e4) a $dynamicRef on an allOf entry is kept verbatim and reported as "written on an allOf entry beside another conjunct, which the IR cannot intersect with it". That is the reason only where the allOf has another conjunct. On an allOf of one entry there is none, yet the same report is drawn, and the keyword is kept where the same schema written without the allOf is expanded:

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    M: {$dynamicAnchor: m, type: object, properties: {m: {type: string}}}
    Bare: {$dynamicRef: '#m'}
    Lone: {allOf: [{$dynamicRef: '#m'}]}
    Beside: {allOf: [{$ref: '#/components/schemas/M'}, {$dynamicRef: '#m'}]}
$ morphic compile --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/dynamic-ref-expanded spec.yaml#/components/schemas/Bare/$dynamicRef: $dynamicRef expanded to "t/openapi/components/schemas/M", the one matching $dynamicAnchor in this document
info openapi/degraded-construct spec.yaml#/components/schemas/Lone/allOf/0/$dynamicRef: $dynamicRef was not expanded because it is written on an allOf entry beside another conjunct, which the IR cannot intersect with it; it is kept verbatim under Unmodeled
info openapi/degraded-construct spec.yaml#/components/schemas/Beside/allOf/1/$dynamicRef: $dynamicRef was not expanded because it is written on an allOf entry beside another conjunct, which the IR cannot intersect with it; it is kept verbatim under Unmodeled
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("openapi/components/schemas/(Bare|Lone|Beside)$")) | {id: (.key | split("/") | last), kind: .value.kind, base: (.value.base.target // null), kept: (.value.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"Bare","kind":"scalar","base":"t/openapi/components/schemas/M","kept":{}}
{"id":"Beside","kind":"model","base":"t/openapi/components/schemas/M","kept":{"openapi:$dynamicRef":"degraded_lowering"}}
{"id":"Lone","kind":"scalar","base":"t/prim/any","kept":{"openapi:$dynamicRef":"degraded_lowering"}}

Beside is the case the sentence describes. Lone has no other conjunct, so the stated reason is false for it, and it lowers to an alias of the top type holding openapi:$dynamicRef, where Bare, the same schema without the allOf, is an alias of M. On main (9562ea4) Lone is a Model with no base keeping the entry under openapi:allOf/0, reported as "inline allOf branch is merged in place, and nothing reads the rest of it", so the false sentence is new to #1996.

Cause

keepEntryDynamicRef (compilers/openapi/internal/schema/entrykept.go) keeps the keyword of an inline entry and draws the report for every one, on the ground its comment gives, that "no entry expands one, as it is a conjunct the IR cannot intersect with the rest". The sentence never asks whether the allOf has a rest (#1996 at 766a6e4).

Direction

A draft: where the entry is the only conjunct the keyword expands as it does written bare, with the same info; where another conjunct exists the sentence stays. The alternative, if a lone entry is meant to be kept, is a sentence that gives the reason that holds for it.

Out of scope

Related: #1996, #2009

Priority: P4, rule 3 (off the golden spec, and diagnostic wording). jq '[.. | objects | select(has("$dynamicRef"))] | length' openapi.json → 0 (spec @8b1a4518, morphic @766a6e447).

Activity

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

    @OmarAlJarrah
    MemberAuthor

    Fixed in #2354 at acf4512, which closes this on merge. An allOf entry is now read as the composition listing it reaches it, and the only entry stands in place: Lone: {allOf: [{$dynamicRef: '#m'}]} expands as Bare does, to the Model over M, with the same openapi/dynamic-ref-expanded info and nothing kept. Nested one-entry allOfs around such an entry expand the same way. Beside keeps its $dynamicRef with the sentence about another conjunct, which is true of 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:P4type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions