JSONSchex.ScopeScanner (jsonschex v0.7.0)

Copy Markdown View Source

Scans a raw schema tree to discover all $id, $anchor, and $dynamicAnchor definitions, resolving them against parent base URIs to build a registry of absolute URI → raw schema mappings.

The resulting registry is used by JSONSchex.Compiler to populate the defs field in the compiled Schema, enabling reference resolution during validation.

Examples

iex> schema = %{
...>   "$id" => "https://example.com/schema",
...>   "$defs" => %{
...>     "user" => %{"$id" => "user", "type" => "object"}
...>   }
...> }
iex> registry = JSONSchex.ScopeScanner.scan(schema)
iex> Map.has_key?(registry, "https://example.com/schema")
true
iex> Map.has_key?(registry, "https://example.com/user")
true

Summary

Functions

Scans a raw schema and returns a tuple {registry, refs} where

Scans every map/list node in a containing document for JSON Schema resource identifiers and references.

Functions

scan(schema)

Scans a raw schema and returns a tuple {registry, refs} where:

  • registry is a map of {absolute_uri => raw_schema}.
  • refs is a MapSet of explicitly defined references.

scan_all(document, base_uri \\ nil)

Scans every map/list node in a containing document for JSON Schema resource identifiers and references.

This is intentionally broader than scan/1: fragment compilation may receive an OpenAPI document whose schema objects live under arbitrary paths such as components.schemas or paths.*.requestBody.content.*.schema.