@@ -9,7 +9,7 @@ const { safePointerToPath, stripHash, getHash } = require("./util/url");
9
9
/**
10
10
* This class represents a single JSON reference and its resolved value.
11
11
*
12
- * @constructor
12
+ * @class
13
13
*/
14
14
function $Ref ( ) {
15
15
/**
@@ -27,24 +27,28 @@ function $Ref () {
27
27
/**
28
28
* The resolved value of the JSON reference.
29
29
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
30
+ *
30
31
* @type {?* }
31
32
*/
32
33
this . value = undefined ;
33
34
34
35
/**
35
36
* The {@link $Refs} object that contains this {@link $Ref} object.
37
+ *
36
38
* @type {$Refs }
37
39
*/
38
40
this . $refs = undefined ;
39
41
40
42
/**
41
43
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
44
+ *
42
45
* @type {?string }
43
46
*/
44
47
this . pathType = undefined ;
45
48
46
49
/**
47
50
* List of all errors. Undefined if no errors.
51
+ *
48
52
* @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError> }
49
53
*/
50
54
this . errors = undefined ;
@@ -53,25 +57,30 @@ function $Ref () {
53
57
/**
54
58
* Pushes an error to errors array.
55
59
*
56
- * @param {Array<JSONParserError | JSONParserErrorGroup> } error - The error to be pushed
60
+ * @param {Array<JSONParserError | JSONParserErrorGroup> } err - The error to be pushed
57
61
* @returns {void }
58
62
*/
59
63
$Ref . prototype . addError = function ( err ) {
60
64
if ( this . errors === undefined ) {
61
65
this . errors = [ ] ;
62
66
}
63
67
68
+ const existingErrors = this . errors . map ( ( { footprint } ) => footprint ) ;
69
+
64
70
// 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
66
73
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
+ ) ;
68
78
}
69
- else {
79
+ else if ( ! existingErrors . includes ( err . footprint ) ) {
70
80
this . errors . push ( normalizeError ( err ) ) ;
71
81
}
72
82
} ;
73
83
74
-
75
84
/**
76
85
* Determines whether the given JSON reference exists within this {@link $Ref#value}.
77
86
*
@@ -106,8 +115,8 @@ $Ref.prototype.get = function (path, options) {
106
115
* @param {string } path - The full path being resolved, optionally with a JSON pointer in the hash
107
116
* @param {$RefParserOptions } options
108
117
* @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 }
111
120
*/
112
121
$Ref . prototype . resolve = function ( path , options , friendlyPath , pathFromRoot ) {
113
122
let pointer = new Pointer ( this , path , friendlyPath ) ;
0 commit comments