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
|`allow.json` |bool |true |Determines whether JSON files are supported
286
+
|`allow.yaml` |bool |true |Determines whether YAML files are supported<br> (note: all JSON files are also valid YAML files)
287
+
|`allow.empty` |bool |true |Determines whether it's ok for a `$ref` pointer to point to an empty file
288
+
|`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)
289
+
|`$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)
290
+
|`$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.
291
+
|`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.
292
+
|`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.
293
+
|`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.
294
+
295
+
261
296
### `Schema` Object
262
297
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.
You can pass an options parameter to any method. You don't need to specify every option - only the ones you want to change.
460
+
### `YAML` object
461
+
This object provides simple YAML parsing functions. JSON Schema $Ref Parser uses this object internally
462
+
for its own YAML parsing, but it is also exposed so you can use it in your code if needed.
463
+
464
+
465
+
### `YAML.parse(text)`
466
+
467
+
-**text** (_required_) - `string`<br>
468
+
The YAML string to be parsed.
469
+
470
+
-**Return Value:**<br>
471
+
Returns the parsed value, which can be any valid JSON type (object, array, string, number, etc.)
472
+
473
+
This method is similar to [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse), but it supports YAML _in addition_ to JSON (since any JSON document is also a valid YAML document).
427
474
428
475
```javascript
429
-
$RefParser.dereference("my-schema.yaml", {
430
-
allow: {
431
-
json:false, // Don't allow JSON files
432
-
yaml:true// Allow YAML files
433
-
},
434
-
$refs: {
435
-
internal:false// Don't dereference internal $refs, only external
476
+
varYAML=$RefParser.YAML;
477
+
var text ="title: person \n"+
478
+
"required: \n"+
479
+
" - name \n"+
480
+
" - age \n"+
481
+
"properties: \n"+
482
+
" name: \n"+
483
+
" type: string \n"+
484
+
" age: \n"+
485
+
" type: number"
486
+
487
+
var obj =YAML.parse(text);
488
+
489
+
// {
490
+
// title: "person",
491
+
// required: ["name", "age"],
492
+
// properties: {
493
+
// name: {
494
+
// type: "string"
495
+
// },
496
+
// age: {
497
+
// type: "number"
498
+
// }
499
+
// }
500
+
// }
501
+
```
502
+
503
+
504
+
### `YAML.stringify(value)`
505
+
506
+
-**value** (_required_)<br>
507
+
The value to be converted to a YAML string. Can be any valid JSON type (object, array, string, number, etc.)
508
+
509
+
-**Return Value:**`string`<br>
510
+
Returns the a YAML string containing the serialized value
511
+
512
+
This method is similar to [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify), except that it converts a value to a YAML string instead of a JSON string.
|`allow.json` |bool |true |Determines whether JSON files are supported
447
-
|`allow.yaml` |bool |true |Determines whether YAML files are supported<br> (note: all JSON files are also valid YAML files)
448
-
|`allow.empty` |bool |true |Determines whether it's ok for a `$ref` pointer to point to an empty file
449
-
|`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)
450
-
|`$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)
451
-
|`$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.
452
-
|`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.
453
-
|`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.
454
-
|`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.
0 commit comments