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

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
  }
@@ -5,6 +5,6 @@ export default normalizeArgs;
5
5
  declare function normalizeArgs(_args: Partial<IArguments>): {
6
6
  path: string;
7
7
  schema: any;
8
- options: import("./options.js").default;
8
+ options: any;
9
9
  callback: any;
10
10
  };
@@ -32,7 +32,12 @@ function normalizeArgs(_args) {
32
32
  schema = args[0];
33
33
  options = args[1];
34
34
  }
35
- options = (0, options_js_1.getNewOptions)(options);
35
+ try {
36
+ options = (0, options_js_1.getNewOptions)(options);
37
+ }
38
+ catch (e) {
39
+ console.log(e);
40
+ }
36
41
  return {
37
42
  path,
38
43
  schema,
@@ -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
  *
@@ -10,7 +10,6 @@ const text_js_1 = __importDefault(require("./parsers/text.js"));
10
10
  const binary_js_1 = __importDefault(require("./parsers/binary.js"));
11
11
  const file_js_1 = __importDefault(require("./resolvers/file.js"));
12
12
  const http_js_1 = __importDefault(require("./resolvers/http.js"));
13
- const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
14
13
  const getDefaults = () => {
15
14
  const defaults = {
16
15
  /**
@@ -20,10 +19,10 @@ const getDefaults = () => {
20
19
  * your own implementation, or disable any parser by setting it to false.
21
20
  */
22
21
  parse: {
23
- json: json_js_1.default,
24
- yaml: yaml_js_1.default,
25
- text: text_js_1.default,
26
- binary: binary_js_1.default,
22
+ json: { ...json_js_1.default },
23
+ yaml: { ...yaml_js_1.default },
24
+ text: { ...text_js_1.default },
25
+ binary: { ...binary_js_1.default },
27
26
  },
28
27
  /**
29
28
  * Determines how JSON References will be resolved.
@@ -32,8 +31,8 @@ const getDefaults = () => {
32
31
  * your own implementation, or disable any resolver by setting it to false.
33
32
  */
34
33
  resolve: {
35
- file: file_js_1.default,
36
- http: http_js_1.default,
34
+ file: { ...file_js_1.default },
35
+ http: { ...http_js_1.default },
37
36
  /**
38
37
  * Determines whether external $ref pointers will be resolved.
39
38
  * If this option is disabled, then none of above resolvers will be called.
@@ -72,7 +71,7 @@ const getDefaults = () => {
72
71
  referenceResolution: "relative",
73
72
  },
74
73
  };
75
- return (0, lodash_clonedeep_1.default)(defaults);
74
+ return defaults;
76
75
  };
77
76
  const getNewOptions = (options) => {
78
77
  const newOptions = getDefaults();
@@ -91,7 +90,8 @@ exports.getNewOptions = getNewOptions;
91
90
  */
92
91
  function merge(target, source) {
93
92
  if (isMergeable(source)) {
94
- const keys = Object.keys(source);
93
+ // prevent prototype pollution
94
+ const keys = Object.keys(source).filter((key) => !["__proto__", "constructor", "prototype"].includes(key));
95
95
  for (let i = 0; i < keys.length; i++) {
96
96
  const key = keys[i];
97
97
  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
  *
@@ -32,7 +32,6 @@ exports.default = {
32
32
  * @returns
33
33
  */
34
34
  async parse(file) {
35
- // eslint-disable-line require-await
36
35
  let data = file.data;
37
36
  if (Buffer.isBuffer(data)) {
38
37
  data = data.toString();
@@ -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.
@@ -9,7 +9,6 @@ exports.default = (0, config_1.defineConfig)({
9
9
  exclude: ["**/__IGNORED__/**"],
10
10
  watch: false,
11
11
  globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined,
12
- setupFiles: isBrowser ? ["./test/fixtures/polyfill.ts"] : undefined,
13
12
  testTimeout: 5000,
14
13
  globals: true,
15
14
  passWithNoTests: true,
@@ -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 {
@@ -33,7 +33,11 @@ function normalizeArgs(_args: Partial<IArguments>) {
33
33
  options = args[1];
34
34
  }
35
35
 
36
- options = getNewOptions(options);
36
+ try {
37
+ options = getNewOptions(options);
38
+ } catch (e) {
39
+ console.log(e);
40
+ }
37
41
 
38
42
  return {
39
43
  path,
package/lib/options.ts CHANGED
@@ -4,7 +4,6 @@ import textParser from "./parsers/text.js";
4
4
  import binaryParser from "./parsers/binary.js";
5
5
  import fileResolver from "./resolvers/file.js";
6
6
  import httpResolver from "./resolvers/http.js";
7
- import cloneDeep from "lodash.clonedeep";
8
7
 
9
8
  import type { HTTPResolverOptions, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
10
9
 
@@ -79,10 +78,12 @@ interface $RefParserOptions {
79
78
  /**
80
79
  * Callback invoked during dereferencing.
81
80
  *
82
- * @argument {string} path The path being dereferenced (ie. the `$ref` string).
83
- * @argument {JSONSchemaObject} object The JSON-Schema that the `$ref` resolved to.
81
+ * @argument {string} path - The path being dereferenced (ie. the `$ref` string)
82
+ * @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
83
+ * @argument {JSONSchemaObject} parent - The parent of the dereferenced object
84
+ * @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
84
85
  */
85
- onDereference?(path: string, value: JSONSchemaObject): void;
86
+ onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
86
87
 
87
88
  /**
88
89
  * Whether a reference should resolve relative to its directory/path, or from the cwd
@@ -102,10 +103,10 @@ const getDefaults = () => {
102
103
  * your own implementation, or disable any parser by setting it to false.
103
104
  */
104
105
  parse: {
105
- json: jsonParser,
106
- yaml: yamlParser,
107
- text: textParser,
108
- binary: binaryParser,
106
+ json: { ...jsonParser },
107
+ yaml: { ...yamlParser },
108
+ text: { ...textParser },
109
+ binary: { ...binaryParser },
109
110
  },
110
111
 
111
112
  /**
@@ -115,8 +116,8 @@ const getDefaults = () => {
115
116
  * your own implementation, or disable any resolver by setting it to false.
116
117
  */
117
118
  resolve: {
118
- file: fileResolver,
119
- http: httpResolver,
119
+ file: { ...fileResolver },
120
+ http: { ...httpResolver },
120
121
 
121
122
  /**
122
123
  * Determines whether external $ref pointers will be resolved.
@@ -159,7 +160,7 @@ const getDefaults = () => {
159
160
  referenceResolution: "relative",
160
161
  },
161
162
  } as $RefParserOptions;
162
- return cloneDeep(defaults);
163
+ return defaults;
163
164
  };
164
165
 
165
166
  export const getNewOptions = (options: DeepPartial<$RefParserOptions>): $RefParserOptions => {
@@ -180,7 +181,8 @@ export type ParserOptions = DeepPartial<$RefParserOptions>;
180
181
  */
181
182
  function merge(target: any, source: any) {
182
183
  if (isMergeable(source)) {
183
- const keys = Object.keys(source);
184
+ // prevent prototype pollution
185
+ const keys = Object.keys(source).filter((key) => !["__proto__", "constructor", "prototype"].includes(key));
184
186
  for (let i = 0; i < keys.length; i++) {
185
187
  const key = keys[i];
186
188
  const sourceSetting = source[key];
@@ -33,7 +33,6 @@ export default {
33
33
  * @returns
34
34
  */
35
35
  async parse(file: FileInfo) {
36
- // eslint-disable-line require-await
37
36
  let data = file.data;
38
37
  if (Buffer.isBuffer(data)) {
39
38
  data = data.toString();
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.1",
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,35 +67,31 @@
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",
77
- "abortcontroller-polyfill": "^1.7.5",
70
+ "@types/eslint": "8.56.5",
71
+ "@types/js-yaml": "^4.0.9",
72
+ "@types/node": "^18.19.21",
73
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
74
+ "@typescript-eslint/parser": "^7.1.1",
75
+ "@vitest/coverage-v8": "^1.3.1",
78
76
  "cross-env": "^7.0.3",
79
- "eslint": "^8.49.0",
80
- "eslint-config-prettier": "^9.0.0",
77
+ "eslint": "^8.57.0",
78
+ "eslint-config-prettier": "^9.1.0",
81
79
  "eslint-config-standard": "^17.1.0",
82
- "eslint-plugin-import": "^2.28.1",
83
- "eslint-plugin-prettier": "^5.0.0",
80
+ "eslint-plugin-import": "^2.29.1",
81
+ "eslint-plugin-prettier": "^5.1.3",
84
82
  "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",
83
+ "eslint-plugin-unused-imports": "^3.1.0",
84
+ "jsdom": "^24.0.0",
88
85
  "node-fetch": "^3.3.2",
89
- "prettier": "^3.0.3",
90
- "typescript": "^5.2.2",
91
- "vitest": "^0.34.4"
86
+ "prettier": "^3.2.5",
87
+ "rimraf": "^5.0.5",
88
+ "typescript": "^5.3.3",
89
+ "vitest": "^1.3.1"
92
90
  },
93
91
  "dependencies": {
94
92
  "@jsdevtools/ono": "^7.1.3",
95
- "@types/json-schema": "^7.0.13",
96
- "@types/lodash.clonedeep": "^4.5.7",
97
- "js-yaml": "^4.1.0",
98
- "lodash.clonedeep": "^4.5.0"
93
+ "@types/json-schema": "^7.0.15",
94
+ "js-yaml": "^4.1.0"
99
95
  },
100
96
  "release": {
101
97
  "branches": [
@@ -107,5 +103,6 @@
107
103
  "@semantic-release/npm",
108
104
  "@semantic-release/github"
109
105
  ]
110
- }
106
+ },
107
+ "packageManager": "yarn@4.1.1"
111
108
  }