# json-schema-deref-sync

> Simple Node.js JSON Schema dereferencer

Latest version **0.14.0** (published 2020-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-deref-sync
pnpm add json-schema-deref-sync
yarn add json-schema-deref-sync
bun add json-schema-deref-sync
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.14.0 |
| Published | 2020-10-29 |
| First published | 2015-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 8 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Bojan D. |
| Maintainers | jcurtis, bojand, chrisbeatty00, cvent_npm |
| Keywords | json, schema, deref |

## Links

- npm: https://www.npmjs.com/package/json-schema-deref-sync
- Repository: https://github.com/cvent/json-schema-deref-sync
- Issues: http://github.com/cvent/json-schema-deref-sync/issues
- npm.io page: https://npm.io/package/json-schema-deref-sync

## Dependencies (8)

- [md5](https://npm.io/package/md5.md) ~2.2.0
- [clone](https://npm.io/package/clone.md) ^2.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.13
- [dag-map](https://npm.io/package/dag-map.md) ~1.0.0
- [traverse](https://npm.io/package/traverse.md) ~0.6.6
- [valid-url](https://npm.io/package/valid-url.md) ~1.0.9
- [memory-cache](https://npm.io/package/memory-cache.md) ~0.2.0
- [is-valid-path](https://npm.io/package/is-valid-path.md) ^0.1.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.14.0 (latest) — 2020-10-29
- 0.4.1-pre.0 (beta) — 2018-02-20
- 0.13.0 — 2019-11-25
- 0.10.1 — 2019-07-10
- 0.10.0 — 2019-03-06
- 0.9.0 — 2019-02-22
- 0.8.0 — 2019-01-29
- 0.7.0 — 2018-10-20
- 0.6.0 — 2018-10-20
- 0.5.0 — 2018-07-16
- 0.4.0 — 2017-11-20
- 0.3.4 — 2017-11-17
- 0.3.3 — 2016-11-02
- 0.3.2 — 2016-08-19
- 0.3.1 — 2016-04-25
- … 14 more at https://npm.io/package/json-schema-deref-sync/versions

## README

# json-schema-deref-sync

[![npm version](https://img.shields.io/npm/v/json-schema-deref-sync.svg?style=flat-square)](https://www.npmjs.com/package/json-schema-deref-sync)
[![build status](https://img.shields.io/travis/bojand/json-schema-deref-sync/master.svg?style=flat-square)](https://travis-ci.org/bojand/json-schema-deref-sync)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)
[![License](https://img.shields.io/github/license/bojand/json-schema-deref-sync.svg?style=flat-square)](https://raw.githubusercontent.com/bojand/json-schema-deref-sync/master/LICENSE)

Dereference JSON pointers in a JSON schemas with their true resolved values.
Basically a lighter, synchronous version of [json-schema-deref](https://github.com/bojand/json-schema-deref) but omits web references.

## Installation

`npm install json-schema-deref-sync`

## Overview

Let's say you have the following JSON Schema:

```json
{
  "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:

```json
{
  "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:


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

var fullSchema = deref(myschema);
```

## API Reference

<a name="deref"></a>

## deref(schema, options) ⇒ <code>Object</code> \| <code>Error</code>
Derefs <code>$ref</code>'s in JSON Schema to actual resolved values. Supports local, and file refs.

**Kind**: global function  
**Returns**: <code>Object</code> \| <code>Error</code> - the deref schema oran instance of <code>Error</code> if error.  

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

---
_Source: https://npm.io/package/json-schema-deref-sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
