@apidevtools/json-schema-ref-parser 11.1.1 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,17 +136,17 @@ function inventory$Ref($refParent, $refKey, path, pathFromRoot, indirections, in
136
136
  }
137
137
  }
138
138
  inventory.push({
139
- $ref,
140
- parent: $refParent,
141
- key: $refKey,
142
- pathFromRoot,
143
- depth,
144
- file,
145
- hash,
146
- value: pointer.value,
147
- circular: pointer.circular,
148
- extended,
149
- external,
139
+ $ref, // The JSON Reference (e.g. {$ref: string})
140
+ parent: $refParent, // The object that contains this $ref pointer
141
+ key: $refKey, // The key in `parent` that is the $ref pointer
142
+ pathFromRoot, // The path to the $ref pointer, from the JSON Schema root
143
+ depth, // How far from the JSON Schema root is this $ref pointer?
144
+ file, // The file that the $ref pointer resolves to
145
+ hash, // The hash within `file` that the $ref pointer resolves to
146
+ value: pointer.value, // The resolved value of the $ref pointer
147
+ circular: pointer.circular, // Is this $ref pointer DIRECTLY circular? (i.e. it references itself)
148
+ extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
149
+ external, // Does this $ref pointer point to a file other than the main JSON Schema file?
150
150
  indirections, // The number of indirect references that were traversed to resolve the value
151
151
  });
152
152
  // Recursively crawl the resolved value
@@ -89,7 +89,7 @@ function crawl(obj, path, pathFromRoot, parents, processedObjects, dereferencedC
89
89
  if (obj[key] !== dereferenced.value) {
90
90
  obj[key] = dereferenced.value;
91
91
  if (options.dereference.onDereference) {
92
- options.dereference.onDereference(value.$ref, obj[key]);
92
+ options.dereference.onDereference(value.$ref, obj[key], obj, key);
93
93
  }
94
94
  }
95
95
  }
