You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser)
11
11
12
+
Installation
13
+
--------------------------
14
+
Install using [npm](https://docs.npmjs.com/about-npm/):
15
+
16
+
```bash
17
+
npm install @apidevtools/json-schema-ref-parser
18
+
yarn add @apidevtools/json-schema-ref-parser
19
+
bun add @apidevtools/json-schema-ref-parser
20
+
```
21
+
12
22
The Problem:
13
23
--------------------------
14
-
You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe you know all the referenced files ahead of time. Maybe you don't. Maybe some are local files, and others are remote URLs. Maybe they are a mix of JSON and YAML format. Maybe some of the files contain cross-references to each other.
24
+
You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe you know all the referenced files ahead
25
+
of time. Maybe you don't. Maybe some are local files, and others are remote URLs. Maybe they are a mix of JSON and YAML
26
+
format. Maybe some of the files contain cross-references to each other.
15
27
16
-
```javascript
28
+
```json
17
29
{
18
30
"definitions": {
19
31
"person": {
@@ -36,144 +48,117 @@ You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe
36
48
}
37
49
```
38
50
39
-
40
51
The Solution:
41
52
--------------------------
42
-
JSON Schema $Ref Parser is a full [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) and [JSON Pointer](https://tools.ietf.org/html/rfc6901) implementation that crawls even the most complex [JSON Schemas](http://json-schema.org/latest/json-schema-core.html) and gives you simple, straightforward JavaScript objects.
53
+
JSON Schema $Ref Parser is a full [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)
54
+
and [JSON Pointer](https://tools.ietf.org/html/rfc6901) implementation that crawls even the most
55
+
complex [JSON Schemas](http://json-schema.org/latest/json-schema-core.html) and gives you simple, straightforward
56
+
JavaScript objects.
43
57
44
58
- Use **JSON** or **YAML** schemas — or even a mix of both!
45
-
- Supports `$ref` pointers to external files and URLs, as well as [custom sources](https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html) such as databases
46
-
- Can [bundle](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundlepath-options-callback) multiple files into a single schema that only has _internal_`$ref` pointers
47
-
- Can [dereference](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferencepath-options-callback) your schema, producing a plain-old JavaScript object that's easy to work with
48
-
- Supports [circular references](https://apitools.dev/json-schema-ref-parser/docs/#circular-refs), nested references, back-references, and cross-references between files
49
-
- Maintains object reference equality —`$ref` pointers to the same value always resolve to the same object instance
50
-
- Tested in Node v10, v12, & v14, and all major web browsers on Windows, Mac, and Linux
51
-
59
+
- Supports `$ref` pointers to external files and URLs, as well
60
+
as [custom sources](https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html) such as databases
61
+
- Can [bundle](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundlepath-options-callback) multiple
62
+
files into a single schema that only has _internal_`$ref` pointers
63
+
- Can [dereference](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferencepath-options-callback)
64
+
your schema, producing a plain-old JavaScript object that's easy to work with
When using a transpiler such as [Babel](https://babeljs.io/) or [TypeScript](https://www.typescriptlang.org/), or a bundler such as [Webpack](https://webpack.js.org/) or [Rollup](https://rollupjs.org/), you can use **ECMAScript modules** syntax instead:
If you are using Node.js < 18, you'll need a polyfill for `fetch`, like [node-fetch](https://github.com/node-fetch/node-fetch):
110
95
```javascript
111
96
importfetchfrom"node-fetch";
112
97
113
98
globalThis.fetch= fetch;
114
99
```
115
100
116
-
117
-
118
101
Browser support
119
102
--------------------------
120
-
JSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may require [Babel](https://babeljs.io/) and/or [polyfills](https://babeljs.io/docs/en/next/babel-polyfill).
121
-
122
-
To use JSON Schema $Ref Parser in a browser, you'll need to use a bundling tool such as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/), or [Browserify](http://browserify.org/). Some bundlers may require a bit of configuration, such as setting `browser: true` in [rollup-plugin-resolve](https://github.com/rollup/rollup-plugin-node-resolve).
103
+
JSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may
To use JSON Schema $Ref Parser in a browser, you'll need to use a bundling tool such
107
+
as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/),
108
+
or [Browserify](http://browserify.org/). Some bundlers may require a bit of configuration, such as
109
+
setting `browser: true` in [rollup-plugin-resolve](https://github.com/rollup/rollup-plugin-node-resolve).
124
110
125
111
#### Webpack 5
126
-
Webpack 5 has dropped the default export of node core modules in favour of polyfills, you'll need to set them up yourself ( after npm-installing them )
112
+
113
+
Webpack 5 has dropped the default export of node core modules in favour of polyfills, you'll need to set them up
114
+
yourself ( after npm-installing them )
127
115
Edit your `webpack.config.js` :
116
+
128
117
```js
129
-
config.resolve.fallback= {
130
-
"path":require.resolve("path-browserify"),
131
-
'util':require.resolve('util/'),
132
-
'fs':require.resolve('browserify-fs'),
133
-
"buffer":require.resolve("buffer/"),
134
-
"http":require.resolve("stream-http"),
135
-
"https":require.resolve("https-browserify"),
136
-
"url":require.resolve("url"),
137
-
}
118
+
config.resolve.fallback= {
119
+
"path":require.resolve("path-browserify"),
120
+
'fs':require.resolve('browserify-fs')
121
+
}
138
122
139
-
config.plugins.push(
140
-
newwebpack.ProvidePlugin({
141
-
Buffer: ['buffer', 'Buffer']
142
-
})
143
-
)
123
+
config.plugins.push(
124
+
newwebpack.ProvidePlugin({
125
+
Buffer: ['buffer', 'Buffer']
126
+
})
127
+
)
144
128
145
129
```
146
130
147
-
148
131
API Documentation
149
132
--------------------------
150
133
Full API documentation is available [right here](https://apitools.dev/json-schema-ref-parser/docs/)
151
134
152
135
153
-
154
136
Contributing
155
137
--------------------------
156
-
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/json-schema-ref-parser/pulls).
138
+
I welcome any contributions, enhancements, and
139
+
bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub
140
+
and [submit a pull request](https://github.com/APIDevTools/json-schema-ref-parser/pulls).
157
141
158
142
#### Building/Testing
143
+
159
144
To build/test the project locally on your computer:
JSON Schema $Ref Parser is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.
175
158
176
-
This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
159
+
This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a
160
+
tree**](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser) to thank us for our work. By contributing to
161
+
the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
0 commit comments