Skip to content

Commit

Permalink
Merge branch 'main' into fix/types
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sturgeon authored Jun 7, 2021
2 parents 59d9199 + 7a899bc commit dab6137
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 2,543 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ name: CI-CD

on:
push:
branches:
- "*"
tags-ignore:
- "*"

pull_request:
schedule:
- cron: "0 0 1 * *"

Expand Down Expand Up @@ -63,7 +59,7 @@ jobs:
browser_tests:
name: Browser Tests
runs-on: ${{ matrix.os }}
timeout-minutes: 10
timeout-minutes: 15
strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -104,7 +100,7 @@ jobs:
coverage:
name: Code Coverage
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 5
needs:
- node_tests
- browser_tests
Expand All @@ -117,8 +113,7 @@ jobs:

release:
name: Release
# removed to test beta branch.
# if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
needs:
Expand Down
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Change Log
====================================================================================================
All notable changes will be documented in this file.
JSON Schema $Ref Parser adheres to [Semantic Versioning](http://semver.org/).

==========

See [GitHub Releases](https://github.com/APIDevTools/json-schema-ref-parser/releases) for more information on newer releases.

[v9.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v9.0.0) (2020-04-21)
----------------------------------------------------------------------------------------------------
Expand Down
24 changes: 19 additions & 5 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ declare namespace $RefParser {
export type JSONParserErrorType = "EUNKNOWN" | "EPARSER" | "EUNMATCHEDPARSER" | "ERESOLVER" | "EUNMATCHEDRESOLVER" | "EMISSINGPOINTER" | "EINVALIDPOINTER";

export class JSONParserError extends Error {
public constructor(message: string, source: string);

public readonly name: string;
public readonly message: string;
public readonly source: string;
Expand Down Expand Up @@ -439,28 +441,40 @@ declare namespace $RefParser {
}

export class ParserError extends JSONParserError {
public constructor(message: string, source: string);

public readonly name = "ParserError";
public readonly code = "EPARSER";
}
export class UnmatchedParserError extends JSONParserError {
public constructor(source: string);

public readonly name = "UnmatchedParserError";
public readonly code ="EUNMATCHEDPARSER";
public readonly code = "EUNMATCHEDPARSER";
}
export class ResolverError extends JSONParserError {
public constructor(ex: Error | NodeJS.ErrnoException, source: string);

public readonly name = "ResolverError";
public readonly code ="ERESOLVER";
public readonly code = "ERESOLVER";
public readonly ioErrorCode?: string;
}
export class UnmatchedResolverError extends JSONParserError {
public constructor(source: string);

public readonly name = "UnmatchedResolverError";
public readonly code ="EUNMATCHEDRESOLVER";
public readonly code = "EUNMATCHEDRESOLVER";
}
export class MissingPointerError extends JSONParserError {
public constructor(token: string | number, source: string);

public readonly name = "MissingPointerError";
public readonly code ="EMISSINGPOINTER";
public readonly code = "EMISSINGPOINTER";
}
export class InvalidPointerError extends JSONParserError {
public constructor(pointer: string, source: string);

public readonly name = "InvalidPointerError";
public readonly code ="EINVALIDPOINTER";
public readonly code = "EINVALIDPOINTER";
}
}
2 changes: 1 addition & 1 deletion lib/parsers/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {

if (typeof data === "string") {
try {
return yaml.safeLoad(data);
return yaml.load(data);
}
catch (e) {
throw new ParserError(e.message, file.url);
Expand Down
4 changes: 4 additions & 0 deletions lib/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ function resolveIf$Ref (pointer, options) {
}
else {
let resolved = pointer.$ref.$refs._resolve($refPath, pointer.path, options);
if (resolved === null) {
return false;
}

pointer.indirections += resolved.indirections + 1;

if ($Ref.isExtended$Ref(pointer.value)) {
Expand Down
25 changes: 17 additions & 8 deletions lib/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { safePointerToPath, stripHash, getHash } = require("./util/url");
/**
* This class represents a single JSON reference and its resolved value.
*
* @constructor
* @class
*/
function $Ref () {
/**
Expand All @@ -27,24 +27,28 @@ function $Ref () {
/**
* The resolved value of the JSON reference.
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
*
* @type {?*}
*/
this.value = undefined;

/**
* The {@link $Refs} object that contains this {@link $Ref} object.
*
* @type {$Refs}
*/
this.$refs = undefined;

/**
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
*
* @type {?string}
*/
this.pathType = undefined;

/**
* List of all errors. Undefined if no errors.
*
* @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError>}
*/
this.errors = undefined;
Expand All @@ -53,25 +57,30 @@ function $Ref () {
/**
* Pushes an error to errors array.
*
* @param {Array<JSONParserError | JSONParserErrorGroup>} error - The error to be pushed
* @param {Array<JSONParserError | JSONParserErrorGroup>} err - The error to be pushed
* @returns {void}
*/
$Ref.prototype.addError = function (err) {
if (this.errors === undefined) {
this.errors = [];
}

const existingErrors = this.errors.map(({ footprint }) => footprint);

// the path has been almost certainly set at this point,
// but just in case something went wrong, let's inject path if necessary
// but just in case something went wrong, normalizeError injects path if necessary
// moreover, certain errors might point at the same spot, so filter them out to reduce noise
if (Array.isArray(err.errors)) {
this.errors.push(...err.errors.map(normalizeError));
this.errors.push(...err.errors
.map(normalizeError)
.filter(({ footprint }) => !existingErrors.includes(footprint)),
);
}
else {
else if (!existingErrors.includes(err.footprint)) {
this.errors.push(normalizeError(err));
}
};


/**
* Determines whether the given JSON reference exists within this {@link $Ref#value}.
*
Expand Down Expand Up @@ -106,8 +115,8 @@ $Ref.prototype.get = function (path, options) {
* @param {string} path - The full path being resolved, optionally with a JSON pointer in the hash
* @param {$RefParserOptions} options
* @param {string} friendlyPath - The original user-specified path (used for error messages)
* @param {string} pathFromRoot - The path of `obj` from the schema root
* @returns {Pointer}
* @param {string} pathFromRoot - The path of `obj` from the schema root
* @returns {Pointer | null}
*/
$Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
let pointer = new Pointer(this, path, friendlyPath);
Expand Down
4 changes: 4 additions & 0 deletions lib/util/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const JSONParserError = exports.JSONParserError = class JSONParserError extends

Ono.extend(this);
}

get footprint () {
return `${this.path}+${this.source}+${this.code}+${this.message}`;
}
};

setErrorName(JSONParserError);
Expand Down
Loading

0 comments on commit dab6137

Please sign in to comment.