@hey-api/json-schema-ref-parser 1.2.3 → 1.3.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.
- package/README.md +9 -84
- package/dist/index.d.mts +629 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1887 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -78
- package/src/__tests__/bundle.test.ts +59 -0
- package/src/__tests__/index.test.ts +43 -0
- package/src/__tests__/pointer.test.ts +34 -0
- package/src/__tests__/utils.ts +3 -0
- package/{lib → src}/bundle.ts +143 -229
- package/{lib → src}/dereference.ts +20 -43
- package/{lib → src}/index.ts +103 -125
- package/{lib → src}/options.ts +13 -9
- package/{lib → src}/parse.ts +19 -15
- package/src/parsers/binary.ts +13 -0
- package/{lib → src}/parsers/json.ts +5 -6
- package/src/parsers/text.ts +21 -0
- package/{lib → src}/parsers/yaml.ts +9 -9
- package/{lib → src}/pointer.ts +42 -23
- package/{lib → src}/ref.ts +25 -21
- package/{lib → src}/refs.ts +23 -26
- package/{lib → src}/resolve-external.ts +91 -60
- package/{lib → src}/resolvers/file.ts +7 -10
- package/{lib → src}/resolvers/url.ts +12 -8
- package/{lib → src}/types/index.ts +9 -2
- package/src/util/convert-path-to-posix.ts +8 -0
- package/{lib → src}/util/errors.ts +38 -36
- package/{lib → src}/util/is-windows.ts +1 -1
- package/{lib → src}/util/plugins.ts +7 -8
- package/{lib → src}/util/url.ts +41 -42
- package/dist/lib/__tests__/bundle.test.d.ts +0 -1
- package/dist/lib/__tests__/bundle.test.js +0 -50
- package/dist/lib/__tests__/index.test.d.ts +0 -1
- package/dist/lib/__tests__/index.test.js +0 -43
- package/dist/lib/__tests__/pointer.test.d.ts +0 -1
- package/dist/lib/__tests__/pointer.test.js +0 -27
- package/dist/lib/bundle.d.ts +0 -26
- package/dist/lib/bundle.js +0 -600
- package/dist/lib/dereference.d.ts +0 -11
- package/dist/lib/dereference.js +0 -226
- package/dist/lib/index.d.ts +0 -92
- package/dist/lib/index.js +0 -525
- package/dist/lib/options.d.ts +0 -61
- package/dist/lib/options.js +0 -45
- package/dist/lib/parse.d.ts +0 -13
- package/dist/lib/parse.js +0 -87
- package/dist/lib/parsers/binary.d.ts +0 -2
- package/dist/lib/parsers/binary.js +0 -12
- package/dist/lib/parsers/json.d.ts +0 -2
- package/dist/lib/parsers/json.js +0 -38
- package/dist/lib/parsers/text.d.ts +0 -2
- package/dist/lib/parsers/text.js +0 -18
- package/dist/lib/parsers/yaml.d.ts +0 -2
- package/dist/lib/parsers/yaml.js +0 -28
- package/dist/lib/pointer.d.ts +0 -88
- package/dist/lib/pointer.js +0 -297
- package/dist/lib/ref.d.ts +0 -180
- package/dist/lib/ref.js +0 -226
- package/dist/lib/refs.d.ts +0 -127
- package/dist/lib/refs.js +0 -232
- package/dist/lib/resolve-external.d.ts +0 -13
- package/dist/lib/resolve-external.js +0 -151
- package/dist/lib/resolvers/file.d.ts +0 -6
- package/dist/lib/resolvers/file.js +0 -61
- package/dist/lib/resolvers/url.d.ts +0 -17
- package/dist/lib/resolvers/url.js +0 -62
- package/dist/lib/types/index.d.ts +0 -43
- package/dist/lib/types/index.js +0 -2
- package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
- package/dist/lib/util/convert-path-to-posix.js +0 -14
- package/dist/lib/util/errors.d.ts +0 -56
- package/dist/lib/util/errors.js +0 -112
- package/dist/lib/util/is-windows.d.ts +0 -1
- package/dist/lib/util/is-windows.js +0 -6
- package/dist/lib/util/plugins.d.ts +0 -16
- package/dist/lib/util/plugins.js +0 -45
- package/dist/lib/util/url.d.ts +0 -79
- package/dist/lib/util/url.js +0 -285
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -19
- package/lib/__tests__/bundle.test.ts +0 -52
- package/lib/__tests__/index.test.ts +0 -45
- package/lib/__tests__/pointer.test.ts +0 -26
- package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
- package/lib/__tests__/spec/multiple-refs.json +0 -34
- package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
- package/lib/__tests__/spec/path-parameter.json +0 -16
- package/lib/parsers/binary.ts +0 -13
- package/lib/parsers/text.ts +0 -21
- package/lib/util/convert-path-to-posix.ts +0 -11
- /package/{LICENSE → LICENSE.md} +0 -0
package/dist/lib/ref.d.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import Pointer from "./pointer.js";
|
|
2
|
-
import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
|
|
3
|
-
import type $Refs from "./refs.js";
|
|
4
|
-
import type { ParserOptions } from "./options.js";
|
|
5
|
-
import type { JSONSchema } from "./types";
|
|
6
|
-
export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
|
|
7
|
-
/**
|
|
8
|
-
* This class represents a single JSON reference and its resolved value.
|
|
9
|
-
*
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
12
|
-
declare class $Ref<S extends object = JSONSchema> {
|
|
13
|
-
/**
|
|
14
|
-
* The file path or URL of the referenced file.
|
|
15
|
-
* This path is relative to the path of the main JSON schema file.
|
|
16
|
-
*
|
|
17
|
-
* This path does NOT contain document fragments (JSON pointers). It always references an ENTIRE file.
|
|
18
|
-
* Use methods such as {@link $Ref#get}, {@link $Ref#resolve}, and {@link $Ref#exists} to get
|
|
19
|
-
* specific JSON pointers within the file.
|
|
20
|
-
*
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
path: undefined | string;
|
|
24
|
-
/**
|
|
25
|
-
* The resolved value of the JSON reference.
|
|
26
|
-
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
27
|
-
*
|
|
28
|
-
* @type {?*}
|
|
29
|
-
*/
|
|
30
|
-
value: any;
|
|
31
|
-
/**
|
|
32
|
-
* The {@link $Refs} object that contains this {@link $Ref} object.
|
|
33
|
-
*
|
|
34
|
-
* @type {$Refs}
|
|
35
|
-
*/
|
|
36
|
-
$refs: $Refs<S>;
|
|
37
|
-
/**
|
|
38
|
-
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
|
|
39
|
-
*/
|
|
40
|
-
pathType: string | unknown;
|
|
41
|
-
/**
|
|
42
|
-
* List of all errors. Undefined if no errors.
|
|
43
|
-
*/
|
|
44
|
-
errors: Array<$RefError>;
|
|
45
|
-
constructor($refs: $Refs<S>);
|
|
46
|
-
/**
|
|
47
|
-
* Pushes an error to errors array.
|
|
48
|
-
*
|
|
49
|
-
* @param err - The error to be pushed
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
addError(err: $RefError): void;
|
|
53
|
-
/**
|
|
54
|
-
* Determines whether the given JSON reference exists within this {@link $Ref#value}.
|
|
55
|
-
*
|
|
56
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
57
|
-
* @param options
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
exists(path: string, options?: ParserOptions): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
|
|
63
|
-
*
|
|
64
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
65
|
-
* @param options
|
|
66
|
-
* @returns - Returns the resolved value
|
|
67
|
-
*/
|
|
68
|
-
get(path: string, options?: ParserOptions): any;
|
|
69
|
-
/**
|
|
70
|
-
* Resolves the given JSON reference within this {@link $Ref#value}.
|
|
71
|
-
*
|
|
72
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
73
|
-
* @param options
|
|
74
|
-
* @param friendlyPath - The original user-specified path (used for error messages)
|
|
75
|
-
* @param pathFromRoot - The path of `obj` from the schema root
|
|
76
|
-
* @returns
|
|
77
|
-
*/
|
|
78
|
-
resolve(path: string, options?: ParserOptions, friendlyPath?: string, pathFromRoot?: string): Pointer<S>;
|
|
79
|
-
/**
|
|
80
|
-
* Sets the value of a nested property within this {@link $Ref#value}.
|
|
81
|
-
* If the property, or any of its parents don't exist, they will be created.
|
|
82
|
-
*
|
|
83
|
-
* @param path - The full path of the property to set, optionally with a JSON pointer in the hash
|
|
84
|
-
* @param value - The value to assign
|
|
85
|
-
*/
|
|
86
|
-
set(path: string, value: any): void;
|
|
87
|
-
/**
|
|
88
|
-
* Determines whether the given value is a JSON reference.
|
|
89
|
-
*
|
|
90
|
-
* @param value - The value to inspect
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
static is$Ref(value: unknown): value is {
|
|
94
|
-
$ref: string;
|
|
95
|
-
length?: number;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Determines whether the given value is an external JSON reference.
|
|
99
|
-
*
|
|
100
|
-
* @param value - The value to inspect
|
|
101
|
-
* @returns
|
|
102
|
-
*/
|
|
103
|
-
static isExternal$Ref(value: unknown): boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Determines whether the given value is a JSON reference, and whether it is allowed by the options.
|
|
106
|
-
*
|
|
107
|
-
* @param value - The value to inspect
|
|
108
|
-
* @param options
|
|
109
|
-
* @returns
|
|
110
|
-
*/
|
|
111
|
-
static isAllowed$Ref(value: unknown): true | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Determines whether the given value is a JSON reference that "extends" its resolved value.
|
|
114
|
-
* That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
|
|
115
|
-
* an existing value, this $ref actually creates a NEW value that is a shallow copy of the resolved
|
|
116
|
-
* value, plus the extra properties.
|
|
117
|
-
*
|
|
118
|
-
* @example: {
|
|
119
|
-
person: {
|
|
120
|
-
properties: {
|
|
121
|
-
firstName: { type: string }
|
|
122
|
-
lastName: { type: string }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
employee: {
|
|
126
|
-
properties: {
|
|
127
|
-
$ref: #/person/properties
|
|
128
|
-
salary: { type: number }
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
* In this example, "employee" is an extended $ref, since it extends "person" with an additional
|
|
133
|
-
* property (salary). The result is a NEW value that looks like this:
|
|
134
|
-
*
|
|
135
|
-
* {
|
|
136
|
-
* properties: {
|
|
137
|
-
* firstName: { type: string }
|
|
138
|
-
* lastName: { type: string }
|
|
139
|
-
* salary: { type: number }
|
|
140
|
-
* }
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
|
-
* @param value - The value to inspect
|
|
144
|
-
* @returns
|
|
145
|
-
*/
|
|
146
|
-
static isExtended$Ref(value: unknown): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* Returns the resolved value of a JSON Reference.
|
|
149
|
-
* If necessary, the resolved value is merged with the JSON Reference to create a new object
|
|
150
|
-
*
|
|
151
|
-
* @example: {
|
|
152
|
-
person: {
|
|
153
|
-
properties: {
|
|
154
|
-
firstName: { type: string }
|
|
155
|
-
lastName: { type: string }
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
employee: {
|
|
159
|
-
properties: {
|
|
160
|
-
$ref: #/person/properties
|
|
161
|
-
salary: { type: number }
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} When "person" and "employee" are merged, you end up with the following object:
|
|
165
|
-
*
|
|
166
|
-
* {
|
|
167
|
-
* properties: {
|
|
168
|
-
* firstName: { type: string }
|
|
169
|
-
* lastName: { type: string }
|
|
170
|
-
* salary: { type: number }
|
|
171
|
-
* }
|
|
172
|
-
* }
|
|
173
|
-
*
|
|
174
|
-
* @param $ref - The JSON reference object (the one with the "$ref" property)
|
|
175
|
-
* @param resolvedValue - The resolved value, which can be any type
|
|
176
|
-
* @returns - Returns the dereferenced value
|
|
177
|
-
*/
|
|
178
|
-
static dereference<S extends object = JSONSchema>($ref: $Ref<S>, resolvedValue: S): S;
|
|
179
|
-
}
|
|
180
|
-
export default $Ref;
|
package/dist/lib/ref.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const pointer_js_1 = __importDefault(require("./pointer.js"));
|
|
7
|
-
const errors_js_1 = require("./util/errors.js");
|
|
8
|
-
/**
|
|
9
|
-
* This class represents a single JSON reference and its resolved value.
|
|
10
|
-
*
|
|
11
|
-
* @class
|
|
12
|
-
*/
|
|
13
|
-
class $Ref {
|
|
14
|
-
constructor($refs) {
|
|
15
|
-
/**
|
|
16
|
-
* List of all errors. Undefined if no errors.
|
|
17
|
-
*/
|
|
18
|
-
this.errors = [];
|
|
19
|
-
this.$refs = $refs;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Pushes an error to errors array.
|
|
23
|
-
*
|
|
24
|
-
* @param err - The error to be pushed
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
addError(err) {
|
|
28
|
-
if (this.errors === undefined) {
|
|
29
|
-
this.errors = [];
|
|
30
|
-
}
|
|
31
|
-
const existingErrors = this.errors.map(({ footprint }) => footprint);
|
|
32
|
-
// the path has been almost certainly set at this point,
|
|
33
|
-
// but just in case something went wrong, normalizeError injects path if necessary
|
|
34
|
-
// moreover, certain errors might point at the same spot, so filter them out to reduce noise
|
|
35
|
-
if ("errors" in err && Array.isArray(err.errors)) {
|
|
36
|
-
this.errors.push(...err.errors.map(errors_js_1.normalizeError).filter(({ footprint }) => !existingErrors.includes(footprint)));
|
|
37
|
-
}
|
|
38
|
-
else if (!("footprint" in err) || !existingErrors.includes(err.footprint)) {
|
|
39
|
-
this.errors.push((0, errors_js_1.normalizeError)(err));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Determines whether the given JSON reference exists within this {@link $Ref#value}.
|
|
44
|
-
*
|
|
45
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
46
|
-
* @param options
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
exists(path, options) {
|
|
50
|
-
try {
|
|
51
|
-
this.resolve(path, options);
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
|
|
60
|
-
*
|
|
61
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
62
|
-
* @param options
|
|
63
|
-
* @returns - Returns the resolved value
|
|
64
|
-
*/
|
|
65
|
-
get(path, options) {
|
|
66
|
-
return this.resolve(path, options)?.value;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Resolves the given JSON reference within this {@link $Ref#value}.
|
|
70
|
-
*
|
|
71
|
-
* @param path - The full path being resolved, optionally with a JSON pointer in the hash
|
|
72
|
-
* @param options
|
|
73
|
-
* @param friendlyPath - The original user-specified path (used for error messages)
|
|
74
|
-
* @param pathFromRoot - The path of `obj` from the schema root
|
|
75
|
-
* @returns
|
|
76
|
-
*/
|
|
77
|
-
resolve(path, options, friendlyPath, pathFromRoot) {
|
|
78
|
-
const pointer = new pointer_js_1.default(this, path, friendlyPath);
|
|
79
|
-
return pointer.resolve(this.value, options, pathFromRoot);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Sets the value of a nested property within this {@link $Ref#value}.
|
|
83
|
-
* If the property, or any of its parents don't exist, they will be created.
|
|
84
|
-
*
|
|
85
|
-
* @param path - The full path of the property to set, optionally with a JSON pointer in the hash
|
|
86
|
-
* @param value - The value to assign
|
|
87
|
-
*/
|
|
88
|
-
set(path, value) {
|
|
89
|
-
const pointer = new pointer_js_1.default(this, path);
|
|
90
|
-
this.value = pointer.set(this.value, value);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Determines whether the given value is a JSON reference.
|
|
94
|
-
*
|
|
95
|
-
* @param value - The value to inspect
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
static is$Ref(value) {
|
|
99
|
-
return (Boolean(value) &&
|
|
100
|
-
typeof value === "object" &&
|
|
101
|
-
value !== null &&
|
|
102
|
-
"$ref" in value &&
|
|
103
|
-
typeof value.$ref === "string" &&
|
|
104
|
-
value.$ref.length > 0);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Determines whether the given value is an external JSON reference.
|
|
108
|
-
*
|
|
109
|
-
* @param value - The value to inspect
|
|
110
|
-
* @returns
|
|
111
|
-
*/
|
|
112
|
-
static isExternal$Ref(value) {
|
|
113
|
-
return $Ref.is$Ref(value) && value.$ref[0] !== "#";
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Determines whether the given value is a JSON reference, and whether it is allowed by the options.
|
|
117
|
-
*
|
|
118
|
-
* @param value - The value to inspect
|
|
119
|
-
* @param options
|
|
120
|
-
* @returns
|
|
121
|
-
*/
|
|
122
|
-
static isAllowed$Ref(value) {
|
|
123
|
-
if (this.is$Ref(value)) {
|
|
124
|
-
if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") {
|
|
125
|
-
// It's a JSON Pointer reference, which is always allowed
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
else if (value.$ref[0] !== "#") {
|
|
129
|
-
// It's an external reference, which is allowed by the options
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Determines whether the given value is a JSON reference that "extends" its resolved value.
|
|
137
|
-
* That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
|
|
138
|
-
* an existing value, this $ref actually creates a NEW value that is a shallow copy of the resolved
|
|
139
|
-
* value, plus the extra properties.
|
|
140
|
-
*
|
|
141
|
-
* @example: {
|
|
142
|
-
person: {
|
|
143
|
-
properties: {
|
|
144
|
-
firstName: { type: string }
|
|
145
|
-
lastName: { type: string }
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
employee: {
|
|
149
|
-
properties: {
|
|
150
|
-
$ref: #/person/properties
|
|
151
|
-
salary: { type: number }
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
* In this example, "employee" is an extended $ref, since it extends "person" with an additional
|
|
156
|
-
* property (salary). The result is a NEW value that looks like this:
|
|
157
|
-
*
|
|
158
|
-
* {
|
|
159
|
-
* properties: {
|
|
160
|
-
* firstName: { type: string }
|
|
161
|
-
* lastName: { type: string }
|
|
162
|
-
* salary: { type: number }
|
|
163
|
-
* }
|
|
164
|
-
* }
|
|
165
|
-
*
|
|
166
|
-
* @param value - The value to inspect
|
|
167
|
-
* @returns
|
|
168
|
-
*/
|
|
169
|
-
static isExtended$Ref(value) {
|
|
170
|
-
return $Ref.is$Ref(value) && Object.keys(value).length > 1;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Returns the resolved value of a JSON Reference.
|
|
174
|
-
* If necessary, the resolved value is merged with the JSON Reference to create a new object
|
|
175
|
-
*
|
|
176
|
-
* @example: {
|
|
177
|
-
person: {
|
|
178
|
-
properties: {
|
|
179
|
-
firstName: { type: string }
|
|
180
|
-
lastName: { type: string }
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
employee: {
|
|
184
|
-
properties: {
|
|
185
|
-
$ref: #/person/properties
|
|
186
|
-
salary: { type: number }
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} When "person" and "employee" are merged, you end up with the following object:
|
|
190
|
-
*
|
|
191
|
-
* {
|
|
192
|
-
* properties: {
|
|
193
|
-
* firstName: { type: string }
|
|
194
|
-
* lastName: { type: string }
|
|
195
|
-
* salary: { type: number }
|
|
196
|
-
* }
|
|
197
|
-
* }
|
|
198
|
-
*
|
|
199
|
-
* @param $ref - The JSON reference object (the one with the "$ref" property)
|
|
200
|
-
* @param resolvedValue - The resolved value, which can be any type
|
|
201
|
-
* @returns - Returns the dereferenced value
|
|
202
|
-
*/
|
|
203
|
-
static dereference($ref, resolvedValue) {
|
|
204
|
-
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {
|
|
205
|
-
const merged = {};
|
|
206
|
-
for (const key of Object.keys($ref)) {
|
|
207
|
-
if (key !== "$ref") {
|
|
208
|
-
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
209
|
-
merged[key] = $ref[key];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
for (const key of Object.keys(resolvedValue)) {
|
|
213
|
-
if (!(key in merged)) {
|
|
214
|
-
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
215
|
-
merged[key] = resolvedValue[key];
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return merged;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// Completely replace the original reference with the resolved value
|
|
222
|
-
return resolvedValue;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.default = $Ref;
|
package/dist/lib/refs.d.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import $Ref from "./ref.js";
|
|
2
|
-
import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
|
|
3
|
-
import type { ParserOptions } from "./options.js";
|
|
4
|
-
import type { JSONSchema } from "./types";
|
|
5
|
-
interface $RefsMap<S extends object = JSONSchema> {
|
|
6
|
-
[url: string]: $Ref<S>;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects.
|
|
10
|
-
*
|
|
11
|
-
* This object is a map of JSON References and their resolved values. It also has several convenient helper methods that make it easy for you to navigate and manipulate the JSON References.
|
|
12
|
-
*
|
|
13
|
-
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html
|
|
14
|
-
*/
|
|
15
|
-
export default class $Refs<S extends object = JSONSchema> {
|
|
16
|
-
/**
|
|
17
|
-
* This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.
|
|
18
|
-
*
|
|
19
|
-
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#circular
|
|
20
|
-
*/
|
|
21
|
-
circular: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Returns the paths/URLs of all the files in your schema (including the main schema file).
|
|
24
|
-
*
|
|
25
|
-
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#pathstypes
|
|
26
|
-
*
|
|
27
|
-
* @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
|
|
28
|
-
*/
|
|
29
|
-
paths(...types: (string | string[])[]): string[];
|
|
30
|
-
/**
|
|
31
|
-
* Returns a map of paths/URLs and their correspond values.
|
|
32
|
-
*
|
|
33
|
-
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#valuestypes
|
|
34
|
-
*
|
|
35
|
-
* @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
|
|
36
|
-
*/
|
|
37
|
-
values(...types: (string | string[])[]): S;
|
|
38
|
-
/**
|
|
39
|
-
* Returns `true` if the given path exists in the schema; otherwise, returns `false`
|
|
40
|
-
*
|
|
41
|
-
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#existsref
|
|
42
|
-
*
|
|
43
|
-
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* Determines whether the given JSON reference exists.
|
|
47
|
-
*
|
|
48
|
-
* @param path - The path being resolved, optionally with a JSON pointer in the hash
|
|
49
|
-
* @param [options]
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
exists(path: string, options: any): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Resolves the given JSON reference and returns the resolved value.
|
|
55
|
-
*
|
|
56
|
-
* @param path - The path being resolved, with a JSON pointer in the hash
|
|
57
|
-
* @param [options]
|
|
58
|
-
* @returns - Returns the resolved value
|
|
59
|
-
*/
|
|
60
|
-
get(path: string, options?: ParserOptions): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
|
|
61
|
-
/**
|
|
62
|
-
* 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.
|
|
63
|
-
*
|
|
64
|
-
* @param path The JSON Reference path, optionally with a JSON Pointer in the hash
|
|
65
|
-
* @param value The value to assign. Can be anything (object, string, number, etc.)
|
|
66
|
-
*/
|
|
67
|
-
set(path: string, value: JSONSchema4Type | JSONSchema6Type | JSONSchema7Type): void;
|
|
68
|
-
/**
|
|
69
|
-
* Returns the specified {@link $Ref} object, or undefined.
|
|
70
|
-
*
|
|
71
|
-
* @param path - The path being resolved, optionally with a JSON pointer in the hash
|
|
72
|
-
* @returns
|
|
73
|
-
* @protected
|
|
74
|
-
*/
|
|
75
|
-
_get$Ref(path: string): $Ref<S>;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a new {@link $Ref} object and adds it to this {@link $Refs} object.
|
|
78
|
-
*
|
|
79
|
-
* @param path - The file path or URL of the referenced file
|
|
80
|
-
*/
|
|
81
|
-
_add(path: string): $Ref<S>;
|
|
82
|
-
/**
|
|
83
|
-
* Resolves the given JSON reference.
|
|
84
|
-
*
|
|
85
|
-
* @param path - The path being resolved, optionally with a JSON pointer in the hash
|
|
86
|
-
* @param pathFromRoot - The path of `obj` from the schema root
|
|
87
|
-
* @param [options]
|
|
88
|
-
* @returns
|
|
89
|
-
* @protected
|
|
90
|
-
*/
|
|
91
|
-
_resolve(path: string, pathFromRoot: string, options?: ParserOptions): import("./pointer.js").default<S>;
|
|
92
|
-
/**
|
|
93
|
-
* A map of paths/urls to {@link $Ref} objects
|
|
94
|
-
*
|
|
95
|
-
* @type {object}
|
|
96
|
-
* @protected
|
|
97
|
-
*/
|
|
98
|
-
_$refs: $RefsMap<S>;
|
|
99
|
-
/**
|
|
100
|
-
* The {@link $Ref} object that is the root of the JSON schema.
|
|
101
|
-
*
|
|
102
|
-
* @type {$Ref}
|
|
103
|
-
* @protected
|
|
104
|
-
*/
|
|
105
|
-
_root$Ref: $Ref<S>;
|
|
106
|
-
constructor();
|
|
107
|
-
/**
|
|
108
|
-
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
|
109
|
-
* including the schema itself.
|
|
110
|
-
*
|
|
111
|
-
* @param [types] - Only return paths of the given types ("file", "http", etc.)
|
|
112
|
-
* @returns
|
|
113
|
-
*/
|
|
114
|
-
/**
|
|
115
|
-
* Returns the map of JSON references and their resolved values.
|
|
116
|
-
*
|
|
117
|
-
* @param [types] - Only return references of the given types ("file", "http", etc.)
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
/**
|
|
121
|
-
* Returns a POJO (plain old JavaScript object) for serialization as JSON.
|
|
122
|
-
*
|
|
123
|
-
* @returns {object}
|
|
124
|
-
*/
|
|
125
|
-
toJSON: (...types: (string | string[])[]) => S;
|
|
126
|
-
}
|
|
127
|
-
export {};
|