Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moeriki/json-schema-flatten
Flatten a JSON schemas with internal references.
https://github.com/moeriki/json-schema-flatten
Last synced: 22 days ago
JSON representation
Flatten a JSON schemas with internal references.
- Host: GitHub
- URL: https://github.com/moeriki/json-schema-flatten
- Owner: moeriki
- Created: 2015-12-09T08:57:34.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-02T07:51:07.000Z (almost 6 years ago)
- Last Synced: 2024-12-26T01:34:44.538Z (30 days ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON Schema Flatten
Flatten a JSON schema separating all nested objects into referenced definitions.
## Usage
```javascript
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.
```JSON
{
"type": "object",
"properties": {
"name": {
"$ref": "#/definitions/name"
}
},
"definitions": {
"name": {
"type": "object",
"properties": {
"first": { "type": "string" },
"last": { "type": "string" }
}
}
}
}
```## Why
[Swagger UI](https://github.com/swagger-api/swagger-ui) doesn't generate documentation well when you have nested object structures. Running it through this fixes it for me.
## API
```javascript
var flatten = require('json-schema-flatten');
```**flatten(** schema *:object* **)** *:object*
* schema — a JSON schema. Won't be modified.