json-schema-flatten
v0.10.2
Published
Flatten a JSON schemas with internal references.
Downloads
78
Readme
JSON Schema Flatten
Flatten a JSON schema separating all nested objects into referenced definitions.
Usage
var flatten = require('json-schema-flatten/es5');
var schema = {
type: 'object',
properties: {
name: {
type: 'object', //= nested object
properties: {
first: { type: 'string' },
last: { type: 'string' },
}
}
}
};
console.log(flatten(schema));
Will output.
{
"type": "object",
"properties": {
"name": {
"$ref": "#/definitions/name"
}
},
"definitions": {
"name": {
"type": "object",
"properties": {
"first": { "type": "string" },
"last": { "type": "string" }
}
}
}
}
Why
Swagger UI doesn't generate documentation well when you have nested object structures. Running it through this fixes it for me.
API
var flatten = require('json-schema-flatten');
flatten( schema :object ) :object
- schema — a JSON schema. Won't be modified.