Resolves references in json-schema to an object containing schemas keyed by reference.
import Resolver from 'extrefs';
Resolver(schema).resolve((error, schemas) => {
//plugin into validator
});
Example:
//schema.json
{
"type": "object",
"properties": {
"example": {
"$ref": "example.json"
}
}
}
//example.json
{
"type": "string"
}
Will result in an object containing:
{
"example.json": {
"type": "string"
}
}
Which can then be used in conjunction with a schema validator.
For remote references (i.e. urls), resulting schemas that contain local external references (i.e just a filename) will be replaced with a fully qualified URL to the schema for proper resolution.
//schema.json
{
"type": "object",
"properties": {
"example": {
"$ref": "http://example.org/example.json"
}
}
}
//http://example.org/example.json
{
"type": "object",
"properties": {
"more": {
"$ref": "more.json"
}
}
}
//http://example.org/more.json
{
"type": "string"
}
Will result in:
{
"http://example.org/example.json": {
"type": "object",
"properties": {
"more": {
"$ref": "http://example.org/more.json"
}
}
},
"http://example.org/more.json": {
"type": "string"
}
}
basedir
- base directory to search local file references for.