oaspec/openapi/external_loader

Support for external $ref values that point at component definitions in a sibling YAML/JSON file — ./other.yaml#/components/schemas/Foo style. Walks components.schemas, pulls referenced schemas from the target file into the main spec, and rewrites the refs to local form.

Supported shapes:

Out of scope (see issue #98 parent):

Name collisions — when an external ref would overwrite an existing local schema, or when two external refs pull in the same fragment name from different files — are surfaced as Diagnostic errors rather than silently dropping one side.

Values

pub fn base_dir_of(path: String) -> option.Option(String)

Helper used by parser.parse_file to compute a spec’s base directory. Empty-string (current working directory) is returned when the filepath module can’t extract a parent — callers can then pass Some("") which resolves relative refs against CWD.

pub fn resolve_external_component_refs(
  spec: spec.OpenApiSpec(spec.Unresolved),
  base_dir: option.Option(String),
  parse_file: fn(String) -> Result(
    spec.OpenApiSpec(spec.Unresolved),
    diagnostic.Diagnostic,
  ),
) -> Result(
  spec.OpenApiSpec(spec.Unresolved),
  diagnostic.Diagnostic,
)

Load every components.schemas entry whose value is an external filesystem ref, merge the referenced schema into the main spec, and rewrite the entry to a local ref. base_dir is the directory of the file this spec was loaded from (used to resolve relative paths).

If base_dir is None (spec loaded from string), external refs are treated as unresolvable and passed through unchanged — downstream validation still rejects them.

Search Document