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: docs/README.md
+1-3
Original file line number
Diff line number
Diff line change
@@ -23,8 +23,6 @@ Classes & Methods
23
23
-[`circular`](refs.md#circular)
24
24
-[`paths()`](refs.md#pathstypes)
25
25
-[`values()`](refs.md#valuestypes)
26
-
-[`isExpired()`](refs.md#isexpiredref)
27
-
-[`expire()`](refs.md#expireref)
28
26
-[`exists()`](refs.md#existsref)
29
27
-[`get()`](refs.md#getref-options)
30
28
-[`set()`](refs.md#setref-value-options)
@@ -50,7 +48,7 @@ var parser = new $RefParser();
50
48
parser.bundle("my-schema.json");
51
49
```
52
50
53
-
The difference is that in the second example you now have a reference to `parser`, which means you can access the results ([`parser.schema`](ref-parser.md#schema) and [`parser.$refs`](ref-parser.md#refs)) anytime you want, rather than just in the callback function. Also, having a `$RefParser` instance allows you to benefit from **[caching](options.md#cache)**, so the next time you call [`parser.resolve()`](ref-parser.md#resolveschema-options-callback), it won't need to re-download those files again (as long as the cache hasn't expired).
51
+
The difference is that in the second example you now have a reference to `parser`, which means you can access the results ([`parser.schema`](ref-parser.md#schema) and [`parser.$refs`](ref-parser.md#refs)) anytime you want, rather than just in the callback function.
Parsers run in a specific order, relative to other parsers. For example, a parser with `order: 5` will run _before_ a parser with `order: 10`. If a parser is unable to successfully parse a file, then the next parser is tried, until one succeeds or they all fail.
51
50
52
-
You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add your own custom parser that you want to run _first_.
51
+
You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add your own custom parser that you want to run _first_.
53
52
54
53
```javascript
55
54
// Run the plain-text parser first
@@ -64,11 +63,11 @@ Multiple parsers can contain the same file extensions. For example, both the JSO
64
63
You can set your own file extensions for any parser. Each extension can be a string or a regular expression to test against the _full file path_. Here's an example:
65
64
66
65
```javascript
67
-
$RefParser.dereference("my-schema.yaml", {
68
-
parse: {
69
-
text: {
66
+
$RefParser.dereference("my-schema.yaml", {
67
+
parse: {
68
+
text: {
70
69
// parse text, html, and readme files as plain-text
71
-
ext: [".txt", ".html",/docs\/README/i]
70
+
ext: [".txt", ".html",/docs\/README/i]
72
71
}
73
72
}
74
73
});
@@ -103,7 +102,7 @@ Here is a simple example of a custom parser. For more complex examples refer to
103
102
104
103
// This parser only parses .foo files
105
104
myCustomParser.ext='.foo';
106
-
105
+
107
106
// This parser runs first (before any other parsers)
Resolvers run in a specific order, relative to other resolvers. For example, a resolver with `order: 5` will run _before_ a resolver with `order: 10`. If a resolver is unable to successfully resolve a path, then the next resolver is tried, until one succeeds or they all fail.
131
130
132
-
You can change the order in which resolvers run, which is useful if you know that most of your file references will be a certain type, or if you add your own custom resolver that you want to run _first_.
131
+
You can change the order in which resolvers run, which is useful if you know that most of your file references will be a certain type, or if you add your own custom resolver that you want to run _first_.
JSON Schema $Ref Parser can automatically cache files, so they don't need to be re-downloaded or re-read every time. You can specify a different cache duration (in milliseconds) for each resolver, or you can disable caching for a given resolver by setting the duration to zero.
141
-
142
-
```javascript
143
-
$RefParser.dereference("my-schema.yaml", {
144
-
resolve: {
145
-
// Cache downloaded files for 30 seconds
146
-
http: { cache:30000 },
147
-
148
-
// Don't cache local files (re-read them every time)
149
-
file: { cache:0 }
150
-
}
151
-
});
152
-
```
153
-
154
138
#### Resolver-specific options
155
139
Resolvers can have other options that are specific to that resolver. For example, the [HTTP resolver](../lib/read/http.js) has options that allow you to customize the HTTP headers, timeout, credentials, etc.
156
140
@@ -166,13 +150,13 @@ To add your own custom resolver, just define a function that accepts the followi
166
150
Here is a simple example of a custom resolver. For more complex examples refer to any of [the built-in resolvers](../lib/read).
167
151
168
152
```javascript
169
-
// A custom resolver that reads from a MongoDB database
153
+
// A custom resolver that reads from a MongoDB database
170
154
functionmongoDb(path, options, callback) {
171
155
// If it's not a MongoDB URL, then error-out, so the next resolver can be tried
172
156
if (path.substr(0, 10) !=="mongodb://") {
173
157
callback("Not a MongoDB URL");
174
158
}
175
-
159
+
176
160
mongoClient.connect(path, function(err, db) {
177
161
if (err) {
178
162
callback(err);
@@ -185,7 +169,7 @@ Here is a simple example of a custom resolver. For more complex examples refer
185
169
186
170
// This parser only parses .foo files
187
171
myCustomParser.ext='.foo';
188
-
172
+
189
173
// This parser runs first (before any other parsers)
190
174
myCustomParser.order=1;
191
175
@@ -203,9 +187,6 @@ Here is a simple example of a custom resolver. For more complex examples refer
|`$refs.circular` |bool or "ignore" |true |Determines whether [circular `$ref` pointers](README.md#circular-refs) are allowed. If `false`, then a `ReferenceError` will be thrown if the schema contains a circular reference.<br><br> If set to `"ignore"`, then circular references will _not_ be dereferenced, even when calling [`dereference()`](ref-parser.md#dereferenceschema-options-callback). No error will be thrown, but the [`$Refs.circular`](refs.md#circular) property will still be set to `true`.
206
-
|`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.
207
-
|`cache.http` |number |300 |The length of time (in seconds) to cache HTTP URLs. The default is five minutes. Setting to zero will cache forever.
208
-
|`cache.https` |number |300 |The length of time (in seconds) to cache HTTPS URLs. The default is five minutes. Setting to zero will cache forever.
209
190
|`http.headers` |object |`{}` |HTTP to send when downloading files<br> (note: [some headers are protected](https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name) and cannot be set)
210
191
|`http.timeout` |number |5000 |The HTTP request timeout (in milliseconds)
211
192
|`http.redirects` |number |5 |The maximum number of HTTP redirects to follow. To disable automatic following of redirects, set this to zero.
The JSON Reference path, optionally with a JSON Pointer in the hash
109
-
110
-
Immediately expires the given JSON reference, so the next time you call a method such as [`parse`](ref-parser.md#parseschema-options-callback) or [`dereference`](ref-parser.md#dereferenceschema-options-callback), the file will be refreshed rather than reusing the cached value.
0 commit comments