@apidevtools/json-schema-ref-parser 9.0.8 → 9.1.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.
@@ -41,8 +41,10 @@ function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferenced
41
41
  circular: false
42
42
  };
43
43
 
44
+ let isExcludedPath = options.dereference.excludedPathMatcher;
45
+
44
46
  if (options.dereference.circular === "ignore" || !processedObjects.has(obj)) {
45
- if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
47
+ if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
46
48
  parents.add(obj);
47
49
  processedObjects.add(obj);
48
50
 
@@ -55,6 +57,11 @@ function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferenced
55
57
  for (const key of Object.keys(obj)) {
56
58
  let keyPath = Pointer.join(path, key);
57
59
  let keyPathFromRoot = Pointer.join(pathFromRoot, key);
60
+
61
+ if (isExcludedPath(keyPathFromRoot)) {
62
+ continue;
63
+ }
64
+
58
65
  let value = obj[key];
59
66
  let circular = false;
60
67
 
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from "json-schema";
1
+ import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema";
2
2
 
3
3
  export = $RefParser;
4
4
 
@@ -173,7 +173,7 @@ declare class $RefParser {
173
173
  // eslint-disable-next-line no-redeclare
174
174
  declare namespace $RefParser {
175
175
 
176
- export type JSONSchema = JSONSchema4 | JSONSchema6;
176
+ export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
177
177
  export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any;
178
178
  export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
179
179
 
@@ -208,7 +208,7 @@ declare namespace $RefParser {
208
208
  file?: Partial<ResolverOptions> | boolean;
209
209
  http?: HTTPResolverOptions | boolean;
210
210
  } & {
211
- [key: string]: Partial<ResolverOptions> | boolean;
211
+ [key: string]: Partial<ResolverOptions> | HTTPResolverOptions | boolean | undefined;
212
212
  };
213
213
 
214
214
  /**
@@ -231,6 +231,13 @@ declare namespace $RefParser {
231
231
  * If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
232
232
  */
233
233
  circular?: boolean | "ignore";
234
+
235
+ /**
236
+ * A function, called for each path, which can return true to stop this path and all
237
+ * subpaths from being dereferenced further. This is useful in schemas where some
238
+ * subpaths contain literal $ref keys that should not be dereferenced.
239
+ */
240
+ excludedPathMatcher?(path: string): boolean;
234
241
  };
235
242
  }
236
243
 
@@ -284,7 +291,7 @@ declare namespace $RefParser {
284
291
  read(
285
292
  file: FileInfo,
286
293
  callback?: (error: Error | null, data: string | null) => any
287
- ): string | Buffer | Promise<string | Buffer>;
294
+ ): string | Buffer | JSONSchema | Promise<string | Buffer | JSONSchema>;
288
295
  }
289
296
 
290
297
  export interface ParserOptions {
@@ -395,7 +402,7 @@ declare namespace $RefParser {
395
402
  *
396
403
  * @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
397
404
  */
398
- public get($ref: string): JSONSchema4Type | JSONSchema6Type
405
+ public get($ref: string): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type
399
406
 
400
407
  /**
401
408
  * Sets the value at the given path in the schema. If the property, or any of its parents, don't exist, they will be created.
@@ -403,7 +410,7 @@ declare namespace $RefParser {
403
410
  * @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
404
411
  * @param value The value to assign. Can be anything (object, string, number, etc.)
405
412
  */
406
- public set($ref: string, value: JSONSchema4Type | JSONSchema6Type): void
413
+ public set($ref: string, value: JSONSchema4Type | JSONSchema6Type | JSONSchema7Type): void
407
414
  }
408
415
 
409
416
  export type JSONParserErrorType = "EUNKNOWN" | "EPARSER" | "EUNMATCHEDPARSER" | "ERESOLVER" | "EUNMATCHEDRESOLVER" | "EMISSINGPOINTER" | "EINVALIDPOINTER";
package/lib/options.js CHANGED
@@ -73,7 +73,16 @@ $RefParserOptions.defaults = {
73
73
  *
74
74
  * @type {boolean|string}
75
75
  */
76
- circular: true
76
+ circular: true,
77
+
78
+ /**
79
+ * A function, called for each path, which can return true to stop this path and all
80
+ * subpaths from being dereferenced further. This is useful in schemas where some
81
+ * subpaths contain literal $ref keys that should not be dereferenced.
82
+ *
83
+ * @type {function}
84
+ */
85
+ excludedPathMatcher: () => false
77
86
  },
78
87
  };
79
88
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { ParserError } = require("../util/errors");
4
4
  const yaml = require("js-yaml");
5
+ const { JSON_SCHEMA } = require("js-yaml");
5
6
 
6
7
  module.exports = {
7
8
  /**
@@ -45,7 +46,7 @@ module.exports = {
45
46
 
46
47
  if (typeof data === "string") {
47
48
  try {
48
- return yaml.safeLoad(data);
49
+ return yaml.load(data, { schema: JSON_SCHEMA });
49
50
  }
50
51
  catch (e) {
51
52
  throw new ParserError(e.message, file.url);
package/lib/pointer.js CHANGED
@@ -91,7 +91,7 @@ Pointer.prototype.resolve = function (obj, options, pathFromRoot) {
91
91
  let token = tokens[i];
92
92
  if (this.value[token] === undefined || this.value[token] === null) {
93
93
  this.value = null;
94
- throw new MissingPointerError(token, this.originalPath);
94
+ throw new MissingPointerError(token, decodeURI(this.originalPath));
95
95
  }
96
96
  else {
97
97
  this.value = this.value[token];
package/lib/ref.js CHANGED
@@ -135,7 +135,7 @@ $Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
135
135
  if (err instanceof InvalidPointerError) {
136
136
  // this is a special case - InvalidPointerError is thrown when dereferencing external file,
137
137
  // but the issue is caused by the source file that referenced the file that undergoes dereferencing
138
- err.source = stripHash(pathFromRoot);
138
+ err.source = decodeURI(stripHash(pathFromRoot));
139
139
  }
140
140
 
141
141
  this.addError(err);
@@ -120,7 +120,7 @@ async function resolve$Ref ($ref, path, $refs, options) {
120
120
  }
121
121
 
122
122
  if ($refs._$refs[withoutHash]) {
123
- err.source = url.stripHash(path);
123
+ err.source = decodeURI(url.stripHash(path));
124
124
  err.path = url.safePointerToPath(url.getHash(path));
125
125
  }
126
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "9.0.8",
3
+ "version": "9.1.0",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",
@@ -76,9 +76,13 @@
76
76
  "@jsdevtools/ono": "^7.1.3",
77
77
  "@types/json-schema": "^7.0.6",
78
78
  "call-me-maybe": "^1.0.1",
79
- "js-yaml": "^3.13.1"
79
+ "js-yaml": "^4.1.0"
80
80
  },
81
81
  "release": {
82
+ "branches": [
83
+ "main",
84
+ "v9"
85
+ ],
82
86
  "plugins": [
83
87
  "@semantic-release/commit-analyzer",
84
88
  "@semantic-release/release-notes-generator",
package/CHANGELOG.md DELETED
@@ -1,182 +0,0 @@
1
- Change Log
2
- ==========
3
-
4
- See [GitHub Releases](https://github.com/APIDevTools/json-schema-ref-parser/releases) for more information on newer releases.
5
-
6
- [v9.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v9.0.0) (2020-04-21)
7
- ----------------------------------------------------------------------------------------------------
8
-
9
- #### Breaking Changes
10
-
11
- - Removed the `YAML` export. We recommend using [`@stoplight/yaml`](https://www.npmjs.com/package/@stoplight/yaml) instead
12
-
13
-
14
- #### Other Changes
15
-
16
- - Added a new [`continueOnError` option](https://apitools.dev/json-schema-ref-parser/docs/options) that allows you to get all errors rather than just the first one
17
-
18
-
19
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v8.0.0...v9.0.0)
20
-
21
-
22
-
23
- [v8.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v8.0.0) (2020-03-13)
24
- ----------------------------------------------------------------------------------------------------
25
-
26
- - Moved JSON Schema $Ref Parser to the [@APIDevTools scope](https://www.npmjs.com/org/apidevtools) on NPM
27
-
28
- - The "json-schema-ref-parser" NPM package is now just a wrapper around the scoped "@apidevtools/json-schema-ref-parser" package
29
-
30
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v7.1.4...v8.0.0)
31
-
32
-
33
-
34
- [v7.1.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v7.1.0) (2019-06-21)
35
- ----------------------------------------------------------------------------------------------------
36
-
37
- - Merged [PR #124](https://github.com/APIDevTools/json-schema-ref-parser/pull/124/), which provides more context to [custom resolvers](https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html).
38
-
39
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v7.0.1...v7.1.0)
40
-
41
-
42
-
43
- [v7.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v7.0.0) (2019-06-11)
44
- ----------------------------------------------------------------------------------------------------
45
-
46
- - Dropped support for Node 6
47
-
48
- - Updated all code to ES6+ syntax (async/await, template literals, arrow functions, etc.)
49
-
50
- - No longer including a pre-built bundle in the package. such as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/), or [Browserify](http://browserify.org/) to include JSON Schema $Ref Parser in your app
51
-
52
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v6.1.0...v7.0.0)
53
-
54
-
55
-
56
- [v6.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v6.0.0) (2018-10-04)
57
- ----------------------------------------------------------------------------------------------------
58
-
59
- - Dropped support for [Bower](https://www.npmjs.com/package/bower), since it has been deprecated
60
-
61
- - Removed the [`debug`](https://npmjs.com/package/debug) dependency
62
-
63
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v5.1.0...v6.0.0)
64
-
65
-
66
-
67
- [v5.1.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v5.1.0) (2018-07-11)
68
- ----------------------------------------------------------------------------------------------------
69
-
70
- - Improved the logic of the [`bundle()` method](https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#bundleschema-options-callback) to produce shorter reference paths when possible. This is not a breaking change, since both the old reference paths and the new reference paths are valid. The new ones are just shorter. Big thanks to [@hipstersmoothie](https://github.com/hipstersmoothie) for [PR #68](https://github.com/APIDevTools/json-schema-ref-parser/pull/68), which helped a lot with this.
71
-
72
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v5.0.0...v5.1.0)
73
-
74
-
75
-
76
- [v5.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v5.0.0) (2018-03-18)
77
- ----------------------------------------------------------------------------------------------------
78
-
79
- This release contains two bug fixes related to file paths. They are _technically_ breaking changes &mdash; hence the major version bump &mdash; but they're both edge cases that probably won't affect most users.
80
-
81
- - Fixed a bug in the [`$refs.paths()`](docs/refs.md#pathstypes) and [`$refs.values()`](docs/refs.md#valuestypes) methods that caused the path of the root schema file to always be represented as a URL, rather than a filesystem path (see [this commit](https://github.com/APIDevTools/json-schema-ref-parser/commit/a95cf50fdf16c864cc1c18d2021d9ce3ec35f5de))
82
-
83
- - Merged [PR #75](https://github.com/APIDevTools/json-schema-ref-parser/pull/75), which resolves [issue #76](https://github.com/APIDevTools/swagger-parser/issues/76). Error messages no longer include the current working directory path when there is no file path.
84
-
85
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v4.1.1...v5.0.0)
86
-
87
-
88
-
89
- [v4.1.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v4.1.0) (2018-01-17)
90
- ----------------------------------------------------------------------------------------------------
91
-
92
- - Updated dependencies
93
-
94
- - Improved the `bundle()` algorithm to favor direct references rather than indirect references (see [PR #62](https://github.com/APIDevTools/json-schema-ref-parser/pull/62) for details). This will produce different bundled output than previous versions for some schemas. Both the old output and the new output are valid, but the new output is arguably better.
95
-
96
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v4.0.0...v4.1.0)
97
-
98
-
99
-
100
- [v4.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v4.0.0) (2017-10-13)
101
- ----------------------------------------------------------------------------------------------------
102
-
103
- #### Breaking Changes
104
-
105
- - To reduce the size of this library, it no longer includes polyfills for [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) and [TypedArrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), which are natively supported in the latest versions of Node and web browsers. If you need to support older browsers (such as IE9), then just use [this `Promise` polyfill](https://github.com/stefanpenner/es6-promise) and [this `TypedArray` polyfill](https://github.com/inexorabletash/polyfill/blob/master/typedarray.js).
106
-
107
- #### Minor Changes
108
-
109
- - Updated dependencies
110
-
111
- - [PR #53](https://github.com/APIDevTools/json-schema-ref-parser/pull/53) - Fixes [an edge-case bug](https://github.com/APIDevTools/json-schema-ref-parser/issues/52) with the `bundle()` method
112
-
113
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v3.3.0...v4.0.0)
114
-
115
-
116
-
117
- [v3.3.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v3.3.0) (2017-08-09)
118
- ----------------------------------------------------------------------------------------------------
119
-
120
- - Updated dependencies
121
-
122
- - [PR #30](https://github.com/APIDevTools/json-schema-ref-parser/pull/30) - Added a `browser` field to the `package.json` file to support bundlers such as Browserify, Rollup, and Webpack
123
-
124
- - [PR #45](https://github.com/APIDevTools/json-schema-ref-parser/pull/45) - Implemented a temporary workaround for [issue #42](https://github.com/APIDevTools/json-schema-ref-parser/issues/42). JSON Schema $Ref Parser does _not_ currently support [named internal references](http://json-schema.org/latest/json-schema-core.html#id-keyword), but support will be added in the next major release.
125
-
126
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v3.0.0...v3.3.0)
127
-
128
-
129
-
130
- [v3.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v3.0.0) (2016-04-03)
131
- ----------------------------------------------------------------------------------------------------
132
-
133
- #### Plug-ins !!!
134
- That's the major new feature in this version. Originally requested in [PR #8](https://github.com/APIDevTools/json-schema-ref-parser/pull/8), and refined a few times over the past few months, the plug-in API is now finalized and ready to use. You can now define your own [resolvers](https://github.com/APIDevTools/json-schema-ref-parser/blob/v3.0.0/docs/plugins/resolvers.md) and [parsers](https://github.com/APIDevTools/json-schema-ref-parser/blob/v3.0.0/docs/plugins/parsers.md).
135
-
136
- #### Breaking Changes
137
- The available [options have changed](https://github.com/APIDevTools/json-schema-ref-parser/blob/v3.0.0/docs/options.md), mostly due to the new plug-in API. There's not a one-to-one mapping of old options to new options, so you'll have to read the docs and determine which options you need to set. If any. The out-of-the-box configuration works for most people.
138
-
139
- All of the [caching options have been removed](https://github.com/APIDevTools/json-schema-ref-parser/commit/1f4260184bfd370e9cd385b523fb08c098fac6db). Instead, all files are now cached, and the entire cache is reset for each new parse operation. Caching options may come back in a future release, if there is enough demand for it. If you used the old caching options, please open an issue and explain your use-case and requirements. I need a better understanding of what caching functionality is actually needed by users.
140
-
141
- #### Bug Fixes
142
- Lots of little bug fixes. The only major bug fix is to [support root-level `$ref`s](https://github.com/APIDevTools/json-schema-ref-parser/issues/16)
143
-
144
-
145
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v2.2.0...v3.0.0)
146
-
147
-
148
-
149
- [v2.2.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v2.2.0) (2016-01-03)
150
- ----------------------------------------------------------------------------------------------------
151
-
152
- This version includes a **complete rewrite** of the [`bundle` method](https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#bundleschema-options-callback) method, mostly to fix [this bug](https://github.com/APIDevTools/swagger-parser/issues/16), but also to address a few [edge-cases](https://github.com/APIDevTools/json-schema-ref-parser/commit/ca9b322879519e4bcb2dcf6e63f08ac254b90868) that weren't handled before. As a side-effect of this rewrite, there was also some pretty significant refactoring and code-cleanup done throughout the codebase.
153
-
154
- Despite the significant code changes, there were no changes to any public-facing APIs, and [all tests are passing](https://apitools.dev/json-schema-ref-parser/test/) as expected.
155
-
156
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v2.1.0...v2.2.0)
157
-
158
-
159
-
160
- [v2.1.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v2.1.0) (2015-12-31)
161
- ----------------------------------------------------------------------------------------------------
162
-
163
- JSON Schema $Ref Parser now automatically follows HTTP redirects. This is especially great for servers that automatically "ugrade" your connection from HTTP to HTTPS via a 301 redirect. Now that won't break your code.
164
-
165
- There are a few [new options](https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/options.md) that allow you to set the number of redirects (default is 5) and a few other HTTP request properties.
166
-
167
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v2.0.0...v2.1.0)
168
-
169
-
170
-
171
- [v2.0.0](https://github.com/APIDevTools/json-schema-ref-parser/tree/v2.0.0) (2015-12-31)
172
- ----------------------------------------------------------------------------------------------------
173
-
174
- Bumping the major version number because [this change](https://github.com/APIDevTools/json-schema-ref-parser/pull/5) technically breaks backward-compatibility &mdash; although I doubt it will actually affect many people. Basically, if you're using JSON Schema $Ref Parser to download files from a CORS-enabled server that requires authentication, then you'll need to set the `http.withCredentials` option to `true`.
175
-
176
- ```javascript
177
- $RefParser.dereference('http://some.server.com/file.json', {
178
- http: { withCredentials: true }
179
- });
180
- ```
181
-
182
- [Full Changelog](https://github.com/APIDevTools/json-schema-ref-parser/compare/v1.4.1...v2.0.0)