Skip to content

Latest commit

 

History

History
35 lines (31 loc) · 3 KB

options.md

File metadata and controls

35 lines (31 loc) · 3 KB

Options

All $RefParser methods accept an optional options parameter, which you can use to customize how the JSON Schema is parsed, resolved, dereferenced, etc.

If you pass an options parameter, you don't need to specify every option. Any options you don't specify will use their default values, as shown below.

$RefParser.dereference("my-schema.yaml", {
    allow: {
        json: false,        // Don't allow JSON files
        empty: false        // Don't allow empty files
    },
    $refs: {
        internal: false     // Don't dereference internal $refs, only external
    },
    cache: {
        fs: 1,              // Cache local files for 1 second
        http: 600           // Cache http URLs for 10 minutes
    }
});
Option Type Default Description
allow.json bool true Determines whether JSON files are supported
allow.yaml bool true Determines whether YAML files are supported
(note: all JSON files are also valid YAML files)
allow.empty bool true Determines whether it's ok for a $ref pointer to point to an empty file
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
$refs.internal bool true Determines whether internal $ref pointers (such as #/definitions/widget) will be dereferenced when calling dereference(). Either way, you'll still be able to get the value using $Refs.get()
$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.
$refs.circular bool or "ignore" true Determines whether circular $ref pointers are allowed. If false, then a ReferenceError will be thrown if the schema contains a circular reference.

If set to "ignore", then circular references will not be dereferenced, even when calling dereference(). No error will be thrown, but the $Refs.circular property will still be set to true.
cache.fs number 60 The length of time (in seconds) to cache local files. The default is one minute. Setting to zero will cache forever.
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.
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.