0.14.0 • Published 3 years ago

json-schema-deref-sync v0.14.0

Weekly downloads
135,028
License
MIT
Repository
github
Last release
3 years ago

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.

ParamTypeDescription
schemaObjectThe JSON schema
optionsObjectoptions
options.baseFolderStringthe base folder to get relative path files from. Default is process.cwd()
options.failOnMissingBooleanBy 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.mergeAdditionalPropertiesBooleanBy 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.removeIdsBooleanBy 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.loadersObjectA hash mapping reference types (e.g., 'file') to loader functions.
0.14.0

3 years ago

0.13.0

4 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.1-pre.0

6 years ago

0.4.0

6 years ago

0.3.4

6 years ago

0.3.3

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago