Apical.RemoteRefs (apical v0.3.2)

Copy Markdown View Source

Handles resolution of remote $ref references from a local cache.

Remote references (URLs starting with http:// or https://) are resolved from a local cache directory. The URL is converted to a file path within the cache directory.

For example, with cache directory /app/cache:

  • https://example.com/schemas/user.json -> /app/cache/example.com/schemas/user.json

Usage

Configure the cache directory via the :remote_refs_cache option:

Apical.router_from_string(schema,
  remote_refs_cache: "priv/openapi_cache"
)

Populating the Cache

The cache must be populated manually before compilation. You can use curl or a similar tool to download schemas:

mkdir -p priv/openapi_cache/example.com/schemas
curl -o priv/openapi_cache/example.com/schemas/user.json \
     https://example.com/schemas/user.json

Summary

Functions

Resolves all remote refs in a schema, inlining them from the cache.

Functions

resolve(schema, opts)

@spec resolve(
  map(),
  keyword()
) :: map()

Resolves all remote refs in a schema, inlining them from the cache.

Returns the schema with remote refs converted to local refs and the referenced content merged into the schema.