@fumadocs/api-docs 0.0.3 → 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/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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/pointer.js +16 -54
- package/dist/ref-parser/ref.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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/ref-parser/util/url.js +206 -0
- 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/utils/cn.js +1 -1
- package/dist/utils/deep-merge.js +8 -0
- package/package.json +8 -10
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@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.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js +0 -121
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@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.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/is-windows.js +0 -5
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/url.js +0 -381
|
@@ -185,7 +185,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
185
185
|
return getJsonPointer.call(this, p, schOrRef);
|
|
186
186
|
}
|
|
187
187
|
exports.resolveSchema = resolveSchema;
|
|
188
|
-
const PREVENT_SCOPE_CHANGE = new Set([
|
|
188
|
+
const PREVENT_SCOPE_CHANGE = /* @__PURE__ */ new Set([
|
|
189
189
|
"properties",
|
|
190
190
|
"patternProperties",
|
|
191
191
|
"enum",
|
|
@@ -9,7 +9,7 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
9
9
|
const util_1 = require_util();
|
|
10
10
|
const equal = require_fast_deep_equal();
|
|
11
11
|
const traverse = require_json_schema_traverse();
|
|
12
|
-
const SIMPLE_INLINED = new Set([
|
|
12
|
+
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
13
13
|
"type",
|
|
14
14
|
"format",
|
|
15
15
|
"pattern",
|
|
@@ -34,7 +34,7 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
34
34
|
return countKeys(schema) <= limit;
|
|
35
35
|
}
|
|
36
36
|
exports.inlineRef = inlineRef;
|
|
37
|
-
const REF_KEYWORDS = new Set([
|
|
37
|
+
const REF_KEYWORDS = /* @__PURE__ */ new Set([
|
|
38
38
|
"$ref",
|
|
39
39
|
"$recursiveRef",
|
|
40
40
|
"$recursiveAnchor",
|
|
@@ -3,7 +3,7 @@ import { __commonJSMin } from "../../../../../../../_virtual/_rolldown/runtime.j
|
|
|
3
3
|
var require_rules = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.getRules = exports.isJSONType = void 0;
|
|
6
|
-
const jsonTypes = new Set([
|
|
6
|
+
const jsonTypes = /* @__PURE__ */ new Set([
|
|
7
7
|
"string",
|
|
8
8
|
"number",
|
|
9
9
|
"integer",
|
package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js
CHANGED
|
@@ -49,7 +49,7 @@ var require_dataType = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
49
49
|
return checkTypes;
|
|
50
50
|
}
|
|
51
51
|
exports.coerceAndCheckDataType = coerceAndCheckDataType;
|
|
52
|
-
const COERCIBLE = new Set([
|
|
52
|
+
const COERCIBLE = /* @__PURE__ */ new Set([
|
|
53
53
|
"string",
|
|
54
54
|
"number",
|
|
55
55
|
"integer",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JSONSchema, SchemaCallback } from "./types/index.js";
|
|
2
|
+
import { BundleOptions, ParserOptions } from "./options.js";
|
|
3
|
+
//#region src/ref-parser/bundle.d.ts
|
|
4
|
+
declare function bundle<S extends object = JSONSchema>(schema: S | string, options?: ParserOptions<S>): Promise<S>;
|
|
5
|
+
declare function bundle<S extends object = JSONSchema>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
6
|
+
declare function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
7
|
+
declare function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string, options: O): Promise<S>;
|
|
8
|
+
declare function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { bundle };
|
|
@@ -1,8 +1,76 @@
|
|
|
1
|
-
import { getHash, resolve, stripHash } from "./util/url.js";
|
|
2
|
-
import {
|
|
1
|
+
import { cwd, fromFileSystemPath, getHash, isFileSystemPath, resolve, stripHash } from "./util/url.js";
|
|
2
|
+
import { JSONParserErrorGroup, isHandledError } from "./util/errors.js";
|
|
3
|
+
import { getSchemaBasePath, registerSchemaResources, usesDynamicIdScope } from "./util/schema-resources.js";
|
|
3
4
|
import Pointer from "./pointer.js";
|
|
4
5
|
import $Ref from "./ref.js";
|
|
5
|
-
|
|
6
|
+
import $Refs from "./refs.js";
|
|
7
|
+
import parse from "./parse.js";
|
|
8
|
+
import normalizeArgs from "./normalize-args.js";
|
|
9
|
+
import resolveExternal from "./resolve-external.js";
|
|
10
|
+
import maybe from "./util/maybe.js";
|
|
11
|
+
//#region src/ref-parser/bundle.ts
|
|
12
|
+
/**
|
|
13
|
+
* Internal parser state used by the bundle pipeline.
|
|
14
|
+
*/
|
|
15
|
+
var $RefParser = class {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.schema = null;
|
|
18
|
+
this.$refs = new $Refs();
|
|
19
|
+
}
|
|
20
|
+
async parse(path, schema, options) {
|
|
21
|
+
this.schema = null;
|
|
22
|
+
this.$refs = new $Refs();
|
|
23
|
+
if (!path && !schema) throw new Error(`Expected a file path or object. Got ${path || schema}`);
|
|
24
|
+
let pathType = "file";
|
|
25
|
+
if (path && isFileSystemPath(path)) path = fromFileSystemPath(path);
|
|
26
|
+
path = resolve(cwd(), path || "");
|
|
27
|
+
if (schema && typeof schema === "object") {
|
|
28
|
+
const $ref = this.$refs._add(path);
|
|
29
|
+
$ref.value = schema;
|
|
30
|
+
$ref.pathType = pathType;
|
|
31
|
+
$ref.dynamicIdScope = usesDynamicIdScope($ref.value);
|
|
32
|
+
registerSchemaResources(this.$refs, $ref.path, $ref.value, $ref.pathType, $ref.dynamicIdScope);
|
|
33
|
+
this.schema = schema;
|
|
34
|
+
return schema;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const result = await parse(path, this.$refs, options);
|
|
38
|
+
if (result !== null && typeof result === "object" && !Buffer.isBuffer(result)) {
|
|
39
|
+
this.schema = result;
|
|
40
|
+
return this.schema;
|
|
41
|
+
}
|
|
42
|
+
throw new SyntaxError(`"${this.$refs._root$Ref.path || result}" is not a valid JSON Schema`);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (!options.continueOnError || !isHandledError(err)) throw err;
|
|
45
|
+
if (this.$refs._$refs[stripHash(path)]) this.$refs._$refs[stripHash(path)].addError(err);
|
|
46
|
+
this.schema = null;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async resolve(path, schema, options) {
|
|
51
|
+
await this.parse(path, schema, options);
|
|
52
|
+
await resolveExternal(this, options);
|
|
53
|
+
finalize(this);
|
|
54
|
+
return this.$refs;
|
|
55
|
+
}
|
|
56
|
+
async runBundle(path, schema, options, callback) {
|
|
57
|
+
try {
|
|
58
|
+
await this.resolve(path, schema, options);
|
|
59
|
+
inlineRefs(this, options);
|
|
60
|
+
finalize(this);
|
|
61
|
+
return maybe(callback, Promise.resolve(this.schema));
|
|
62
|
+
} catch (err) {
|
|
63
|
+
return maybe(callback, Promise.reject(err));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function finalize(parser) {
|
|
68
|
+
if (JSONParserErrorGroup.getParserErrors(parser).length > 0) throw new JSONParserErrorGroup(parser);
|
|
69
|
+
}
|
|
70
|
+
async function bundle() {
|
|
71
|
+
const args = normalizeArgs(arguments);
|
|
72
|
+
return new $RefParser().runBundle(args.path, args.schema, args.options, args.callback);
|
|
73
|
+
}
|
|
6
74
|
/**
|
|
7
75
|
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
|
|
8
76
|
* only has *internal* references, not any *external* references.
|
|
@@ -11,7 +79,7 @@ import $Ref from "./ref.js";
|
|
|
11
79
|
* @param parser
|
|
12
80
|
* @param options
|
|
13
81
|
*/
|
|
14
|
-
function
|
|
82
|
+
function inlineRefs(parser, options) {
|
|
15
83
|
const rootScopeBase = parser.$refs._root$Ref.dynamicIdScope ? getSchemaBasePath(parser.$refs._root$Ref.path, parser.schema) : parser.$refs._root$Ref.path;
|
|
16
84
|
const inventory = [];
|
|
17
85
|
crawl(parser, "schema", parser.$refs._root$Ref.path + "#", rootScopeBase, parser.$refs._root$Ref.dynamicIdScope, "#", 0, inventory, parser.$refs, options);
|
|
@@ -79,6 +147,7 @@ function inventory$Ref($refParent, $refKey, path, scopeBase, dynamicIdScope, pat
|
|
|
79
147
|
const file = stripHash(pointer.path);
|
|
80
148
|
const hash = getHash(pointer.path);
|
|
81
149
|
const external = file !== $refs._root$Ref.path && !$refs._aliases[file];
|
|
150
|
+
const nestedResource = Boolean($refs._aliases[file]) && pointer.$ref.value !== $refs._root$Ref.value;
|
|
82
151
|
const extended = $Ref.isExtended$Ref($ref);
|
|
83
152
|
indirections += pointer.indirections;
|
|
84
153
|
const existingEntry = findInInventory(inventory, $refParent, $refKey);
|
|
@@ -96,6 +165,7 @@ function inventory$Ref($refParent, $refKey, path, scopeBase, dynamicIdScope, pat
|
|
|
96
165
|
circular: pointer.circular,
|
|
97
166
|
extended,
|
|
98
167
|
external,
|
|
168
|
+
nestedResource,
|
|
99
169
|
indirections
|
|
100
170
|
});
|
|
101
171
|
if (!existingEntry || external) crawl(pointer.value, null, pointer.path, pointer.$ref.path, pointer.$ref.dynamicIdScope, pathFromRoot, indirections + 1, inventory, $refs, options);
|
|
@@ -141,7 +211,7 @@ function remap(inventory, options, rootId) {
|
|
|
141
211
|
for (const entry of inventory) {
|
|
142
212
|
const bundleOpts = options.bundle || {};
|
|
143
213
|
if (!entry.external) {
|
|
144
|
-
if (bundleOpts.optimizeInternalRefs !== false) entry.$ref.$ref = entry.hash;
|
|
214
|
+
if (bundleOpts.optimizeInternalRefs !== false && !entry.nestedResource) entry.$ref.$ref = entry.hash;
|
|
145
215
|
} else if (entry.file === file && entry.hash === hash) if (rootId && isInsideIdScope(inventory, entry)) entry.$ref.$ref = rootId + pathFromRoot;
|
|
146
216
|
else entry.$ref.$ref = pathFromRoot;
|
|
147
217
|
else if (entry.file === file && entry.hash.indexOf(hash + "/") === 0) {
|
|
@@ -236,4 +306,4 @@ function isInsideIdScope(inventory, entry) {
|
|
|
236
306
|
return false;
|
|
237
307
|
}
|
|
238
308
|
//#endregion
|
|
239
|
-
export { bundle
|
|
309
|
+
export { bundle };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNewOptions } from "./options.js";
|
|
2
|
-
//#region
|
|
2
|
+
//#region src/ref-parser/normalize-args.ts
|
|
3
3
|
/**
|
|
4
4
|
* Normalizes the given arguments, accounting for optional args.
|
|
5
5
|
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { JSONSchema, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ref-parser/options.d.ts
|
|
4
|
+
type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
|
5
|
+
interface BundleOptions {
|
|
6
|
+
excludedPathMatcher?(path: string): boolean;
|
|
7
|
+
onBundle?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
|
|
8
|
+
optimizeInternalRefs?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface $RefParserOptions<S extends object = JSONSchema> {
|
|
11
|
+
parse: {
|
|
12
|
+
json?: Plugin | boolean;
|
|
13
|
+
yaml?: Plugin | boolean;
|
|
14
|
+
[key: string]: Plugin | boolean | undefined;
|
|
15
|
+
};
|
|
16
|
+
resolve: {
|
|
17
|
+
external?: boolean;
|
|
18
|
+
file?: Partial<ResolverOptions<S>> | boolean;
|
|
19
|
+
} & {
|
|
20
|
+
[key: string]: Partial<ResolverOptions<S>> | boolean | undefined;
|
|
21
|
+
};
|
|
22
|
+
continueOnError: boolean;
|
|
23
|
+
bundle: BundleOptions;
|
|
24
|
+
mutateInputSchema?: boolean;
|
|
25
|
+
}
|
|
26
|
+
type ParserOptions<S extends object = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { BundleOptions, ParserOptions };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeDeep } from "../utils/deep-merge.js";
|
|
2
|
+
import json_default from "./parsers/json.js";
|
|
3
|
+
import yaml_default from "./parsers/yaml.js";
|
|
4
|
+
import file_default from "./resolvers/file.js";
|
|
5
|
+
//#region src/ref-parser/options.ts
|
|
6
|
+
const getJsonSchemaRefParserDefaultOptions = () => {
|
|
7
|
+
return {
|
|
8
|
+
parse: {
|
|
9
|
+
json: { ...json_default },
|
|
10
|
+
yaml: { ...yaml_default }
|
|
11
|
+
},
|
|
12
|
+
resolve: {
|
|
13
|
+
file: { ...file_default },
|
|
14
|
+
external: true
|
|
15
|
+
},
|
|
16
|
+
continueOnError: false,
|
|
17
|
+
bundle: { excludedPathMatcher: () => false },
|
|
18
|
+
mutateInputSchema: true
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const getNewOptions = (options) => {
|
|
22
|
+
const defaults = getJsonSchemaRefParserDefaultOptions();
|
|
23
|
+
if (!options) return defaults;
|
|
24
|
+
return mergeDeep(defaults, options);
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { getNewOptions };
|
|
@@ -2,7 +2,7 @@ import { getExtension } from "./util/url.js";
|
|
|
2
2
|
import { ParserError, ResolverError, UnmatchedParserError, UnmatchedResolverError, isHandledError } from "./util/errors.js";
|
|
3
3
|
import { registerSchemaResources, usesDynamicIdScope } from "./util/schema-resources.js";
|
|
4
4
|
import { all, filter, run, sort } from "./util/plugins.js";
|
|
5
|
-
//#region
|
|
5
|
+
//#region src/ref-parser/parse.ts
|
|
6
6
|
/**
|
|
7
7
|
* Reads and parses the specified file path or URL.
|
|
8
8
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserError } from "../util/errors.js";
|
|
2
|
-
//#region
|
|
2
|
+
//#region src/ref-parser/parsers/json.ts
|
|
3
3
|
var json_default = {
|
|
4
4
|
/**
|
|
5
5
|
* The order that this parser will run, in relation to other parsers.
|
|
@@ -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,14 +1,11 @@
|
|
|
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
|
-
const tildes = /~/g;
|
|
9
|
-
const escapedSlash = /~1/g;
|
|
10
|
-
const escapedTilde = /~0/g;
|
|
11
|
-
const unsafeSetTokens = new Set([
|
|
8
|
+
const unsafeSetTokens = /* @__PURE__ */ new Set([
|
|
12
9
|
"__proto__",
|
|
13
10
|
"constructor",
|
|
14
11
|
"prototype"
|
|
@@ -22,37 +19,6 @@ const unsafeSetTokens = new Set([
|
|
|
22
19
|
* @class
|
|
23
20
|
*/
|
|
24
21
|
var Pointer = class Pointer {
|
|
25
|
-
/**
|
|
26
|
-
* The {@link $Ref} object that contains this {@link Pointer} object.
|
|
27
|
-
*/
|
|
28
|
-
$ref;
|
|
29
|
-
/**
|
|
30
|
-
* The file path or URL, containing the JSON pointer in the hash.
|
|
31
|
-
* This path is relative to the path of the main JSON schema file.
|
|
32
|
-
*/
|
|
33
|
-
path;
|
|
34
|
-
/**
|
|
35
|
-
* The original path or URL, used for error messages.
|
|
36
|
-
*/
|
|
37
|
-
originalPath;
|
|
38
|
-
/**
|
|
39
|
-
* The current base URI used to resolve nested $ref pointers while walking this pointer.
|
|
40
|
-
*/
|
|
41
|
-
scopeBase;
|
|
42
|
-
/**
|
|
43
|
-
* The value of the JSON pointer.
|
|
44
|
-
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
|
45
|
-
*/
|
|
46
|
-
value;
|
|
47
|
-
/**
|
|
48
|
-
* Indicates whether the pointer references itself.
|
|
49
|
-
*/
|
|
50
|
-
circular;
|
|
51
|
-
/**
|
|
52
|
-
* The number of indirect references that were traversed to resolve the value.
|
|
53
|
-
* Resolving a single pointer may require resolving multiple $Refs.
|
|
54
|
-
*/
|
|
55
|
-
indirections;
|
|
56
22
|
constructor($ref, path, friendlyPath) {
|
|
57
23
|
this.$ref = $ref;
|
|
58
24
|
this.path = path;
|
|
@@ -161,28 +127,24 @@ var Pointer = class Pointer {
|
|
|
161
127
|
* @returns
|
|
162
128
|
*/
|
|
163
129
|
static parse(path, originalPath) {
|
|
164
|
-
const
|
|
165
|
-
if (!
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
+
}
|
|
170
137
|
}
|
|
171
138
|
/**
|
|
172
139
|
* Creates a JSON pointer path, by joining one or more tokens to a base path.
|
|
173
|
-
*
|
|
174
|
-
* @param base - The base path (e.g. "schema.json#/definitions/person")
|
|
175
|
-
* @param tokens - The token(s) to append (e.g. ["name", "first"])
|
|
176
|
-
* @returns
|
|
177
140
|
*/
|
|
178
141
|
static join(base, tokens) {
|
|
179
|
-
if (base.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
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;
|
|
186
148
|
}
|
|
187
149
|
};
|
|
188
150
|
/**
|
|
@@ -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.
|