JSON Schema Flatten
Flatten a JSON schema separating all nested objects into referenced definitions.
Usage
var flatten = ; var schema = type: 'object' properties: name: type: 'object' //= nested object properties: first: type: 'string' last: type: 'string' ; console;
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 = ;
flatten( schema :object ) :object
- schema — a JSON schema. Won't be modified.