Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-ref-parser

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-ref-parser - npm Package Compare versions

Comparing version 6.0.1 to 6.0.2

2

CHANGELOG.md

@@ -89,3 +89,3 @@ # Change Log

Despite the significant code changes, there were no changes to any public-facing APIs, and [all tests are passing](https://apidevtools.org/json-schema-ref-parser/test/index.html) as expected.
Despite the significant code changes, there were no changes to any public-facing APIs, and [all tests are passing](https://apidevtools.org/json-schema-ref-parser/test/) as expected.

@@ -92,0 +92,0 @@ [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v2.1.0...v2.2.0)

@@ -1,6 +0,6 @@

'use strict';
"use strict";
var $Ref = require('./ref'),
Pointer = require('./pointer'),
url = require('./util/url');
var $Ref = require("./ref"),
Pointer = require("./pointer"),
url = require("./util/url");

@@ -22,3 +22,3 @@ module.exports = bundle;

var inventory = [];
crawl(parser, 'schema', parser.$refs._root$Ref.path + '#', '#', 0, inventory, parser.$refs, options);
crawl(parser, "schema", parser.$refs._root$Ref.path + "#", "#", 0, inventory, parser.$refs, options);

@@ -43,3 +43,3 @@ // Remap all $ref pointers

if (obj && typeof obj === 'object') {
if (obj && typeof obj === "object") {
if ($Ref.isAllowed$Ref(obj)) {

@@ -56,6 +56,6 @@ inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);

// so we always crawl that property first, if it exists.
if (a === 'definitions') {
if (a === "definitions") {
return -1;
}
else if (b === 'definitions') {
else if (b === "definitions") {
return 1;

@@ -192,4 +192,4 @@ }

// Most people will expect references to be bundled into the the "definitions" property if possible.
var aDefinitionsIndex = a.pathFromRoot.lastIndexOf('/definitions');
var bDefinitionsIndex = b.pathFromRoot.lastIndexOf('/definitions');
var aDefinitionsIndex = a.pathFromRoot.lastIndexOf("/definitions");
var bDefinitionsIndex = b.pathFromRoot.lastIndexOf("/definitions");

@@ -219,5 +219,5 @@ if (aDefinitionsIndex !== bDefinitionsIndex) {

}
else if (entry.file === file && entry.hash.indexOf(hash + '/') === 0) {
// This $ref points to the a sub-value as the prevous $ref, so remap it beneath that path
entry.$ref.$ref = Pointer.join(pathFromRoot, Pointer.parse(entry.hash));
else if (entry.file === file && entry.hash.indexOf(hash + "/") === 0) {
// This $ref points to a sub-value of the prevous $ref, so remap it beneath that path
entry.$ref.$ref = Pointer.join(pathFromRoot, Pointer.parse(entry.hash.replace(hash, "#")));
}

@@ -224,0 +224,0 @@ else {

@@ -1,7 +0,7 @@

'use strict';
"use strict";
var $Ref = require('./ref'),
Pointer = require('./pointer'),
ono = require('ono'),
url = require('./util/url');
var $Ref = require("./ref"),
Pointer = require("./pointer"),
ono = require("ono"),
url = require("./util/url");

@@ -19,3 +19,3 @@ module.exports = dereference;

// console.log('Dereferencing $ref pointers in %s', parser.$refs._root$Ref.path);
var dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, '#', [], parser.$refs, options);
var dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", [], parser.$refs, options);
parser.$refs.circular = dereferenced.circular;

@@ -43,3 +43,3 @@ parser.schema = dereferenced.value;

if (obj && typeof obj === 'object') {
if (obj && typeof obj === "object") {
parents.push(obj);

@@ -119,3 +119,3 @@

if (circular && !directCircular && options.dereference.circular === 'ignore') {
if (circular && !directCircular && options.dereference.circular === "ignore") {
// The user has chosen to "ignore" circular references, so don't change the value

@@ -149,5 +149,5 @@ dereferencedValue = $ref;

if (!options.dereference.circular) {
throw ono.reference('Circular $ref pointer found at %s', keyPath);
throw ono.reference("Circular $ref pointer found at %s", keyPath);
}
return true;
}

@@ -17,3 +17,3 @@ import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from 'json-schema';

*/
schema: JSONSchema4 | JSONSchema6
schema: $RefParser.JSONSchema

@@ -40,7 +40,28 @@ /**

*/
dereference(path: string, schema: string | JSONSchema4 | JSONSchema6, options?: $RefParser.Options, callback?: (err: Error | null, schema: JSONSchema4 | JSONSchema6 | null) => any): Promise<JSONSchema4 | JSONSchema6>
dereference(path: string, options?: $RefParser.Options, callback?: (err: Error | null, schema: JSONSchema4 | JSONSchema6 | null) => any): Promise<JSONSchema4 | JSONSchema6>
dereference(schema: JSONSchema4 | JSONSchema6, options?: $RefParser.Options, callback?: (err: Error | null, schema: JSONSchema4 | JSONSchema6 | null) => any): Promise<JSONSchema4 | JSONSchema6>
dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
/**
* 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.
*
* 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, so be careful if you intend to serialize the schema using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
*
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#dereferenceschema-options-callback
*
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
* @param options (optional)
* @param callback (optional) A callback that will receive the dereferenced schema object
*/
static dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
/**
* 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.

@@ -56,9 +77,28 @@ *

*/
bundle(
schema: string | JSONSchema4 | JSONSchema6,
options?: $RefParser.Options,
callback?: (err: Error | null, schema: JSONSchema4 | JSONSchema6 | null) => any
): Promise<JSONSchema4 | JSONSchema6>
bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
/**
* 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.
*
* This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
*
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#bundleschema-options-callback
*
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
* @param options (optional)
* @param callback (optional) A callback that will receive the bundled schema object
*/
static bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
/**
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*

@@ -74,7 +114,8 @@ *

*/
parse(
schema: string | JSONSchema4 | JSONSchema6,
options?: $RefParser.Options,
callback?: (err: Error | null, schema: JSONSchema4 | JSONSchema6 | null) => any
): Promise<JSONSchema4 | JSONSchema6>
parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;

@@ -84,2 +125,20 @@ /**

*
* 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.
*
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#parseschema-options-callback
*
* @param schema A JSON Schema object, or the file path or URL of a 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.
* @param options (optional)
* @param callback (optional) A callback that will receive the parsed schema object, or an error
*/
static parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
static parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
/**
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
*
* 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. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.

@@ -93,7 +152,26 @@ *

*/
resolve(
schema: string | JSONSchema4 | JSONSchema6,
options?: $RefParser.Options,
callback?: (err: Error | null, $refs: $RefParser.$Refs | null) => any
): Promise<$RefParser.$Refs>
resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
/**
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
*
* 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. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
*
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#resolveschema-options-callback
*
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
* @param options (optional)
* @param callback (optional) A callback that will receive a `$Refs` object
*/
static resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
static resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
}

@@ -103,6 +181,10 @@

export type JSONSchema = JSONSchema4 | JSONSchema6;
export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any;
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
/**
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/options.md
*/
export type Options = object & {
export type Options = {

@@ -284,3 +366,3 @@ /**

*/
values(...types: string[]): { [url: string]: JSONSchema4 | JSONSchema6 }
values(...types: string[]): { [url: string]: $RefParser.JSONSchema }

@@ -287,0 +369,0 @@ /**

@@ -1,16 +0,16 @@

'use strict';
"use strict";
var Options = require('./options'),
$Refs = require('./refs'),
parse = require('./parse'),
normalizeArgs = require('./normalize-args'),
resolveExternal = require('./resolve-external'),
bundle = require('./bundle'),
dereference = require('./dereference'),
url = require('./util/url'),
maybe = require('call-me-maybe'),
ono = require('ono');
var Options = require("./options"),
$Refs = require("./refs"),
parse = require("./parse"),
normalizeArgs = require("./normalize-args"),
resolveExternal = require("./resolve-external"),
bundle = require("./bundle"),
dereference = require("./dereference"),
url = require("./util/url"),
maybe = require("call-me-maybe"),
ono = require("ono");
module.exports = $RefParser;
module.exports.YAML = require('./util/yaml');
module.exports.YAML = require("./util/yaml");

@@ -74,3 +74,3 @@ /**

if (!args.path && !args.schema) {
var err = ono('Expected a file path, URL, or object. Got %s', args.path || args.schema);
var err = ono("Expected a file path, URL, or object. Got %s", args.path || args.schema);
return maybe(args.callback, Promise.reject(err));

@@ -89,6 +89,6 @@ }

// If it doesn't work for your use-case, then use a URL instead.
var pathType = 'http';
var pathType = "http";
if (url.isFileSystemPath(args.path)) {
args.path = url.fromFileSystemPath(args.path);
pathType = 'file';
pathType = "file";
}

@@ -99,3 +99,3 @@

if (args.schema && typeof args.schema === 'object') {
if (args.schema && typeof args.schema === "object") {
// A schema object was passed-in.

@@ -116,3 +116,3 @@ // So immediately add a new $Ref with the schema object as its value

.then(function (result) {
if (!result || typeof result !== 'object' || Buffer.isBuffer(result)) {
if (!result || typeof result !== "object" || Buffer.isBuffer(result)) {
throw ono.syntax('"%s" is not a valid JSON Schema', me.$refs._root$Ref.path || result);

@@ -119,0 +119,0 @@ }

@@ -1,4 +0,4 @@

'use strict';
"use strict";
var Options = require('./options');
var Options = require("./options");

@@ -17,3 +17,3 @@ module.exports = normalizeArgs;

if (typeof args[args.length - 1] === 'function') {
if (typeof args[args.length - 1] === "function") {
// The last parameter is a callback function

@@ -23,6 +23,6 @@ callback = args.pop();

if (typeof args[0] === 'string') {
if (typeof args[0] === "string") {
// The first parameter is the path
path = args[0];
if (typeof args[2] === 'object') {
if (typeof args[2] === "object") {
// The second parameter is the schema, and the third parameter is the options

@@ -40,3 +40,3 @@ schema = args[1];

// The first parameter is the schema
path = '';
path = "";
schema = args[0];

@@ -43,0 +43,0 @@ options = args[1];

/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
'use strict';
"use strict";
var jsonParser = require('./parsers/json'),
yamlParser = require('./parsers/yaml'),
textParser = require('./parsers/text'),
binaryParser = require('./parsers/binary'),
fileResolver = require('./resolvers/file'),
httpResolver = require('./resolvers/http');
var jsonParser = require("./parsers/json"),
yamlParser = require("./parsers/yaml"),
textParser = require("./parsers/text"),
binaryParser = require("./parsers/binary"),
fileResolver = require("./resolvers/file"),
httpResolver = require("./resolvers/http");

@@ -110,3 +110,3 @@ module.exports = $RefParserOptions;

return val &&
(typeof val === 'object') &&
(typeof val === "object") &&
!Array.isArray(val) &&

@@ -113,0 +113,0 @@ !(val instanceof RegExp) &&

@@ -1,6 +0,6 @@

'use strict';
"use strict";
var ono = require('ono'),
url = require('./util/url'),
plugins = require('./util/plugins');
var ono = require("ono"),
url = require("./util/url"),
plugins = require("./util/plugins");

@@ -68,7 +68,7 @@ module.exports = parse;

var resolvers = plugins.all(options.resolve);
resolvers = plugins.filter(resolvers, 'canRead', file);
resolvers = plugins.filter(resolvers, "canRead", file);
// Run the resolvers, in order, until one of them succeeds
plugins.sort(resolvers);
plugins.run(resolvers, 'read', file)
plugins.run(resolvers, "read", file)
.then(resolve, onError);

@@ -109,3 +109,3 @@

var allParsers = plugins.all(options.parse);
var filteredParsers = plugins.filter(allParsers, 'canParse', file);
var filteredParsers = plugins.filter(allParsers, "canParse", file);
var parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;

@@ -115,3 +115,3 @@

plugins.sort(parsers);
plugins.run(parsers, 'parse', file)
plugins.run(parsers, "parse", file)
.then(onParsed, onError);

@@ -131,6 +131,6 @@

err = err instanceof Error ? err : new Error(err);
reject(ono.syntax(err, 'Error parsing %s', file.url));
reject(ono.syntax(err, "Error parsing %s", file.url));
}
else {
reject(ono.syntax('Unable to parse %s', file.url));
reject(ono.syntax("Unable to parse %s", file.url));
}

@@ -149,5 +149,5 @@ }

return value === undefined ||
(typeof value === 'object' && Object.keys(value).length === 0) ||
(typeof value === 'string' && value.trim().length === 0) ||
(typeof value === "object" && Object.keys(value).length === 0) ||
(typeof value === "string" && value.trim().length === 0) ||
(Buffer.isBuffer(value) && value.length === 0);
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -3,0 +3,0 @@ var BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -26,3 +26,3 @@ module.exports = {

*/
canParse: '.json',
canParse: ".json",

@@ -45,3 +45,3 @@ /**

if (typeof data === 'string') {
if (typeof data === "string") {
if (data.trim().length === 0) {

@@ -48,0 +48,0 @@ resolve(undefined); // This mirrors the YAML behavior

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -25,3 +25,3 @@ var TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;

*/
encoding: 'utf8',
encoding: "utf8",

@@ -42,3 +42,3 @@ /**

// Use this parser if the file is a string or Buffer, and has a known text-based extension
return (typeof file.data === 'string' || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url);
return (typeof file.data === "string" || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url);
},

@@ -56,3 +56,3 @@

parse: function parseText (file) {
if (typeof file.data === 'string') {
if (typeof file.data === "string") {
return file.data;

@@ -64,5 +64,5 @@ }

else {
throw new Error('data is not text');
throw new Error("data is not text");
}
}
};

@@ -1,4 +0,4 @@

'use strict';
"use strict";
var YAML = require('../util/yaml');
var YAML = require("../util/yaml");

@@ -28,3 +28,3 @@ module.exports = {

*/
canParse: ['.yaml', '.yml', '.json'], // JSON is valid YAML
canParse: [".yaml", ".yml", ".json"], // JSON is valid YAML

@@ -47,3 +47,3 @@ /**

if (typeof data === 'string') {
if (typeof data === "string") {
resolve(YAML.parse(data));

@@ -50,0 +50,0 @@ }

@@ -1,8 +0,8 @@

'use strict';
"use strict";
module.exports = Pointer;
var $Ref = require('./ref'),
url = require('./util/url'),
ono = require('ono'),
var $Ref = require("./ref"),
url = require("./util/url"),
ono = require("ono"),
slashes = /\//g,

@@ -166,10 +166,10 @@ tildes = /~/g,

// Split into an array
pointer = pointer.split('/');
pointer = pointer.split("/");
// Decode each part, according to RFC 6901
for (var i = 0; i < pointer.length; i++) {
pointer[i] = decodeURIComponent(pointer[i].replace(escapedSlash, '/').replace(escapedTilde, '~'));
pointer[i] = decodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
}
if (pointer[0] !== '') {
if (pointer[0] !== "") {
throw ono.syntax('Invalid $ref pointer "%s". Pointers must begin with "#/"', pointer);

@@ -190,4 +190,4 @@ }

// Ensure that the base path contains a hash
if (base.indexOf('#') === -1) {
base += '#';
if (base.indexOf("#") === -1) {
base += "#";
}

@@ -200,3 +200,3 @@

// Encode the token, according to RFC 6901
base += '/' + encodeURIComponent(token.replace(tildes, '~0').replace(slashes, '~1'));
base += "/" + encodeURIComponent(token.replace(tildes, "~0").replace(slashes, "~1"));
}

@@ -261,4 +261,4 @@

function setValue (pointer, token, value) {
if (pointer.value && typeof pointer.value === 'object') {
if (token === '-' && Array.isArray(pointer.value)) {
if (pointer.value && typeof pointer.value === "object") {
if (token === "-" && Array.isArray(pointer.value)) {
pointer.value.push(value);

@@ -265,0 +265,0 @@ }

@@ -1,6 +0,6 @@

'use strict';
"use strict";
module.exports = $Ref;
var Pointer = require('./pointer');
var Pointer = require("./pointer");

@@ -105,3 +105,3 @@ /**

$Ref.is$Ref = function (value) {
return value && typeof value === 'object' && typeof value.$ref === 'string' && value.$ref.length > 0;
return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
};

@@ -116,3 +116,3 @@

$Ref.isExternal$Ref = function (value) {
return $Ref.is$Ref(value) && value.$ref[0] !== '#';
return $Ref.is$Ref(value) && value.$ref[0] !== "#";
};

@@ -130,7 +130,7 @@

if ($Ref.is$Ref(value)) {
if (value.$ref.substr(0, 2) === '#/' || value.$ref === '#') {
if (value.$ref.substr(0, 2) === "#/" || value.$ref === "#") {
// It's a JSON Pointer reference, which is always allowed
return true;
}
else if (value.$ref[0] !== '#' && (!options || options.resolve.external)) {
else if (value.$ref[0] !== "#" && (!options || options.resolve.external)) {
// It's an external reference, which is allowed by the options

@@ -217,6 +217,6 @@ return true;

$Ref.dereference = function ($ref, resolvedValue) {
if (resolvedValue && typeof resolvedValue === 'object' && $Ref.isExtended$Ref($ref)) {
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {
var merged = {};
Object.keys($ref).forEach(function (key) {
if (key !== '$ref') {
if (key !== "$ref") {
merged[key] = $ref[key];

@@ -223,0 +223,0 @@ }

@@ -1,6 +0,6 @@

'use strict';
"use strict";
var ono = require('ono'),
$Ref = require('./ref'),
url = require('./util/url');
var ono = require("ono"),
$Ref = require("./ref"),
url = require("./util/url");

@@ -193,5 +193,5 @@ module.exports = $Refs;

encoded: path,
decoded: $refs[path].pathType === 'file' ? url.toFileSystemPath(path, true) : path
decoded: $refs[path].pathType === "file" ? url.toFileSystemPath(path, true) : path
};
});
}

@@ -1,7 +0,7 @@

'use strict';
"use strict";
var $Ref = require('./ref'),
Pointer = require('./pointer'),
parse = require('./parse'),
url = require('./util/url');
var $Ref = require("./ref"),
Pointer = require("./pointer"),
parse = require("./parse"),
url = require("./util/url");

@@ -31,3 +31,3 @@ module.exports = resolveExternal;

// console.log('Resolving $ref pointers in %s', parser.$refs._root$Ref.path);
var promises = crawl(parser.schema, parser.$refs._root$Ref.path + '#', parser.$refs, options);
var promises = crawl(parser.schema, parser.$refs._root$Ref.path + "#", parser.$refs, options);
return Promise.all(promises);

@@ -57,3 +57,3 @@ }

if (obj && typeof obj === 'object') {
if (obj && typeof obj === "object") {
if ($Ref.isExternal$Ref(obj)) {

@@ -110,5 +110,5 @@ promises.push(resolve$Ref(obj, path, $refs, options));

// console.log('Resolving $ref pointers in %s', withoutHash);
var promises = crawl(result, withoutHash + '#', $refs, options);
var promises = crawl(result, withoutHash + "#", $refs, options);
return Promise.all(promises);
});
}

@@ -1,5 +0,5 @@

'use strict';
var fs = require('fs'),
ono = require('ono'),
url = require('../util/url');
"use strict";
var fs = require("fs"),
ono = require("ono"),
url = require("../util/url");

@@ -43,3 +43,3 @@ module.exports = {

catch (err) {
reject(ono.uri(err, 'Malformed URI: %s', file.url));
reject(ono.uri(err, "Malformed URI: %s", file.url));
}

@@ -46,0 +46,0 @@

@@ -1,7 +0,7 @@

'use strict';
"use strict";
var http = require('http'),
https = require('https'),
ono = require('ono'),
url = require('../util/url');
var http = require("http"),
https = require("https"),
ono = require("ono"),
url = require("../util/url");

@@ -105,11 +105,11 @@ module.exports = {

if (res.statusCode >= 400) {
throw ono({ status: res.statusCode }, 'HTTP ERROR %d', res.statusCode);
throw ono({ status: res.statusCode }, "HTTP ERROR %d", res.statusCode);
}
else if (res.statusCode >= 300) {
if (redirects.length > httpOptions.redirects) {
reject(ono({ status: res.statusCode }, 'Error downloading %s. \nToo many redirects: \n %s',
redirects[0], redirects.join(' \n ')));
reject(ono({ status: res.statusCode }, "Error downloading %s. \nToo many redirects: \n %s",
redirects[0], redirects.join(" \n ")));
}
else if (!res.headers.location) {
throw ono({ status: res.statusCode }, 'HTTP %d redirect with no location header', res.statusCode);
throw ono({ status: res.statusCode }, "HTTP %d redirect with no location header", res.statusCode);
}

@@ -127,3 +127,3 @@ else {

.catch(function (err) {
reject(ono(err, 'Error downloading', u.href));
reject(ono(err, "Error downloading", u.href));
});

@@ -146,3 +146,3 @@ });

var protocol = u.protocol === 'https:' ? https : http;
var protocol = u.protocol === "https:" ? https : http;
var req = protocol.get({

@@ -158,22 +158,22 @@ hostname: u.hostname,

if (typeof req.setTimeout === 'function') {
if (typeof req.setTimeout === "function") {
req.setTimeout(httpOptions.timeout);
}
req.on('timeout', function () {
req.on("timeout", function () {
req.abort();
});
req.on('error', reject);
req.on("error", reject);
req.once('response', function (res) {
req.once("response", function (res) {
res.body = new Buffer(0);
res.on('data', function (data) {
res.on("data", function (data) {
res.body = Buffer.concat([res.body, new Buffer(data)]);
});
res.on('error', reject);
res.on("error", reject);
res.on('end', function () {
res.on("end", function () {
resolve(res);

@@ -180,0 +180,0 @@ });

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -13,3 +13,3 @@ /**

.filter(function (key) {
return typeof plugins[key] === 'object';
return typeof plugins[key] === "object";
})

@@ -80,3 +80,3 @@ .map(function (key) {

var result = getResult(plugin, method, file, callback);
if (result && typeof result.then === 'function') {
if (result && typeof result.then === "function") {
// A promise was returned

@@ -136,3 +136,3 @@ result.then(onSuccess, onError);

if (typeof value === 'function') {
if (typeof value === "function") {
return value.apply(obj, [file, callback]);

@@ -148,3 +148,3 @@ }

}
else if (typeof value === 'string') {
else if (typeof value === "string") {
return value === file.extension;

@@ -151,0 +151,0 @@ }

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -10,4 +10,4 @@ var isWindows = /^win/.test(process.platform),

var urlEncodePatterns = [
/\?/g, '%3F',
/\#/g, '%23',
/\?/g, "%3F",
/\#/g, "%23",
];

@@ -17,11 +17,11 @@

var urlDecodePatterns = [
/\%23/g, '#',
/\%24/g, '$',
/\%26/g, '&',
/\%2C/g, ',',
/\%40/g, '@'
/\%23/g, "#",
/\%24/g, "$",
/\%26/g, "&",
/\%2C/g, ",",
/\%40/g, "@"
];
exports.parse = require('url').parse;
exports.resolve = require('url').resolve;
exports.parse = require("url").parse;
exports.resolve = require("url").resolve;

@@ -34,3 +34,3 @@ /**

exports.cwd = function cwd () {
return process.browser ? location.href : process.cwd() + '/';
return process.browser ? location.href : process.cwd() + "/";
};

@@ -59,7 +59,7 @@

exports.getExtension = function getExtension (path) {
var lastDot = path.lastIndexOf('.');
var lastDot = path.lastIndexOf(".");
if (lastDot >= 0) {
return path.substr(lastDot).toLowerCase();
}
return '';
return "";
};

@@ -75,7 +75,7 @@

exports.getHash = function getHash (path) {
var hashIndex = path.indexOf('#');
var hashIndex = path.indexOf("#");
if (hashIndex >= 0) {
return path.substr(hashIndex);
}
return '#';
return "#";
};

@@ -90,3 +90,3 @@

exports.stripHash = function stripHash (path) {
var hashIndex = path.indexOf('#');
var hashIndex = path.indexOf("#");
if (hashIndex >= 0) {

@@ -106,3 +106,3 @@ path = path.substr(0, hashIndex);

var protocol = url.getProtocol(path);
if (protocol === 'http' || protocol === 'https') {
if (protocol === "http" || protocol === "https") {
return true;

@@ -135,3 +135,3 @@ }

var protocol = url.getProtocol(path);
return protocol === undefined || protocol === 'file';
return protocol === undefined || protocol === "file";
};

@@ -159,3 +159,3 @@

if (isWindows) {
path = path.replace(/\\/g, '/');
path = path.replace(/\\/g, "/");
}

@@ -196,10 +196,10 @@

// or convert it to a local filesystem path
var isFileUrl = path.substr(0, 7).toLowerCase() === 'file://';
var isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
if (isFileUrl) {
// Strip-off the protocol, and the initial "/", if there is one
path = path[7] === '/' ? path.substr(8) : path.substr(7);
path = path[7] === "/" ? path.substr(8) : path.substr(7);
// insert a colon (":") after the drive letter on Windows
if (isWindows && path[1] === '/') {
path = path[0] + ':' + path.substr(1);
if (isWindows && path[1] === "/") {
path = path[0] + ":" + path.substr(1);
}

@@ -209,3 +209,3 @@

// Return the consistently-formatted "file://" URL
path = 'file:///' + path;
path = "file:///" + path;
}

@@ -217,3 +217,3 @@ else {

isFileUrl = false;
path = isWindows ? path : '/' + path;
path = isWindows ? path : "/" + path;
}

@@ -225,6 +225,6 @@ }

// Replace forward slashes with backslashes
path = path.replace(forwardSlashPattern, '\\');
path = path.replace(forwardSlashPattern, "\\");
// Capitalize the drive letter
if (path.substr(1, 2) === ':\\') {
if (path.substr(1, 2) === ":\\") {
path = path[0].toUpperCase() + path.substr(1);

@@ -231,0 +231,0 @@ }

/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
'use strict';
"use strict";
var yaml = require('js-yaml'),
ono = require('ono');
var yaml = require("js-yaml"),
ono = require("ono");

@@ -43,3 +43,3 @@ /**

try {
var indent = (typeof space === 'string' ? space.length : space) || 2;
var indent = (typeof space === "string" ? space.length : space) || 2;
return yaml.safeDump(value, { indent: indent });

@@ -46,0 +46,0 @@ }

{
"name": "json-schema-ref-parser",
"version": "6.0.1",
"version": "6.0.2",
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",

@@ -25,3 +25,3 @@ "keywords": [

],
"homepage": "https://github.com/APIDevTools/json-schema-ref-parser",
"homepage": "https://apidevtools.org/json-schema-ref-parser/",
"repository": {

@@ -45,8 +45,9 @@ "type": "git",

"scripts": {
"lint": "eslint lib test/fixtures test/specs --fix",
"lint": "eslint lib test/fixtures test/specs",
"build": "simplifyify lib/index.js --outfile dist/ref-parser.js --standalone \\$RefParser --bundle --debug --minify",
"watch": "npm run build -- --watch",
"test": "npm run test:node && npm run test:browser && npm run lint",
"test": "npm run test:node && npm run test:browser && npm run test:typescript && npm run lint",
"test:node": "mocha",
"test:browser": "karma start --single-run",
"test:browser": "npm run build && karma start --single-run",
"test:typescript": "tsc --noEmit --strict --lib esnext test/specs/typescript-definition.ts",
"coverage": "npm run coverage:node && npm run coverage:browser",

@@ -58,14 +59,14 @@ "coverage:node": "nyc --reporter=text --reporter=lcov --report-dir coverage/node mocha",

"release": "npm run upgrade && npm test && npm run bump && npm publish",
"start": "http-server -c-1 -o http://localhost:8080/test/index.html"
"start": "http-server -c-1 -o http://localhost:8080/test/"
},
"devDependencies": {
"@types/json-schema": "^7.0.1",
"@types/node": "^10.11.5",
"@types/node": "^10.12.1",
"chai": "^4.2.0",
"codacy-coverage": "^3.1.0",
"codacy-coverage": "^3.2.0",
"coveralls": "^3.0.2",
"eslint": "^5.6.1",
"eslint-config-modular": "^4.2.2",
"eslint": "^5.8.0",
"eslint-config-modular": "^5.0.0",
"http-server": "^0.11.1",
"karma": "^3.0.0",
"karma": "^3.1.1",
"karma-chai": "^0.1.0",

@@ -85,4 +86,5 @@ "karma-chrome-launcher": "^2.2.0",

"npm-check": "^5.9.0",
"nyc": "^13.0.1",
"simplifyify": "^6.0.1",
"nyc": "^13.1.0",
"simplifyify": "^7.0.0",
"typescript": "^3.1.4",
"version-bump-prompt": "^4.2.1"

@@ -89,0 +91,0 @@ },

@@ -53,5 +53,5 @@ JSON Schema $Ref Parser

- Can [dereference](https://apidevtools.org/json-schema-ref-parser/docs/ref-parser.html#dereferencepath-options-callback) your schema, producing a plain-old JavaScript object that's easy to work with
- Supports [circular references](https://apidevtools.org/json-schema-ref-parser/docs/README.html#circular-refs), nested references, back-references, and cross-references between files
- Supports [circular references](https://apidevtools.org/json-schema-ref-parser/docs/#circular-refs), nested references, back-references, and cross-references between files
- Maintains object reference equality &mdash; `$ref` pointers to the same value always resolve to the same object instance
- [Tested](https://apidevtools.org/json-schema-ref-parser/test/index.html) in Node, io.js, and all major web browsers on Windows, Mac, and Linux
- [Tested](https://apidevtools.org/json-schema-ref-parser/test/) in Node, io.js, and all major web browsers on Windows, Mac, and Linux

@@ -147,3 +147,3 @@

5. __Start the local web server__<br>
`npm start` (then browse to [http://localhost:8080/test/index.html](https://apidevtools.org/json-schema-ref-parser/test/index.html))
`npm start` (then browse to [http://localhost:8080/test/](http://localhost:8080/test/))

@@ -150,0 +150,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc