json-resolver

0.8.3 • Public • Published

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

  1. Install with npm or yarn:
# via npm 
npm install json-resolver
# via yarn 
yarn add json-resolver
  1. 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

Readme

Keywords

none

Package Sidebar

Install

npm i json-resolver

Weekly Downloads

0

Version

0.8.3

License

MIT

Unpacked Size

26.2 kB

Total Files

24

Last publish

Collaborators

  • zachchai