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
Copy file name to clipboardExpand all lines: README.md
+22-21Lines changed: 22 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe
43
43
}
44
44
```
45
45
46
+
46
47
The Solution:
47
48
--------------------------
48
49
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.
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.
209
+
-**schema** (_required_) - `string` or `object`<br>
210
+
A JSON Schema object, or the file path or URL of a JSON Schema file.
210
211
<br><br>
211
-
If you already have the JSON Schema as a JavaScript object, then you can pass that instead of a file path.
212
+
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.
The file path or URL of your JSON Schema file. See the [`parse`](#parsepath-options-callback) method for more info.
238
+
A JSON Schema object, or the file path or URL of a JSON Schema file. See the [`parse`](#parseschema-options-callback) method for more info.
238
239
239
240
-**options** (_optional_) - `object`<br>
240
241
See [options](#options) below.
@@ -245,7 +246,7 @@ A callback that will receive a [`$Refs`](#refs-object) object.
245
246
-**Return Value:**`Promise`<br>
246
247
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
247
248
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.
249
+
> This method is used internally by other methods, such as [`bundle`](#bundleschema-options-callback) and [`dereference`](#dereferenceschema-options-callback). You probably won't need to call this method yourself.
249
250
250
251
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.
|`allow.yaml` |bool |true |Determines whether YAML files are supported<br> (note: all JSON files are also valid YAML files)
290
291
|`allow.empty` |bool |true |Determines whether it's ok for a `$ref` pointer to point to an empty file
291
292
|`allow.unknown` |bool |true |Determines whether it's ok for a `$ref` pointer to point to an unknown/unsupported file type (such as HTML, text, image, etc.). The default is to resolve unknown files as a [`Buffer`](https://nodejs.org/api/buffer.html#buffer_class_buffer)
292
-
|`$refs.internal` |bool |true |Determines whether internal `$ref` pointers (such as `#/definitions/widget`) will be dereferenced when calling [`dereference()`](#dereferencepath-options-callback). Either way, you'll still be able to get the value using [`$Refs.get()`](#refsgetref-options)
293
+
|`$refs.internal` |bool |true |Determines whether internal `$ref` pointers (such as `#/definitions/widget`) will be dereferenced when calling [`dereference()`](#dereferenceschema-options-callback). Either way, you'll still be able to get the value using [`$Refs.get()`](#refsgetref-options)
293
294
|`$refs.external` |bool |true |Determines whether external `$ref` pointers get resolved/dereferenced. If `false`, then no files/URLs will be retrieved. Use this if you only want to allow single-file schemas.
294
295
|`$refs.circular` |bool |true |Determines whether [circular `$ref` pointers](#circular-refs) are allowed. If `false`, then a `ReferenceError` will be thrown if the schema contains a circular reference.
295
296
|`cache.fs` |number |60 |<aname="caching"></a>The length of time (in seconds) to cache local files. The default is one minute. Setting to zero will cache forever.
If you create an instance of the `$RefParser` class (rather than just calling the static methods), then the `schema` property gives you easy access to the JSON schema. This is the same value that is passed to the callback function (or Promise) when calling the [`parse`](#parsepath-options-callback), [`bundle`](#bundlepath-options-callback), or [`dereference`](#dereferencepath-options-callback) methods.
302
+
If you create an instance of the `$RefParser` class (rather than just calling the static methods), then the `schema` property gives you easy access to the JSON schema. This is the same value that is passed to the callback function (or Promise) when calling the [`parse`](#parseschema-options-callback), [`bundle`](#bundleschema-options-callback), or [`dereference`](#dereferenceschema-options-callback) methods.
When you call the [`resolve`](#resolvepath-options-callback) method, the value that gets passed to the callback function (or Promise) is a `$Refs` object. This same object is accessible via the `parser.$refs` property of `$RefParser` instances.
319
+
When you call the [`resolve`](#resolveschema-options-callback) method, the value that gets passed to the callback function (or Promise) is a `$Refs` object. This same object is accessible via the `parser.$refs` property of `$RefParser` instances.
319
320
320
321
This object is a map of JSON References and their resolved values. It also has several convenient helper methods that make it easy for you to navigate and manipulate the JSON References.
The JSON Reference path, optionally with a JSON Pointer in the hash
410
411
411
-
Immediately expires the given JSON reference, so the next time you call a method such as [`parse`](#parsepath-options-callback) or [`dereference`](#dereferencepath-options-callback), the file will be refreshed rather than reusing the cached value.
412
+
Immediately expires the given JSON reference, so the next time you call a method such as [`parse`](#parseschema-options-callback) or [`dereference`](#dereferenceschema-options-callback), the file will be refreshed rather than reusing the cached value.
412
413
413
414
```javascript
414
415
$RefParser.resolve("my-schema.json")
@@ -577,7 +578,7 @@ var parser = new $RefParser();
577
578
parser.resolve("my-schema.json");
578
579
```
579
580
580
-
The difference is that in the second example you now have a reference to `parser`, which means you can access the results ([`parser.schema`](#schema-object) and [`parser.$refs`](#refs-object)) anytime you want, rather than just in the callback function. Also, having a `$RefParser` instance allows you to benefit from **[caching](#caching)**, so the next time you call [`parser.resolve()`](#resolvepath-options-callback), it won't need to re-download those files again (as long as the cache hasn't expired).
581
+
The difference is that in the second example you now have a reference to `parser`, which means you can access the results ([`parser.schema`](#schema-object) and [`parser.$refs`](#refs-object)) anytime you want, rather than just in the callback function. Also, having a `$RefParser` instance allows you to benefit from **[caching](#caching)**, so the next time you call [`parser.resolve()`](#resolveschema-options-callback), it won't need to re-download those files again (as long as the cache hasn't expired).
You can disable circular references by setting the [`$refs.circular`](#options) option to `false`. Then, if a circular reference is found, a `ReferenceError` will be thrown.
592
593
593
-
Another option is to use the [`bundle`](#bundlepath-options-callback) method rather than the [`dereference`](#dereferencepath-options-callback) method. Bundling does _not_ result in circular references, because it simply converts _external_`$ref` pointers to _internal_ ones.
594
+
Another option is to use the [`bundle`](#bundleschema-options-callback) method rather than the [`dereference`](#dereferenceschema-options-callback) method. Bundling does _not_ result in circular references, because it simply converts _external_`$ref` pointers to _internal_ ones.
0 commit comments