@fumadocs/api-docs 0.0.2 → 0.0.4
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/css/generated/shared.css +1 -1
- package/dist/components/schema/client.d.ts +16 -1
- package/dist/components/schema/client.js +17 -12
- package/dist/components/schema/index.d.ts +13 -20
- package/dist/components/schema/index.js +82 -60
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +2 -2
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +1 -1
- package/dist/ref-parser/bundle.d.ts +10 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/bundle.js +76 -6
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/normalize-args.js +1 -1
- package/dist/ref-parser/options.d.ts +28 -0
- package/dist/ref-parser/options.js +27 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parse.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parsers/json.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parsers/yaml.js +6 -12
- package/dist/ref-parser/pointer.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/pointer.js +24 -53
- package/dist/ref-parser/ref.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/ref.js +6 -48
- package/dist/ref-parser/refs.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/refs.js +4 -41
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/resolve-external.js +3 -3
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/resolvers/file.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/types/index.d.ts +8 -40
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/convert-path-to-posix.js +1 -1
- package/dist/ref-parser/util/errors.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/errors.js +16 -34
- package/dist/ref-parser/util/is-windows.js +5 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/maybe.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/next.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/plugins.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/schema-resources.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/url.js +4 -113
- package/dist/schema/bundle.d.ts +1 -1
- package/dist/schema/bundle.js +1 -1
- package/dist/schema/ref.d.ts +3 -1
- package/dist/schema/ref.js +1 -1
- package/dist/schema/sample.js +5 -7
- package/dist/schema/to-string.js +6 -0
- package/dist/utils/cn.js +1 -1
- package/dist/utils/deep-merge.js +8 -0
- package/package.json +18 -17
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/dereference.js +0 -187
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.d.ts +0 -157
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.js +0 -136
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.d.ts +0 -166
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.js +0 -124
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/binary.js +0 -30
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/text.js +0 -36
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/pointer.d.ts +0 -96
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/ref.d.ts +0 -190
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/refs.d.ts +0 -134
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js +0 -112
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/errors.d.ts +0 -34
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.5_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/is-windows.js +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ParserError } from "../util/errors.js";
|
|
2
|
-
import
|
|
3
|
-
//#region
|
|
2
|
+
import { JSON_SCHEMA, load } from "js-yaml";
|
|
3
|
+
//#region src/ref-parser/parsers/yaml.ts
|
|
4
4
|
var yaml_default = {
|
|
5
5
|
/**
|
|
6
6
|
* The order that this parser will run, in relation to other parsers.
|
|
@@ -23,26 +23,20 @@ var yaml_default = {
|
|
|
23
23
|
],
|
|
24
24
|
/**
|
|
25
25
|
* Parses the given file as YAML
|
|
26
|
-
*
|
|
27
|
-
* @param file - An object containing information about the referenced file
|
|
28
|
-
* @param file.url - The full URL of the referenced file
|
|
29
|
-
* @param file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
|
30
|
-
* @param file.data - The file contents. This will be whatever data type was returned by the resolver
|
|
31
|
-
* @returns
|
|
32
26
|
*/
|
|
33
27
|
async parse(file) {
|
|
34
28
|
let data = file.data;
|
|
35
29
|
if (Buffer.isBuffer(data)) data = data.toString();
|
|
36
30
|
if (typeof data === "string") try {
|
|
37
|
-
return
|
|
31
|
+
return load(data, { schema: JSON_SCHEMA });
|
|
38
32
|
} catch {
|
|
39
33
|
try {
|
|
40
|
-
return
|
|
34
|
+
return load(data);
|
|
41
35
|
} catch (e) {
|
|
42
|
-
throw new ParserError(e
|
|
36
|
+
throw new ParserError(e instanceof Error ? e.message : "Parser Error", file.url);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
|
|
39
|
+
return data;
|
|
46
40
|
}
|
|
47
41
|
};
|
|
48
42
|
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { appendInternalRefPath, decodeInternalRef } from "../schema/ref.js";
|
|
1
2
|
import { getHash, resolve, stripHash } from "./util/url.js";
|
|
2
3
|
import { InvalidPointerError, JSONParserError, MissingPointerError, isHandledError } from "./util/errors.js";
|
|
3
4
|
import { getSchemaBasePath } from "./util/schema-resources.js";
|
|
4
5
|
import $Ref from "./ref.js";
|
|
5
|
-
//#region
|
|
6
|
+
//#region src/ref-parser/pointer.ts
|
|
6
7
|
const nullSymbol = Symbol("null");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const unsafeSetTokens = /* @__PURE__ */ new Set([
|
|
9
|
+
"__proto__",
|
|
10
|
+
"constructor",
|
|
11
|
+
"prototype"
|
|
12
|
+
]);
|
|
11
13
|
/**
|
|
12
14
|
* This class represents a single JSON pointer and its resolved value.
|
|
13
15
|
*
|
|
@@ -17,37 +19,6 @@ const escapedTilde = /~0/g;
|
|
|
17
19
|
* @class
|
|
18
20
|
*/
|
|
19
21
|
var Pointer = class Pointer {
|
|
20
|
-
/**
|
|
21
|
-
* The {@link $Ref} object that contains this {@link Pointer} object.
|
|
22
|
-
*/
|
|
23
|
-
$ref;
|
|
24
|
-
/**
|
|
25
|
-
* The file path or URL, containing the JSON pointer in the hash.
|
|
26
|
-
* This path is relative to the path of the main JSON schema file.
|
|
27
|
-
*/
|
|
28
|
-
path;
|
|
29
|
-
/**
|
|
30
|
-
* The original path or URL, used for error messages.
|
|
31
|
-
*/
|
|
32
|
-
originalPath;
|
|
33
|
-
/**
|
|
34
|
-
* The current base URI used to resolve nested $ref pointers while walking this pointer.
|
|
35
|
-
*/
|
|
36
|
-
scopeBase;
|
|
37
|
-
/**
|
|
38
|
-
* The value of the JSON pointer.
|
|
39
|
-
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
40
|
-
*/
|
|
41
|
-
value;
|
|
42
|
-
/**
|
|
43
|
-
* Indicates whether the pointer references itself.
|
|
44
|
-
*/
|
|
45
|
-
circular;
|
|
46
|
-
/**
|
|
47
|
-
* The number of indirect references that were traversed to resolve the value.
|
|
48
|
-
* Resolving a single pointer may require resolving multiple $Refs.
|
|
49
|
-
*/
|
|
50
|
-
indirections;
|
|
51
22
|
constructor($ref, path, friendlyPath) {
|
|
52
23
|
this.$ref = $ref;
|
|
53
24
|
this.path = path;
|
|
@@ -128,6 +99,7 @@ var Pointer = class Pointer {
|
|
|
128
99
|
this.value = value;
|
|
129
100
|
return value;
|
|
130
101
|
}
|
|
102
|
+
assertSafeSetTokens(this.path, tokens);
|
|
131
103
|
this.value = unwrapOrThrow(obj);
|
|
132
104
|
if (this.$ref.dynamicIdScope && !isAliasedResource(this.$ref)) this.scopeBase = getSchemaBasePath(this.scopeBase, this.value);
|
|
133
105
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
@@ -155,28 +127,24 @@ var Pointer = class Pointer {
|
|
|
155
127
|
* @returns
|
|
156
128
|
*/
|
|
157
129
|
static parse(path, originalPath) {
|
|
158
|
-
const
|
|
159
|
-
if (!
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
130
|
+
const hash = getHash(path);
|
|
131
|
+
if (!hash || hash === "#") return [];
|
|
132
|
+
try {
|
|
133
|
+
return decodeInternalRef(hash);
|
|
134
|
+
} catch {
|
|
135
|
+
throw new InvalidPointerError(hash.slice(1), originalPath === void 0 ? path : originalPath);
|
|
136
|
+
}
|
|
164
137
|
}
|
|
165
138
|
/**
|
|
166
139
|
* Creates a JSON pointer path, by joining one or more tokens to a base path.
|
|
167
|
-
*
|
|
168
|
-
* @param base - The base path (e.g. "schema.json#/definitions/person")
|
|
169
|
-
* @param tokens - The token(s) to append (e.g. ["name", "first"])
|
|
170
|
-
* @returns
|
|
171
140
|
*/
|
|
172
141
|
static join(base, tokens) {
|
|
173
|
-
if (base.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return base;
|
|
142
|
+
if (!base.includes("#")) base += "#";
|
|
143
|
+
const hashIndex = base.indexOf("#");
|
|
144
|
+
const prefix = base.slice(0, hashIndex);
|
|
145
|
+
let pointer = base.slice(hashIndex);
|
|
146
|
+
for (const token of Array.isArray(tokens) ? tokens : [tokens]) pointer = appendInternalRefPath(pointer, token);
|
|
147
|
+
return prefix + pointer;
|
|
180
148
|
}
|
|
181
149
|
};
|
|
182
150
|
/**
|
|
@@ -228,6 +196,9 @@ function setValue(pointer, token, value) {
|
|
|
228
196
|
else throw new JSONParserError(`Error assigning $ref pointer "${pointer.path}". \nCannot set "${token}" of a non-object.`);
|
|
229
197
|
return value;
|
|
230
198
|
}
|
|
199
|
+
function assertSafeSetTokens(pointerPath, tokens) {
|
|
200
|
+
for (const token of tokens) if (unsafeSetTokens.has(token)) throw new JSONParserError(`Error assigning $ref pointer "${pointerPath}". \nUnsafe JSON Pointer token "${token}" cannot be used for assignment.`);
|
|
201
|
+
}
|
|
231
202
|
function unwrapOrThrow(value) {
|
|
232
203
|
if (isHandledError(value)) throw value;
|
|
233
204
|
return value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,50 +1,18 @@
|
|
|
1
1
|
import { getHash, safePointerToPath, stripHash } from "./util/url.js";
|
|
2
2
|
import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js";
|
|
3
3
|
import Pointer, { nullSymbol } from "./pointer.js";
|
|
4
|
-
|
|
4
|
+
import { isPlainObject } from "../utils/is-plain-object.js";
|
|
5
|
+
import { mergeDeep } from "../utils/deep-merge.js";
|
|
6
|
+
//#region src/ref-parser/ref.ts
|
|
5
7
|
/**
|
|
6
8
|
* This class represents a single JSON reference and its resolved value.
|
|
7
9
|
*
|
|
8
10
|
* @class
|
|
9
11
|
*/
|
|
10
12
|
var $Ref = class $Ref {
|
|
11
|
-
/**
|
|
12
|
-
* The file path or URL of the referenced file.
|
|
13
|
-
* This path is relative to the path of the main JSON schema file.
|
|
14
|
-
*
|
|
15
|
-
* This path does NOT contain document fragments (JSON pointers). It always references an ENTIRE file.
|
|
16
|
-
* Use methods such as {@link $Ref#get}, {@link $Ref#resolve}, and {@link $Ref#exists} to get
|
|
17
|
-
* specific JSON pointers within the file.
|
|
18
|
-
*
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
path;
|
|
22
|
-
/**
|
|
23
|
-
* The resolved value of the JSON reference.
|
|
24
|
-
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
25
|
-
*
|
|
26
|
-
* @type {?*}
|
|
27
|
-
*/
|
|
28
|
-
value;
|
|
29
|
-
/**
|
|
30
|
-
* The {@link $Refs} object that contains this {@link $Ref} object.
|
|
31
|
-
*
|
|
32
|
-
* @type {$Refs}
|
|
33
|
-
*/
|
|
34
|
-
$refs;
|
|
35
|
-
/**
|
|
36
|
-
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
|
|
37
|
-
*/
|
|
38
|
-
pathType;
|
|
39
|
-
/**
|
|
40
|
-
* Whether this document/resource should use JSON Schema 2019-09+ nested $id scope semantics.
|
|
41
|
-
*/
|
|
42
|
-
dynamicIdScope = false;
|
|
43
|
-
/**
|
|
44
|
-
* List of all errors. Undefined if no errors.
|
|
45
|
-
*/
|
|
46
|
-
errors = [];
|
|
47
13
|
constructor($refs) {
|
|
14
|
+
this.dynamicIdScope = false;
|
|
15
|
+
this.errors = [];
|
|
48
16
|
this.$refs = $refs;
|
|
49
17
|
}
|
|
50
18
|
/**
|
|
@@ -224,24 +192,14 @@ var $Ref = class $Ref {
|
|
|
224
192
|
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {
|
|
225
193
|
const merged = {};
|
|
226
194
|
for (const key of Object.keys($ref)) if (key !== "$ref") merged[key] = $ref[key];
|
|
227
|
-
const mergeKeys = options?.dereference?.mergeKeys ?? true;
|
|
228
195
|
for (const _key of Object.keys(resolvedValue)) {
|
|
229
196
|
const key = _key;
|
|
230
197
|
if (!(key in merged)) merged[key] = resolvedValue[key];
|
|
231
|
-
else if (
|
|
198
|
+
else if (isPlainObject(merged[key]) && isPlainObject(resolvedValue[key])) merged[key] = mergeDeep(resolvedValue[key], merged[key]);
|
|
232
199
|
}
|
|
233
200
|
return merged;
|
|
234
201
|
} else return resolvedValue;
|
|
235
202
|
}
|
|
236
203
|
};
|
|
237
|
-
function deepMerge(target, source) {
|
|
238
|
-
if (typeof target !== "object" || target === null) return source;
|
|
239
|
-
if (typeof source !== "object" || source === null) return source;
|
|
240
|
-
const output = Array.isArray(target) ? [...target] : { ...target };
|
|
241
|
-
for (const key of Object.keys(source)) if (Array.isArray(source[key])) output[key] = [...source[key]];
|
|
242
|
-
else if (typeof source[key] === "object" && source[key] !== null) output[key] = deepMerge(target[key], source[key]);
|
|
243
|
-
else output[key] = source[key];
|
|
244
|
-
return output;
|
|
245
|
-
}
|
|
246
204
|
//#endregion
|
|
247
205
|
export { $Ref as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import convertPathToPosix from "./util/convert-path-to-posix.js";
|
|
2
2
|
import { resolve, stripHash, toFileSystemPath } from "./util/url.js";
|
|
3
3
|
import $Ref from "./ref.js";
|
|
4
|
-
//#region
|
|
4
|
+
//#region src/ref-parser/refs.ts
|
|
5
5
|
/**
|
|
6
6
|
* 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.
|
|
7
7
|
*
|
|
@@ -10,12 +10,6 @@ import $Ref from "./ref.js";
|
|
|
10
10
|
* See https://apidevtools.com/json-schema-ref-parser/docs/refs.html
|
|
11
11
|
*/
|
|
12
12
|
var $Refs = class {
|
|
13
|
-
/**
|
|
14
|
-
* 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.
|
|
15
|
-
*
|
|
16
|
-
* See https://apidevtools.com/json-schema-ref-parser/docs/refs.html#circular
|
|
17
|
-
*/
|
|
18
|
-
circular;
|
|
19
13
|
/**
|
|
20
14
|
* Returns the paths/URLs of all the files in your schema (including the main schema file).
|
|
21
15
|
*
|
|
@@ -136,22 +130,10 @@ var $Refs = class {
|
|
|
136
130
|
if (!$ref) throw new Error(`Error resolving $ref pointer "${path}". \n"${stripHash(absPath)}" not found.`);
|
|
137
131
|
return $ref.resolve(absPath, options, path, pathFromRoot);
|
|
138
132
|
}
|
|
139
|
-
/**
|
|
140
|
-
* A map of paths/urls to {@link $Ref} objects
|
|
141
|
-
*
|
|
142
|
-
* @type {object}
|
|
143
|
-
* @protected
|
|
144
|
-
*/
|
|
145
|
-
_$refs = {};
|
|
146
|
-
_aliases = {};
|
|
147
|
-
/**
|
|
148
|
-
* The {@link $Ref} object that is the root of the JSON schema.
|
|
149
|
-
*
|
|
150
|
-
* @type {$Ref}
|
|
151
|
-
* @protected
|
|
152
|
-
*/
|
|
153
|
-
_root$Ref;
|
|
154
133
|
constructor() {
|
|
134
|
+
this._$refs = {};
|
|
135
|
+
this._aliases = {};
|
|
136
|
+
this.toJSON = this.values;
|
|
155
137
|
/**
|
|
156
138
|
* Indicates whether the schema contains any circular references.
|
|
157
139
|
*
|
|
@@ -162,25 +144,6 @@ var $Refs = class {
|
|
|
162
144
|
this._aliases = {};
|
|
163
145
|
this._root$Ref = null;
|
|
164
146
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
|
167
|
-
* including the schema itself.
|
|
168
|
-
*
|
|
169
|
-
* @param [types] - Only return paths of the given types ("file", "http", etc.)
|
|
170
|
-
* @returns
|
|
171
|
-
*/
|
|
172
|
-
/**
|
|
173
|
-
* Returns the map of JSON references and their resolved values.
|
|
174
|
-
*
|
|
175
|
-
* @param [types] - Only return references of the given types ("file", "http", etc.)
|
|
176
|
-
* @returns
|
|
177
|
-
*/
|
|
178
|
-
/**
|
|
179
|
-
* Returns a POJO (plain old JavaScript object) for serialization as JSON.
|
|
180
|
-
*
|
|
181
|
-
* @returns {object}
|
|
182
|
-
*/
|
|
183
|
-
toJSON = this.values;
|
|
184
147
|
_getRef(path) {
|
|
185
148
|
const withoutHash = stripHash(path);
|
|
186
149
|
return this._$refs[withoutHash] || this._aliases[withoutHash];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHash, resolve, safePointerToPath, stripHash } from "./util/url.js";
|
|
2
2
|
import { isHandledError } from "./util/errors.js";
|
|
3
3
|
import { getSchemaBasePath } from "./util/schema-resources.js";
|
|
4
4
|
import Pointer from "./pointer.js";
|
|
5
5
|
import $Ref from "./ref.js";
|
|
6
6
|
import parse from "./parse.js";
|
|
7
|
-
//#region
|
|
7
|
+
//#region src/ref-parser/resolve-external.ts
|
|
8
8
|
/**
|
|
9
9
|
* Crawls the JSON schema, finds all external JSON references, and resolves their values.
|
|
10
10
|
* This method does not mutate the JSON schema. The resolved values are added to {@link $RefParser#$refs}.
|
|
@@ -71,7 +71,7 @@ function crawl(obj, path, scopeBase, dynamicIdScope, $refs, options, seen, exter
|
|
|
71
71
|
* including nested references that are contained in externally-referenced files.
|
|
72
72
|
*/
|
|
73
73
|
async function resolve$Ref($ref, path, scopeBase, dynamicIdScope, $refs, options) {
|
|
74
|
-
const resolutionBase =
|
|
74
|
+
const resolutionBase = dynamicIdScope ? scopeBase : path;
|
|
75
75
|
const resolvedPath = resolve(resolutionBase, $ref.$ref);
|
|
76
76
|
const withoutHash = stripHash(resolvedPath);
|
|
77
77
|
const ref = $refs._get$Ref(withoutHash);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isFileSystemPath, toFileSystemPath } from "../util/url.js";
|
|
2
2
|
import { ResolverError } from "../util/errors.js";
|
|
3
|
-
//#region
|
|
3
|
+
//#region src/ref-parser/resolvers/file.ts
|
|
4
4
|
var file_default = {
|
|
5
5
|
/**
|
|
6
6
|
* The order that this resolver will run, in relation to other resolvers.
|
|
@@ -1,43 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $
|
|
3
|
-
import { JSONSchema4, JSONSchema4Object, JSONSchema6, JSONSchema6Object, JSONSchema7, JSONSchema7Object } from "json-schema";
|
|
1
|
+
import { JSONSchema } from "json-schema-typed/draft-2020-12";
|
|
2
|
+
import { JSONSchema as JSONSchema$1 } from "json-schema-typed/draft-07";
|
|
4
3
|
|
|
5
|
-
//#region
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type SchemaCallback<S extends object = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* See https://apidevtools.com/json-schema-ref-parser/docs/options.html
|
|
12
|
-
*/
|
|
13
|
-
interface HTTPResolverOptions<S extends object = JSONSchema> extends Partial<ResolverOptions<S>> {
|
|
14
|
-
/**
|
|
15
|
-
* You can specify any HTTP headers that should be sent when downloading files. For example, some servers may require you to set the `Accept` or `Referrer` header.
|
|
16
|
-
*/
|
|
17
|
-
headers?: RequestInit["headers"] | null;
|
|
18
|
-
/**
|
|
19
|
-
* The amount of time (in milliseconds) to wait for a response from the server when downloading files. The default is 5 seconds.
|
|
20
|
-
*/
|
|
21
|
-
timeout?: number;
|
|
22
|
-
/**
|
|
23
|
-
* The maximum number of HTTP redirects to follow per file. The default is 5. To disable automatic following of redirects, set this to zero.
|
|
24
|
-
*/
|
|
25
|
-
redirects?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
|
28
|
-
*/
|
|
29
|
-
withCredentials?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Set this to `false` if you want to allow unsafe URLs (e.g., `127.0.0.1`, localhost, and other internal URLs).
|
|
32
|
-
*/
|
|
33
|
-
safeUrlResolver?: boolean;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* JSON Schema `$Ref` Parser comes with built-in resolvers for HTTP and HTTPS URLs, as well as local filesystem paths (when running in Node.js). You can add your own custom resolvers to support additional protocols, or even replace any of the built-in resolvers with your own custom implementation.
|
|
37
|
-
*
|
|
38
|
-
* See https://apidevtools.com/json-schema-ref-parser/docs/plugins/resolvers.html
|
|
39
|
-
*/
|
|
40
|
-
interface ResolverOptions<S extends object = JSONSchema> {
|
|
4
|
+
//#region src/ref-parser/types/index.d.ts
|
|
5
|
+
type JSONSchemaObject = Exclude<JSONSchema$1, boolean> | Exclude<JSONSchema, boolean>;
|
|
6
|
+
type JSONSchema$2 = JSONSchemaObject;
|
|
7
|
+
type SchemaCallback<S extends object = JSONSchema$2> = (err: Error | null, schema?: S | object | null) => any;
|
|
8
|
+
interface ResolverOptions<S extends object = JSONSchema$2> {
|
|
41
9
|
name?: string;
|
|
42
10
|
/**
|
|
43
11
|
* All resolvers have an order property, even the built-in resolvers. If you don't specify an order property, then your resolver will run last. Specifying `order: 1`, like we did in this example, will make your resolver run first. Or you can squeeze your resolver in-between some of the built-in resolvers. For example, `order: 101` would make it run after the file resolver, but before the HTTP resolver. You can see the order of all the built-in resolvers by looking at their source code.
|
|
@@ -130,4 +98,4 @@ interface FileInfo {
|
|
|
130
98
|
data: string | Buffer;
|
|
131
99
|
}
|
|
132
100
|
//#endregion
|
|
133
|
-
export { $
|
|
101
|
+
export { JSONSchema$2 as JSONSchema, JSONSchemaObject, Plugin, ResolverOptions, SchemaCallback };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region src/ref-parser/util/convert-path-to-posix.ts
|
|
2
2
|
const win32Sep = "\\";
|
|
3
3
|
function convertPathToPosix(filePath) {
|
|
4
4
|
if (filePath.startsWith("\\\\?\\")) return filePath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getHash, stripHash, toFileSystemPath } from "./url.js";
|
|
2
|
-
//#region
|
|
2
|
+
//#region src/ref-parser/util/errors.ts
|
|
3
3
|
const nonJsonTypes = [
|
|
4
4
|
"function",
|
|
5
5
|
"symbol",
|
|
@@ -40,33 +40,27 @@ function getDeepKeys(obj, omit = []) {
|
|
|
40
40
|
return uniqueKeys;
|
|
41
41
|
}
|
|
42
42
|
var JSONParserError = class extends Error {
|
|
43
|
-
name;
|
|
44
|
-
message;
|
|
45
|
-
source;
|
|
46
|
-
path;
|
|
47
|
-
code;
|
|
48
43
|
constructor(message, source) {
|
|
49
44
|
super();
|
|
45
|
+
this.toJSON = toJSON.bind(this);
|
|
50
46
|
this.code = "EUNKNOWN";
|
|
51
47
|
this.name = "JSONParserError";
|
|
52
48
|
this.message = message;
|
|
53
49
|
this.source = source;
|
|
54
50
|
this.path = null;
|
|
55
51
|
}
|
|
56
|
-
toJSON = toJSON.bind(this);
|
|
57
52
|
get footprint() {
|
|
58
53
|
return `${this.path}+${this.source}+${this.code}+${this.message}`;
|
|
59
54
|
}
|
|
60
55
|
};
|
|
61
56
|
var JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
|
|
62
|
-
files;
|
|
63
57
|
constructor(parser) {
|
|
64
58
|
super();
|
|
59
|
+
this.toJSON = toJSON.bind(this);
|
|
65
60
|
this.files = parser;
|
|
66
61
|
this.name = "JSONParserErrorGroup";
|
|
67
62
|
this.message = `${this.errors.length} error${this.errors.length > 1 ? "s" : ""} occurred while reading '${toFileSystemPath(parser.$refs._root$Ref.path)}'`;
|
|
68
63
|
}
|
|
69
|
-
toJSON = toJSON.bind(this);
|
|
70
64
|
static getParserErrors(parser) {
|
|
71
65
|
const errors = [];
|
|
72
66
|
for (const $ref of Object.values(parser.$refs._$refs)) if ($ref.errors) errors.push(...$ref.errors);
|
|
@@ -77,62 +71,50 @@ var JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
|
|
|
77
71
|
}
|
|
78
72
|
};
|
|
79
73
|
var ParserError = class extends JSONParserError {
|
|
80
|
-
code = "EPARSER";
|
|
81
|
-
name = "ParserError";
|
|
82
74
|
constructor(message, source) {
|
|
83
75
|
super(`Error parsing ${source}: ${message}`, source);
|
|
76
|
+
this.code = "EPARSER";
|
|
77
|
+
this.name = "ParserError";
|
|
84
78
|
}
|
|
85
79
|
};
|
|
86
80
|
var UnmatchedParserError = class extends JSONParserError {
|
|
87
|
-
code = "EUNMATCHEDPARSER";
|
|
88
|
-
name = "UnmatchedParserError";
|
|
89
81
|
constructor(source) {
|
|
90
82
|
super(`Could not find parser for "${source}"`, source);
|
|
83
|
+
this.code = "EUNMATCHEDPARSER";
|
|
84
|
+
this.name = "UnmatchedParserError";
|
|
91
85
|
}
|
|
92
86
|
};
|
|
93
87
|
var ResolverError = class extends JSONParserError {
|
|
94
|
-
code = "ERESOLVER";
|
|
95
|
-
name = "ResolverError";
|
|
96
|
-
ioErrorCode;
|
|
97
88
|
constructor(ex, source) {
|
|
98
89
|
super(ex.message || `Error reading file "${source}"`, source);
|
|
90
|
+
this.code = "ERESOLVER";
|
|
91
|
+
this.name = "ResolverError";
|
|
99
92
|
if ("code" in ex) this.ioErrorCode = String(ex.code);
|
|
100
93
|
}
|
|
101
94
|
};
|
|
102
95
|
var UnmatchedResolverError = class extends JSONParserError {
|
|
103
|
-
code = "EUNMATCHEDRESOLVER";
|
|
104
|
-
name = "UnmatchedResolverError";
|
|
105
96
|
constructor(source) {
|
|
106
97
|
super(`Could not find resolver for "${source}"`, source);
|
|
98
|
+
this.code = "EUNMATCHEDRESOLVER";
|
|
99
|
+
this.name = "UnmatchedResolverError";
|
|
107
100
|
}
|
|
108
101
|
};
|
|
109
102
|
var MissingPointerError = class extends JSONParserError {
|
|
110
|
-
code = "EMISSINGPOINTER";
|
|
111
|
-
name = "MissingPointerError";
|
|
112
|
-
targetToken;
|
|
113
|
-
targetRef;
|
|
114
|
-
targetFound;
|
|
115
|
-
parentPath;
|
|
116
103
|
constructor(token, path, targetRef, targetFound, parentPath) {
|
|
117
104
|
super(`Missing $ref pointer "${getHash(path)}". Token "${token}" does not exist.`, stripHash(path));
|
|
105
|
+
this.code = "EMISSINGPOINTER";
|
|
106
|
+
this.name = "MissingPointerError";
|
|
118
107
|
this.targetToken = token;
|
|
119
108
|
this.targetRef = targetRef;
|
|
120
109
|
this.targetFound = targetFound;
|
|
121
110
|
this.parentPath = parentPath;
|
|
122
111
|
}
|
|
123
112
|
};
|
|
124
|
-
var TimeoutError = class extends JSONParserError {
|
|
125
|
-
code = "ETIMEOUT";
|
|
126
|
-
name = "TimeoutError";
|
|
127
|
-
constructor(timeout) {
|
|
128
|
-
super(`Dereferencing timeout reached: ${timeout}ms`);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
113
|
var InvalidPointerError = class extends JSONParserError {
|
|
132
|
-
code = "EUNMATCHEDRESOLVER";
|
|
133
|
-
name = "InvalidPointerError";
|
|
134
114
|
constructor(pointer, path) {
|
|
135
115
|
super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path));
|
|
116
|
+
this.code = "EUNMATCHEDRESOLVER";
|
|
117
|
+
this.name = "InvalidPointerError";
|
|
136
118
|
}
|
|
137
119
|
};
|
|
138
120
|
function isHandledError(err) {
|
|
@@ -143,4 +125,4 @@ function normalizeError(err) {
|
|
|
143
125
|
return err;
|
|
144
126
|
}
|
|
145
127
|
//#endregion
|
|
146
|
-
export { InvalidPointerError, JSONParserError, JSONParserErrorGroup, MissingPointerError, ParserError, ResolverError,
|
|
128
|
+
export { InvalidPointerError, JSONParserError, JSONParserErrorGroup, MissingPointerError, ParserError, ResolverError, UnmatchedParserError, UnmatchedResolverError, isHandledError, normalizeError };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import next_default from "./next.js";
|
|
2
|
-
//#region
|
|
2
|
+
//#region src/ref-parser/util/maybe.ts
|
|
3
3
|
function maybe(cb, promise) {
|
|
4
4
|
if (cb) {
|
|
5
5
|
promise.then(function(result) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region src/ref-parser/util/next.ts
|
|
2
2
|
function makeNext() {
|
|
3
3
|
if (typeof process === "object" && typeof process.nextTick === "function") return process.nextTick;
|
|
4
4
|
else if (typeof setImmediate === "function") return setImmediate;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region src/ref-parser/util/plugins.ts
|
|
2
2
|
/**
|
|
3
3
|
* Returns the given plugins as an array, rather than an object map.
|
|
4
4
|
* All other methods in this module expect an array of plugins rather than an object map.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve } from "./url.js";
|
|
2
|
-
//#region
|
|
2
|
+
//#region src/ref-parser/util/schema-resources.ts
|
|
3
3
|
function getSchemaBasePath(basePath, value) {
|
|
4
4
|
const schemaId = getSchemaId(value);
|
|
5
5
|
return schemaId ? resolve(basePath, schemaId) : basePath;
|