# `JSONSchex.Compiler`
[🔗](https://github.com/xinz/jsonschex/blob/main/lib/jsonschex/compiler.ex#L1)

Transforms raw JSON Schema maps into executable `Schema` structs.

Compilation has two phases:

1. **Node compilation** — Recursively converts keywords into `Rule` structs
   (serializable rule descriptors), resolves vocabularies, and compiles `$defs`.
2. **Scope scanning** — Discovers all `$id` and anchor definitions across the
   schema tree and registers them by absolute URI for reference resolution.

Standard rules execute first; **finalizer** rules (`unevaluatedProperties`,
`unevaluatedItems`) run last so they can see which keys were already evaluated.

## Examples

    iex> {:ok, schema} = JSONSchex.Compiler.compile(%{"type" => "string"})
    iex> length(schema.rules)
    1

# `bundle_fragment`

```elixir
@spec bundle_fragment(
  map() | boolean(),
  keyword()
) :: {:ok, map() | boolean()} | {:error, JSONSchex.Types.Error.t()}
```

Bundles a JSON Schema fragment into a standalone raw schema document.

# `compile`

Compiles a raw JSON Schema into an executable `Schema` struct.

See `JSONSchex.compile/2` for options and usage.

# `compile_fragment`

```elixir
@spec compile_fragment(
  map() | boolean(),
  keyword()
) :: {:ok, JSONSchex.Types.Schema.t()} | {:error, JSONSchex.Types.Error.t()}
```

Compiles a JSON Schema fragment from a containing document while preserving
that document as the reference-resolution context.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
