json-resolver
v0.8.3
Published
Parse and resolve complex JSON schemas
Downloads
10
Readme
JSON Resolver
Parse and resolve complex JSON Documents. Designed for Open API Specification.
Features
- Resolves external references to files and their sub-schemas
- Supports nested references and bidirectional references between files
- Detects circular references
- Reads both JSON and YAML files
Getting Started
Installation
- Install with npm or yarn:
# via npm
npm install json-resolver
# via yarn
yarn add json-resolver
- Then import in your code
// via ECMAScript
import JsonResolver from 'json-resolver'
// via commonJS
var JsonResolver = require('swagger-parser');
Usage
JsonResolver.resolveRef(filePath, function(err, result) {
if (err) {
console.error(err.message)
} else {
console.log(JSON.stringify(result))
}
})
Example
# Original
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
# Dereferenced
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Unsupported Features
- References with scheme, authority, or query components according to https://tools.ietf.org/html/rfc3986#section-3