@@ -9,7 +9,7 @@ const { safePointerToPath, stripHash, getHash } = require("./util/url");
99/**
1010 * This class represents a single JSON reference and its resolved value.
1111 *
12- * @constructor
12+ * @class
1313 */
1414function $Ref ( ) {
1515 /**
@@ -27,24 +27,28 @@ function $Ref () {
2727 /**
2828 * The resolved value of the JSON reference.
2929 * Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
30+ *
3031 * @type {?* }
3132 */
3233 this . value = undefined ;
3334
3435 /**
3536 * The {@link $Refs} object that contains this {@link $Ref} object.
37+ *
3638 * @type {$Refs }
3739 */
3840 this . $refs = undefined ;
3941
4042 /**
4143 * Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
44+ *
4245 * @type {?string }
4346 */
4447 this . pathType = undefined ;
4548
4649 /**
4750 * List of all errors. Undefined if no errors.
51+ *
4852 * @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError> }
4953 */
5054 this . errors = undefined ;
@@ -53,25 +57,30 @@ function $Ref () {
5357/**
5458 * Pushes an error to errors array.
5559 *
56- * @param {Array<JSONParserError | JSONParserErrorGroup> } error - The error to be pushed
60+ * @param {Array<JSONParserError | JSONParserErrorGroup> } err - The error to be pushed
5761 * @returns {void }
5862 */
5963$Ref . prototype . addError = function ( err ) {
6064 if ( this . errors === undefined ) {
6165 this . errors = [ ] ;
6266 }
6367
68+ const existingErrors = this . errors . map ( ( { footprint } ) => footprint ) ;
69+
6470 // the path has been almost certainly set at this point,
65- // but just in case something went wrong, let's inject path if necessary
71+ // but just in case something went wrong, normalizeError injects path if necessary
72+ // moreover, certain errors might point at the same spot, so filter them out to reduce noise
6673 if ( Array . isArray ( err . errors ) ) {
67- this . errors . push ( ...err . errors . map ( normalizeError ) ) ;
74+ this . errors . push ( ...err . errors
75+ . map ( normalizeError )
76+ . filter ( ( { footprint } ) => ! existingErrors . includes ( footprint ) ) ,
77+ ) ;
6878 }
69- else {
79+ else if ( ! existingErrors . includes ( err . footprint ) ) {
7080 this . errors . push ( normalizeError ( err ) ) ;
7181 }
7282} ;
7383
74-
7584/**
7685 * Determines whether the given JSON reference exists within this {@link $Ref#value}.
7786 *
@@ -106,8 +115,8 @@ $Ref.prototype.get = function (path, options) {
106115 * @param {string } path - The full path being resolved, optionally with a JSON pointer in the hash
107116 * @param {$RefParserOptions } options
108117 * @param {string } friendlyPath - The original user-specified path (used for error messages)
109- * @param {string } pathFromRoot - The path of `obj` from the schema root
110- * @returns {Pointer }
118+ * @param {string } pathFromRoot - The path of `obj` from the schema root
119+ * @returns {Pointer | null }
111120 */
112121$Ref . prototype . resolve = function ( path , options , friendlyPath , pathFromRoot ) {
113122 let pointer = new Pointer ( this , path , friendlyPath ) ;
0 commit comments