Do you have $ref's ?
A simple way for solving $ref
values:
var deref = require('deref');
Schema dereferencing
$ = deref();
var a = {
id: 'a',
type: 'object',
properties: {
b: {
$ref: 'b'
}
}
};
var b = {
id: 'b',
type: 'string'
};
var c = {
id: 'c',
type: 'array',
items: {
$ref: 'a'
}
};
console.log($(c, [b, a]).id);
console.log($(c, [b, a], true).items.properties.b.type);
Schema normalization
var schema = {
id: 'http://x.y.z/rootschema.json#',
schema1: {
id: '#foo'
},
schema2: {
id: 'otherschema.json',
nested: {
id: '#bar'
},
alsonested: {
id: 't/inner.json#a'
}
},
schema3: {
id: 'some://where.else/completely#'
}
};
console.log(deref.util.normalizeSchema(schema).schema2.nested.id);
Basic usage
The resulting function of calling deref()
can accept three arguments:
-
fakeroot (string)
Used on missing $schema
values for resolve into fully qualified URIs.
console.log($('http://example.com', { id: '#foo' }).id);
If missing will use http://json-schema.org/schema
.
-
schema (object)
The JSON-Schema object for dereferencing.
-
refs (array|object)
Any additional schemas used while dereferencing.
-
ex (boolean)
Whether do full dereferencing or not, false
by default.
Examples
$('http://example.com', schema, true);
$(schema, refs, true);
$(schema, true);
Utilities
Aside the basics of $
, this function will include:
Note that calling $(schema)
will not read/download any local/remote files.
Since 0.2.1
the $schema
and id
are no longer required for schema normalization.