json-schema-deref-sync

0.14.0 • Public • Published

json-schema-deref-sync

npm version build status JavaScript Style Guide License

Dereference JSON pointers in a JSON schemas with their true resolved values. Basically a lighter, synchronous version of json-schema-deref but omits web references.

Installation

npm install json-schema-deref-sync

Overview

Let's say you have the following JSON Schema:

{
  "description": "Just some JSON schema.",
  "title": "Basic Widget",
  "type": "object",
  "definitions": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    }
  },
  "properties": {
    "id": {
      "$ref": "#/definitions/id"
    },
    "bar": {
      "$ref": "bar.json"
    }
  }
}

Sometimes you just want that schema to be fully expanded, with $ref's being their (true) resolved values:

{
  "description": "Just some JSON schema.",
  "title": "Basic Widget",
  "type": "object",
  "definitions": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    }
  },
  "properties": {
    "id": {
      "description": "unique identifier",
      "type": "string",
      "minLength": 1,
      "readOnly": true
    },
    "bar": {
      "description": "bar property",
      "type": "boolean"
    }
  }
}

This utility lets you do that:

var deref = require('json-schema-deref-sync');
var myschema = require('schema.json');
 
var fullSchema = deref(myschema);

API Reference

deref(schema, options) ⇒ Object | Error

Derefs $ref's in JSON Schema to actual resolved values. Supports local, and file refs.

Kind: global function
Returns: Object | Error - the deref schema oran instance of Error if error.

Param Type Description
schema Object The JSON schema
options Object options
options.baseFolder String the base folder to get relative path files from. Default is process.cwd()
options.failOnMissing Boolean By default missing / unresolved refs will be left as is with their ref value intact. If set to true we will error out on first missing ref that we cannot resolve. Default: false.
options.mergeAdditionalProperties Boolean By default properties in a object with $ref will be removed in the output. If set to true they will be added/overwrite the output. This will use lodash's merge function. Default: false.
options.removeIds Boolean By default $id fields will get copied when dereferencing. If set to true they will be removed. Merged properties will not get removed. Default: false.
options.loaders Object A hash mapping reference types (e.g., 'file') to loader functions.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.14.072,724latest
0.4.1-pre.01beta

Version History

VersionDownloads (Last 7 Days)Published
0.14.072,724
0.13.0585,739
0.10.13,412
0.10.07
0.9.01,406
0.8.0137
0.7.0466
0.6.09,332
0.5.031
0.4.1-pre.01
0.4.0788
0.3.4746
0.3.31,892
0.3.21
0.3.11
0.3.01
0.2.91
0.2.81
0.2.71
0.2.61
0.2.51
0.2.41
0.2.31
0.2.21
0.2.11
0.2.01
0.1.23
0.1.11
0.1.01

Package Sidebar

Install

npm i json-schema-deref-sync

Weekly Downloads

676,699

Version

0.14.0

License

MIT

Unpacked Size

23.2 kB

Total Files

10

Last publish

Collaborators

  • jcurtis
  • bojand
  • chrisbeatty00
  • cvent_npm