The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

JSON References


Upgrade Guide

Scope Resolution

When the dereferencer encounters a reference, the reference is resolved like a URI. For example:

Base Reference Resolved user.json ../user.json

If you would like to customize how the Base URI scope is resolved, you can implement the ScopeResolverInterface. For every URI encountered, the scope resolver is invoked with the current schema, a pointer to the current location in the schema, and the current uri scope (if any).

JSON Schema Scope Resolution

In JSON Schema the id property is used to alter the resolution scope of references.

If the top of your schema had { "id": "" } and you encountered the reference {"$ref": "user.json"}, JSON Schema dictates that the schema should be loaded from, even if the schema was loaded from or even the local filesystem.

To enable JSON Schema scope resolution, you can pass the JsonSchemaScopeResolver into the dereferencer. The JSON Schema scope resolver takes the keyword it should use as the only parameter.


use League\JsonReference\Dereferencer;
use League\JsonReference\ScopeResolver\JsonSchemaScopeResolver;

$dereferencer = new Dereferencer(new JsonSchemaScopeResolver('id'));

There are some helper functions to make this easier.

use League\JsonReference\Dereferencer;

$dereferencer = Dereferencer::draft4(); // schemas using `id`

$dereferencer = Dereferencer::draft6(); // schemas using `$id`