Repository navigation
Description
Problem
A $ref whose pointer names an allOf entry denotes that entry's schema alone. When the entry is {$dynamicRef: '#m'} and #m names a string schema, the reference admits strings (JSON Schema Core 2020-12 §8.2.3.2: the $dynamicRef resolves to the outermost $dynamicAnchor of that name in the dynamic scope, here the document's M). The compiler expands it so when the entry is the reference's target, but the conjunct reading that decides an enclosing allOf skips an entry's $dynamicRef and reads the entry as admitting every kind:
openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
schemas:
M: {$dynamicAnchor: m, type: string}
Q:
allOf:
- {type: object, properties: {a: {type: string}}}
- {$dynamicRef: '#m'}
ViaEntry:
allOf:
- {$ref: '#/components/schemas/Q/allOf/1'}
- {type: object, properties: {b: {type: string}}}
ViaM:
allOf:
- {$ref: '#/components/schemas/M'}
- {type: object, properties: {b: {type: string}}}$ morphic compile --diag-limit 0 spec.yaml >ir.json; echo "exit $?"
info openapi/degraded-construct spec.yaml#/components/schemas/Q/allOf/1: inline allOf branch is merged in place, and nothing reads the rest of it; the branch ($dynamicRef) is kept verbatim under Unmodeled
warning openapi/degraded-construct spec.yaml#/components/schemas/ViaM: the conjuncts of this allOf share no value (allOf/0: string, allOf/1: object), so no instance satisfies this schema, which a composition cannot state
info openapi/dynamic-ref-expanded spec.yaml#/components/schemas/Q/allOf/1/$dynamicRef: $dynamicRef expanded to "t/openapi/components/schemas/M", the one matching $dynamicAnchor in this document
exit 0
$ jq -c '.types | to_entries[] | select(.key | test("schemas/(ViaEntry|ViaM|Q/allOf/1)$")) | {id: (.key | split("/") | .[3:] | join("/")), kind: .value.kind, base: (.value.base.target // "" | split("/") | last), kept: (.value.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"schemas/Q/allOf/1","kind":"scalar","base":"M","kept":{}}
{"id":"schemas/ViaEntry","kind":"model","base":"1","kept":{}}
{"id":"schemas/ViaM","kind":"model","base":"M","kept":{}}ViaM and ViaEntry admit the same values: a string that is also an object, which no instance is. ViaM draws the warning and ViaEntry draws none. ViaEntry is a Model whose base is the node at Q/allOf/1, a Scalar over M, which is a string, with nothing reported at ViaEntry. The same pointer, Q/allOf/1/$dynamicRef, is also told it was kept verbatim (by the report at Q/allOf/1) and that it expanded to M.
With #1996 (at 766a6e4) ViaEntry gets an info that its $ref is "not an object alone, and a model composes only models" and is kept verbatim under openapi:$ref, so it no longer composes over a string; it still draws no warning where ViaM does, and the report at Q/allOf/1/$dynamicRef says "was not expanded because it is written on an allOf entry beside another conjunct" beside the "expanded to M" report at the same pointer.
Cause
dynamicExpansionOf (compilers/openapi/internal/schema/admissions.go) returns no expansion for a statement whose pointer names an allOf entry (writtenAsEntry), because no allOf position expands one: the reading is keyed by where the keyword is written, not by who reads it, so a $ref landing on the entry gets that reading too (#1996 at 766a6e4). On main (9562ea4) the same spec draws no warning for ViaEntry, which is a Model over the entry's node.
Direction
A draft: key the reading on how the entry is reached. An entry of an allOf the position lowers masks no kind there; the same schema reached by a $ref is a schema of its own, and its $dynamicRef expands, as it does at Q/allOf/1 as a node, so ViaEntry reads as ViaM does. The alternative is to leave the entry unexpanded for the reference too, which makes the node at Q/allOf/1 (a Scalar over M) say something the reference's reading denies.
Out of scope
- A
$dynamicRefon the only entry of anallOf(own issue) and the sentence reported for one on an entry. - A
$dynamicRefbeside a$ref(openapi: a $dynamicRef beside a $ref is dropped where the position has no carrier #2009).
Priority: P3, rule 3 (off the golden spec: it writes no $dynamicRef). jq '[.. | objects | select(has("$dynamicRef"))] | length' openapi.json → 0 (spec @8b1a4518, morphic @9562ea46d).
Activity
OmarAlJarrah commentedon Nov 19, 2026
A second site of this mechanism, on
mainat 512f3ee:failedEntry(compilers/openapi/internal/statement/table.go) reads "anallOfentry whose$refnames nothing" off the schema's pointer too, so a$refnaming such an entry reads it as the composition does, whole, and nothing keeps what it writes beside its reference:ViaEntryandViaNamedname the same schema object at two pointers.Namedis aModelholdingaand keeping its$ref; the node atE/allOf/0, whichViaEntryis a use of, is aScalarover the top type holding neithertypenorproperties, with no report at it: the one report naming them speaks ofE's model, which keeps them under its own keys. The document already fails on the unresolved$ref, so this is what the node says beside the error, not a silent pass.Two functions read "an
allOfentry" off a pointer,failedEntryhere andwrittenAsEntryfor the$dynamicRefabove, and they parse it differently: the first takes the last token bystrconv.Atoi, the second bystrconv.ParseUint, so a member+3of a mapping keyedallOf($ref: '#/x-defs/allOf/+3') is an entry to the first alone, and a member7of one is an entry to both, though neither is an entry of anyallOf. Folding the two onto either parse changes what such a document lowers to, so they are left as they are, each naming the other in a comment (#2083). Both go when the statement answers how a schema is reached, as the Direction above drafts: an entry is then a fact of the composition listing it, and no pointer is parsed.test(compilers/openapi): pin the reach decisions' issue rows
OmarAlJarrah commentedon Nov 30, 2026
Fixed in #2354, which closes this on merge. A
$refnaming an entry now reads that entry's schema alone, expanded: with the first spec here,ViaEntrydraws theopenapi/unsatisfiable-schemawarningViaMdraws, and both are the closed bottom (acf4512). The comment's spec lowers as it asks from 7213104:E/allOf/0is theModelholdingaand keeping its$ref, asNamedis, andViaEntrycomposes it asViaNamedcomposesNamed.failedEntryandwrittenAsEntryare gone, so no reader parses a pointer to find an entry.