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
The file path or URL of your JSON Schema file. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
154
-
<br><br>
155
-
If you already have the JSON Schema as a JavaScript object, then you can pass that instead of a file path.
151
+
-**path** (_required_) - `string` or `object`<br>
152
+
The file path or URL of your JSON Schema file. See the [`parse`](#parsepath-options-callback) method for more info.
A callback that will receive the parsed schema object, or an error.
158
+
A callback that will receive the dereferenced schema object.
162
159
163
160
-**Return Value:**`Promise`<br>
164
161
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
165
162
166
-
Parses the given JSON Schema file (in JSON or YAML format), and returns it as a JavaScript object. This method **does not** resolve `$ref` pointers or dereference anything. It simply parses _one_ file and returns it.
163
+
Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain _any_`$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
164
+
165
+
The `dereference` method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of [circular references](#circular-refs), so be careful if you intend to serialize the schema using [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Consider using the [`bundle`](#bundlepath-options-callback) method instead, which does not create circular references.
A callback that will receive the bundled schema object.
186
190
187
191
-**Return Value:**`Promise`<br>
188
192
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
189
193
190
-
Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well (unless `options.$refs.external` is false). This method **does not** dereference anything. It simply gives you a [`$Refs`](#refs-object) object, which is a map of all the resolved references and their values.
191
-
192
-
```javascript
193
-
$RefParser.resolve("my-schema.yaml")
194
-
.then(function($refs) {
195
-
// $refs.paths() returns the paths of all the files in your schema
196
-
var filePaths =$refs.paths();
194
+
Bundles all referenced files/URLs into a single schema that only has _internal_`$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain _internal_ JSON references rather than being [fully-dereferenced](#dereferencepath-options-callback).
197
195
198
-
// $refs.get() lets you query parts of your schema
199
-
var name =$refs.get("schemas/people/Bruce-Wayne.json#/properties/name");
196
+
This also eliminates the risk of [circular references](#circular-refs), so the schema can be safely serialized using [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
200
197
201
-
// $refs.set() lets you change parts of your schema
The file path or URL of your JSON Schema file. See the [`parse`](#parsepath-options-callback) method for more info.
208
+
-**path** (_required_) - `string`<br>
209
+
The file path or URL of your JSON Schema file. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
210
+
<br><br>
211
+
If you already have the JSON Schema as a JavaScript object, then you can pass that instead of a file path.
A callback that will receive the bundled schema object.
217
+
A callback that will receive the parsed schema object, or an error.
217
218
218
219
-**Return Value:**`Promise`<br>
219
220
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
220
221
221
-
Bundles all referenced files/URLs into a single schema that only has _internal_`$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain _internal_ JSON references rather than being [fully-dereferenced](#dereferencepath-options-callback).
222
+
> This method is used internally by other methods, such as [`bundle`](#bundlepath-options-callback) and [`dereference`](#dereferencepath-options-callback). You probably won't need to call this method yourself.
222
223
223
-
This also eliminates the risk of [circular references](#circular-refs), so the schema can be safely serialized using [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
224
+
Parses the given JSON Schema file (in JSON or YAML format), and returns it as a JavaScript object. This method **does not** resolve `$ref` pointers or dereference anything. It simply parses _one_ file and returns it.
A callback that will receive a [`$Refs`](#refs-object) object.
243
244
244
245
-**Return Value:**`Promise`<br>
245
246
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
246
247
247
-
Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain _any_`$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
248
+
> This method is used internally by other methods, such as [`bundle`](#bundlepath-options-callback)and [`dereference`](#dereferencepath-options-callback). You probably won't need to call this method yourself.
248
249
249
-
The `dereference` method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of [circular references](#circular-refs), so be careful if you intend to serialize the schema using [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Consider using the [`bundle`](#bundlepath-options-callback) method instead, which does not create circular references.
250
+
Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well (unless `options.$refs.external` is false). This method **does not** dereference anything. It simply gives you a [`$Refs`](#refs-object) object, which is a map of all the resolved references and their values.
250
251
251
252
```javascript
252
-
$RefParser.dereference("my-schema.yaml")
253
-
.then(function(schema) {
254
-
// The `schema` object is a normal JavaScript object,
255
-
// so you can easily access any part of the schema using simple dot notation
0 commit comments