flat-ajv-schema
v1.0.1
Published
Takes a schema validation instance and returns a schema object with flattened $refs
Downloads
1,466
Readme
flat-ajv-schema
The purpose of flat-ajv-schema is to take a compiled ajv json schema instance validator function and extract the schema including any and all references used in the schema.
Usage
var Ajv = require('ajv');
var flattener = require('flat-ajv-schema');
var defSchema = { $id: 'defs', one: { type: 'string' } };
var valSchema = { $id: 'valSchema', $ref: 'defs#/one' };
var validator = new Ajv({ schemas: [ defsSchema, validatorSchema ]}).getSchema('valSchema');
var flatSchema = flattener(validator);
// flatSchema is now:
/*
{
defs: {
'defs#/one': { type: 'string' },
},
valSchema: {
$id: 'valSchema',
$ref: 'defs#/one',
},
}
*/