@@ -65,10 +65,12 @@ interface $RefParserOptions {
65
65
  /**
66
66
  * Callback invoked during dereferencing.
67
67
  *
68
- * @argument {string} path The path being dereferenced (ie. the `$ref` string).
69
- * @argument {JSONSchemaObject} object The JSON-Schema that the `$ref` resolved to.
68
+ * @argument {string} path - The path being dereferenced (ie. the `$ref` string)
69
+ * @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
70
+ * @argument {JSONSchemaObject} parent - The parent of the dereferenced object
71
+ * @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
70
72
  */
71
- onDereference?(path: string, value: JSONSchemaObject): void;
73
+ onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
72
74
  /**
73
75
  * Whether a reference should resolve relative to its directory/path, or from the cwd
74
76
  *
@@ -91,7 +91,8 @@ exports.getNewOptions = getNewOptions;
91
91
  */
92
92
  function merge(target, source) {
93
93
  if (isMergeable(source)) {
94
- const keys = Object.keys(source);
94
+ // prevent prototype pollution
95
+ const keys = Object.keys(source).filter((key) => !["__proto__", "constructor", "prototype"].includes(key));
95
96
  for (let i = 0; i < keys.length; i++) {
96
97
  const key = keys[i];
97
98
  const sourceSetting = source[key];
@@ -21,7 +21,7 @@ exports.default = {
21
21
  * Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
22
22
  * every parser will be tried.
23
23
  */
24
- canParse: [".yaml", ".yml", ".json"],
24
+ canParse: [".yaml", ".yml", ".json"], // JSON is valid YAML
25
25
  /**
26
26
  * Parses the given file as YAML
27
27
  *
@@ -44,7 +44,7 @@ exports.default = {
44
44
  /**
45
45
  * HTTP request timeout (in milliseconds).
46
46
  */
47
- timeout: 5000,
47
+ timeout: 5000, // 5 seconds
48
48
  /**
49
49
  * The maximum number of HTTP redirects to follow.
50
50
  * To disable automatic following of redirects, set this to zero.
@@ -107,7 +107,7 @@ function crawl(
107
107
  if (obj[key] !== dereferenced.value) {
108
108
  obj[key] = dereferenced.value;
109
109
  if (options.dereference.onDereference) {
110
- options.dereference.onDereference(value.$ref, obj[key]);
110
+ options.dereference.onDereference(value.$ref, obj[key], obj, key);
111
111
  }
112
112
  }
113
113
  } else {
package/lib/options.ts CHANGED
@@ -79,10 +79,12 @@ interface $RefParserOptions {
79
79
  /**
80
80
  * Callback invoked during dereferencing.
81
81
  *
82
- * @argument {string} path The path being dereferenced (ie. the `$ref` string).
83
- * @argument {JSONSchemaObject} object The JSON-Schema that the `$ref` resolved to.
82
+ * @argument {string} path - The path being dereferenced (ie. the `$ref` string)
83
+ * @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
84
+ * @argument {JSONSchemaObject} parent - The parent of the dereferenced object
85
+ * @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
84
86
  */
85
- onDereference?(path: string, value: JSONSchemaObject): void;
87
+ onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
86
88
 
87
89
  /**
88
90
  * Whether a reference should resolve relative to its directory/path, or from the cwd
@@ -180,7 +182,8 @@ export type ParserOptions = DeepPartial<$RefParserOptions>;
180
182
  */
181
183
  function merge(target: any, source: any) {
182
184
  if (isMergeable(source)) {
183
- const keys = Object.keys(source);
185
+ // prevent prototype pollution
186
+ const keys = Object.keys(source).filter((key) => !["__proto__", "constructor", "prototype"].includes(key));
184
187
  for (let i = 0; i < keys.length; i++) {
185
188
  const key = keys[i];
186
189
  const sourceSetting = source[key];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.1.1",
3
+ "version": "11.2.0",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",
@@ -57,7 +57,7 @@
57
57
  "scripts": {
58
58
  "prepublishOnly": "yarn build",
59
59
  "lint": "eslint lib",
60
- "build": "rm -fr dist/* && tsc",
60
+ "build": "rimraf dist && tsc",
61
61
  "typecheck": "tsc --noEmit",
62
62
  "prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
63
63
  "test": "vitest --coverage",
@@ -67,33 +67,34 @@
67
67
  "test:watch": "vitest -w"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/eslint": "8.44.2",
71
- "@types/js-yaml": "^4.0.6",
72
- "@types/node": "^20.6.2",
73
- "@typescript-eslint/eslint-plugin": "^6.7.2",
74
- "@typescript-eslint/eslint-plugin-tslint": "^6.7.2",
75
- "@typescript-eslint/parser": "^6.7.2",
76
- "@vitest/coverage-v8": "^0.34.4",
70
+ "@types/eslint": "8.56.5",
71
+ "@types/js-yaml": "^4.0.9",
72
+ "@types/node": "^20.11.24",
73
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
74
+ "@typescript-eslint/eslint-plugin-tslint": "^7.0.2",
75
+ "@typescript-eslint/parser": "^7.1.1",
76
+ "@vitest/coverage-v8": "^1.3.1",
77
77
  "abortcontroller-polyfill": "^1.7.5",
78
78
  "cross-env": "^7.0.3",
79
- "eslint": "^8.49.0",
80
- "eslint-config-prettier": "^9.0.0",
79
+ "eslint": "^8.57.0",
80
+ "eslint-config-prettier": "^9.1.0",
81
81
  "eslint-config-standard": "^17.1.0",
82
- "eslint-plugin-import": "^2.28.1",
83
- "eslint-plugin-prettier": "^5.0.0",
82
+ "eslint-plugin-import": "^2.29.1",
83
+ "eslint-plugin-prettier": "^5.1.3",
84
84
  "eslint-plugin-promise": "^6.1.1",
85
- "eslint-plugin-unused-imports": "^3.0.0",
86
- "jsdom": "^22.1.0",
87
- "lint-staged": "^14.0.1",
85
+ "eslint-plugin-unused-imports": "^3.1.0",
86
+ "jsdom": "^24.0.0",
87
+ "lint-staged": "^15.2.2",
88
88
  "node-fetch": "^3.3.2",
89
- "prettier": "^3.0.3",
90
- "typescript": "^5.2.2",
91
- "vitest": "^0.34.4"
89
+ "prettier": "^3.2.5",
90
+ "rimraf": "^5.0.5",
91
+ "typescript": "^5.3.3",
92
+ "vitest": "^1.3.1"
92
93
  },
93
94
  "dependencies": {
94
95
  "@jsdevtools/ono": "^7.1.3",
95
- "@types/json-schema": "^7.0.13",
96
- "@types/lodash.clonedeep": "^4.5.7",
96
+ "@types/json-schema": "^7.0.15",
97
+ "@types/lodash.clonedeep": "^4.5.9",
97
98
  "js-yaml": "^4.1.0",
98
99
  "lodash.clonedeep": "^4.5.0"
99
100
  },
@@ -107,5 +108,6 @@
107
108
  "@semantic-release/npm",
108
109
  "@semantic-release/github"
109
110
  ]
110
- }
111
+ },
112
+ "packageManager": "yarn@4.1.1"
111
113
  }