0.10.2 • Published 8 years ago

json-schema-flatten v0.10.2

Weekly downloads
6
License
ISC
Repository
github
Last release
8 years ago

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.
0.10.2

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.9.3

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago