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
-[Class methods vs. Instance methods](#class-methods-vs-instance-methods)
32
-
-[Callbacks vs. Promises](#callbacks-vs-promises)
33
-
-[Circular references](#circular-refs)
36
+
#### [`Options`](options.md)
34
37
35
38
36
39
### Class methods vs. Instance methods
@@ -54,8 +57,7 @@ The difference is that in the second example you now have a reference to `parser
54
57
Many people prefer [ES6 Promise syntax](http://javascriptplayground.com/blog/2015/02/promises/) instead of callbacks. JSON Schema $Ref Parser allows you to use whichever one you prefer. Every method accepts an optional callback _and_ returns a Promise. So pick your poison.
55
58
56
59
57
-
Circular $Refs
58
-
--------------------------
60
+
### Circular $Refs
59
61
JSON Schema files can contain [circular $ref pointers](https://gist.github.com/BigstickCarpet/d18278935fc73e3a0ee1), and JSON Schema $Ref Parser fully supports them. Circular references can be resolved and dereferenced just like any other reference. However, if you intend to serialize the dereferenced schema as JSON, then you should be aware that [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) does not support circular references by default, so you will need to [use a custom replacer function](https://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json).
60
62
61
63
You can disable circular references by setting the [`$refs.circular`](options.md) option to `false`. Then, if a circular reference is found, a `ReferenceError` will be thrown.
@@ -65,7 +65,7 @@ See [Callbacks vs. Promises](README.md#callbacks-vs-promises)
65
65
66
66
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.
67
67
68
-
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](README.md#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.
68
+
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](README.md#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`](#bundleschema-options-callback) method instead, which does not create circular references.
69
69
70
70
```javascript
71
71
$RefParser.dereference("my-schema.yaml")
@@ -94,7 +94,7 @@ A callback that will receive the bundled schema object
94
94
-**Return Value:**`Promise`<br>
95
95
See [Callbacks vs. Promises](README.md#callbacks-vs-promises)
96
96
97
-
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).
97
+
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](#dereferenceschema-options-callback).
98
98
99
99
This also eliminates the risk of [circular references](README.md#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).
100
100
@@ -122,7 +122,7 @@ A callback that will receive the parsed schema object, or an error
122
122
-**Return Value:**`Promise`<br>
123
123
See [Callbacks vs. Promises](README.md#callbacks-vs-promises)
124
124
125
-
> 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.
125
+
> 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.
126
126
127
127
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.
0 commit comments