Skip to content

Commit 5211eda

Browse files
Clarified documentation
1 parent 8f0109f commit 5211eda

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe
4343
}
4444
```
4545

46+
4647
The Solution:
4748
--------------------------
4849
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.
@@ -61,7 +62,7 @@ Example
6162
--------------------------
6263

6364
```javascript
64-
$RefParser.dereference("my-schema.json", function(err, schema) {
65+
$RefParser.dereference(mySchema, function(err, schema) {
6566
if (err) {
6667
console.error(err);
6768
}
@@ -76,7 +77,7 @@ $RefParser.dereference("my-schema.json", function(err, schema) {
7677
Or use [Promises syntax](http://javascriptplayground.com/blog/2015/02/promises/) instead. The following example is the same as above:
7778

7879
```javascript
79-
$RefParser.dereference("my-schema.json")
80+
$RefParser.dereference(mySchema)
8081
.then(function(schema) {
8182
console.log(schema.definitions.person.properties.firstName);
8283
})
@@ -146,10 +147,10 @@ The API
146147
- [Callbacks vs. Promises](#callbacks-vs-promises)
147148

148149

149-
### `dereference(path, [options], [callback])`
150+
### `dereference(schema, [options], [callback])`
150151

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.
152+
- **schema** (_required_) - `string` or `object`<br>
153+
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.
153154

154155
- **options** (_optional_) - `object`<br>
155156
See [options](#options) below.
@@ -177,10 +178,10 @@ $RefParser.dereference("my-schema.yaml")
177178
```
178179

179180

180-
### `bundle(path, [options], [callback])`
181+
### `bundle(schema, [options], [callback])`
181182

182-
- **path** (_required_) - `string` or `object`<br>
183-
The file path or URL of your JSON Schema file. See the [`parse`](#parsepath-options-callback) method for more info.
183+
- **schema** (_required_) - `string` or `object`<br>
184+
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.
184185

185186
- **options** (_optional_) - `object`<br>
186187
See [options](#options) below.
@@ -203,12 +204,12 @@ $RefParser.bundle("my-schema.yaml")
203204
```
204205

205206

206-
### `parse(path, [options], [callback])`
207+
### `parse(schema, [options], [callback])`
207208

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.
209+
- **schema** (_required_) - `string` or `object`<br>
210+
A JSON Schema object, or the file path or URL of a JSON Schema file.
210211
<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.
212213

213214
- **options** (_optional_) - `object`<br>
214215
See [options](#options) below.
@@ -231,10 +232,10 @@ $RefParser.parse("my-schema.yaml")
231232
```
232233

233234

234-
### `resolve(path, [options], [callback])`
235+
### `resolve(schema, [options], [callback])`
235236

236237
- **path** (_required_) - `string` or `object`<br>
237-
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.
238239

239240
- **options** (_optional_) - `object`<br>
240241
See [options](#options) below.
@@ -245,7 +246,7 @@ A callback that will receive a [`$Refs`](#refs-object) object.
245246
- **Return Value:** `Promise`<br>
246247
See [Callbacks vs. Promises](#callbacks-vs-promises) below.
247248

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.
249250
250251
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.
251252

@@ -289,7 +290,7 @@ $RefParser.dereference("my-schema.yaml", {
289290
|`allow.yaml` |bool |true |Determines whether YAML files are supported<br> (note: all JSON files are also valid YAML files)
290291
|`allow.empty` |bool |true |Determines whether it's ok for a `$ref` pointer to point to an empty file
291292
|`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)
293294
|`$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.
294295
|`$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.
295296
|`cache.fs` |number |60 |<a name="caching"></a>The length of time (in seconds) to cache local files. The default is one minute. Setting to zero will cache forever.
@@ -298,7 +299,7 @@ $RefParser.dereference("my-schema.yaml", {
298299

299300

300301
### `Schema` Object
301-
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.
302303

303304
```javascript
304305
var parser = new $RefParser();
@@ -315,7 +316,7 @@ parser.dereference("my-schema.json")
315316

316317

317318
### `$Refs` Object
318-
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.
319320

320321
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.
321322

@@ -408,7 +409,7 @@ $RefParser.resolve("my-schema.json")
408409
- **$ref** (_required_) - `string`<br>
409410
The JSON Reference path, optionally with a JSON Pointer in the hash
410411

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.
412413

413414
```javascript
414415
$RefParser.resolve("my-schema.json")
@@ -577,7 +578,7 @@ var parser = new $RefParser();
577578
parser.resolve("my-schema.json");
578579
```
579580

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).
581582

582583

583584
### Callbacks vs. Promises
@@ -590,7 +591,7 @@ JSON Schema files can contain [circular $ref pointers](https://gist.github.com/B
590591

591592
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.
592593

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.
594595

595596
```javascript
596597
"person": {

0 commit comments

Comments
 (0)