Resolves $refs in an OpenAPI document.
References to schemas (#/components/schemas/...) are kept: each named
schema becomes its own struct, and keeping the reference is what lets a
schema refer to itself. Every other reference (parameters, responses,
request bodies, headers, examples, ...) is replaced by what it points to.
Rules, from measuring real specs:
- fields next to a
$ref(OpenAPI 3.1 allows asummaryanddescriptionthere; OpenAI's spec has 624) override the target's - only a
$refwhose value is a string is a reference: Cloudflare's spec has a schema with a property named$ref - literal data is never read for references:
example,default,enum,const, an example'svalue, a 3.1 schema'sexampleslist, andx-extensions - references to other files or URLs are not supported yet (none of the surveyed specs use them)
Summary
Functions
Returns what a local reference points to, following the JSON Pointer rules
(~1 is /, ~0 is ~, and percent-encoding is decoded).
Resolves every non-schema reference. Returns an error listing references that point nowhere, point to another document, or form a loop.
Returns the schema name of a schema reference: "#/components/schemas/Pet" -> "Pet".
Whether ref points at a named schema.
Functions
Returns what a local reference points to, following the JSON Pointer rules
(~1 is /, ~0 is ~, and percent-encoding is decoded).
Resolves every non-schema reference. Returns an error listing references that point nowhere, point to another document, or form a loop.
Returns the schema name of a schema reference: "#/components/schemas/Pet" -> "Pet".
Whether ref points at a named schema.