@fumadocs/api-docs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/css/generated/shared.css +1 -0
- package/css/preset.css +1 -0
- package/dist/.translations/index.d.ts +28 -0
- package/dist/.translations/keys.js +28 -0
- package/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/auto-anchor/client.d.ts +16 -0
- package/dist/auto-anchor/client.js +20 -0
- package/dist/auto-anchor/index.d.ts +9 -0
- package/dist/auto-anchor/index.js +17 -0
- package/dist/codegen.d.ts +38 -0
- package/dist/codegen.js +35 -0
- package/dist/components/accordion.d.ts +22 -0
- package/dist/components/accordion.js +67 -0
- package/dist/components/dialog.d.ts +39 -0
- package/dist/components/dialog.js +61 -0
- package/dist/components/input.d.ts +8 -0
- package/dist/components/input.js +17 -0
- package/dist/components/playground/inputs.d.ts +50 -0
- package/dist/components/playground/inputs.js +426 -0
- package/dist/components/playground/schema.d.ts +66 -0
- package/dist/components/playground/schema.js +144 -0
- package/dist/components/schema/client.d.ts +17 -0
- package/dist/components/schema/client.js +415 -0
- package/dist/components/schema/index.d.ts +102 -0
- package/dist/components/schema/index.js +276 -0
- package/dist/components/select-tab.d.ts +33 -0
- package/dist/components/select-tab.js +56 -0
- package/dist/components/select.d.ts +16 -0
- package/dist/components/select.js +72 -0
- package/dist/components/spinner.d.ts +7 -0
- package/dist/components/spinner.js +14 -0
- package/dist/i18n.d.ts +7 -0
- package/dist/i18n.js +7 -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/bundle.js +239 -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/dereference.js +187 -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/index.d.ts +157 -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/index.js +136 -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/normalize-args.js +41 -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/options.d.ts +166 -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/options.js +124 -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/parse.js +109 -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/parsers/binary.js +30 -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/parsers/json.js +46 -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/parsers/text.js +36 -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/parsers/yaml.js +49 -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/pointer.d.ts +96 -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/pointer.js +242 -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.d.ts +190 -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.js +247 -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/refs.d.ts +134 -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/refs.js +210 -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/resolve-external.js +100 -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/resolvers/file.js +41 -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/resolvers/http.js +112 -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/types/index.d.ts +133 -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/util/convert-path-to-posix.js +8 -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/util/errors.d.ts +34 -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/util/errors.js +146 -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/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/util/maybe.js +18 -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/util/next.js +11 -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/util/plugins.js +99 -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/util/schema-resources.js +30 -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/util/url.js +315 -0
- package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js +108 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +110 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/code.js +138 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +674 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/scope.js +141 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/errors.js +102 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +223 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/names.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/ref_error.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +133 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +146 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/applicability.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +172 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/defaults.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +433 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +113 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +583 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/data.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/index.js +42 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.js +50 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.js +36 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.js +85 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/schema.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/equal.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js +25 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/uri.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/validation_error.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +57 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +96 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +29 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +89 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +87 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/if.js +62 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +60 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +34 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/not.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +52 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +41 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/code.js +130 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/id.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +112 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +101 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/draft2020.js +35 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js +45 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js +15 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/index.js +10 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/metadata.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/next.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/index.js +13 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/const.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/enum.js +49 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/index.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitContains.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +33 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +47 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +38 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +70 -0
- package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +33 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +236 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +187 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +282 -0
- package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +78 -0
- package/dist/schema/bundle.d.ts +2 -0
- package/dist/schema/bundle.js +2 -0
- package/dist/schema/dereference.d.ts +19 -0
- package/dist/schema/dereference.js +49 -0
- package/dist/schema/index.d.ts +21 -0
- package/dist/schema/index.js +0 -0
- package/dist/schema/merge.d.ts +12 -0
- package/dist/schema/merge.js +156 -0
- package/dist/schema/ref.d.ts +20 -0
- package/dist/schema/ref.js +43 -0
- package/dist/schema/resolve-ref.d.ts +4 -0
- package/dist/schema/resolve-ref.js +11 -0
- package/dist/schema/sample.d.ts +12 -0
- package/dist/schema/sample.js +442 -0
- package/dist/schema/to-string.d.ts +10 -0
- package/dist/schema/to-string.js +51 -0
- package/dist/utils/cn.js +2 -0
- package/dist/utils/deep-equal.js +21 -0
- package/dist/utils/id-to-title.d.ts +4 -0
- package/dist/utils/id-to-title.js +12 -0
- package/dist/utils/is-plain-object.js +8 -0
- package/dist/utils/merge-refs.js +11 -0
- package/dist/utils/url.d.ts +5 -0
- package/dist/utils/url.js +13 -0
- package/package.json +105 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { getHash, resolve, stripHash } from "./util/url.js";
|
|
2
|
+
import { getSchemaBasePath } from "./util/schema-resources.js";
|
|
3
|
+
import Pointer from "./pointer.js";
|
|
4
|
+
import $Ref from "./ref.js";
|
|
5
|
+
//#region ../../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/bundle.js
|
|
6
|
+
/**
|
|
7
|
+
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
|
|
8
|
+
* only has *internal* references, not any *external* references.
|
|
9
|
+
* This method mutates the JSON schema object, adding new references and re-mapping existing ones.
|
|
10
|
+
*
|
|
11
|
+
* @param parser
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
function bundle(parser, options) {
|
|
15
|
+
const rootScopeBase = parser.$refs._root$Ref.dynamicIdScope ? getSchemaBasePath(parser.$refs._root$Ref.path, parser.schema) : parser.$refs._root$Ref.path;
|
|
16
|
+
const inventory = [];
|
|
17
|
+
crawl(parser, "schema", parser.$refs._root$Ref.path + "#", rootScopeBase, parser.$refs._root$Ref.dynamicIdScope, "#", 0, inventory, parser.$refs, options);
|
|
18
|
+
remap(inventory, options, parser.schema && typeof parser.schema === "object" && "$id" in parser.schema ? parser.schema.$id : void 0);
|
|
19
|
+
if ((options.bundle || {}).optimizeInternalRefs !== false) fixRefsThroughRefs(inventory, parser.schema);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Recursively crawls the given value, and inventories all JSON references.
|
|
23
|
+
*
|
|
24
|
+
* @param parent - The object containing the value to crawl. If the value is not an object or array, it will be ignored.
|
|
25
|
+
* @param key - The property key of `parent` to be crawled
|
|
26
|
+
* @param path - The full path of the property being crawled, possibly with a JSON Pointer in the hash
|
|
27
|
+
* @param pathFromRoot - The path of the property being crawled, from the schema root
|
|
28
|
+
* @param indirections
|
|
29
|
+
* @param inventory - An array of already-inventoried $ref pointers
|
|
30
|
+
* @param $refs
|
|
31
|
+
* @param options
|
|
32
|
+
*/
|
|
33
|
+
function crawl(parent, key, path, scopeBase, dynamicIdScope, pathFromRoot, indirections, inventory, $refs, options) {
|
|
34
|
+
const obj = key === null ? parent : parent[key];
|
|
35
|
+
const bundleOptions = options.bundle || {};
|
|
36
|
+
const isExcludedPath = bundleOptions.excludedPathMatcher || (() => false);
|
|
37
|
+
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
|
|
38
|
+
const currentScopeBase = scopeBase;
|
|
39
|
+
if ($Ref.isAllowed$Ref(obj)) inventory$Ref(parent, key, path, currentScopeBase, dynamicIdScope, pathFromRoot, indirections, inventory, $refs, options);
|
|
40
|
+
else {
|
|
41
|
+
const keys = Object.keys(obj).sort((a, b) => {
|
|
42
|
+
if (a === "definitions" || a === "$defs") return -1;
|
|
43
|
+
else if (b === "definitions" || b === "$defs") return 1;
|
|
44
|
+
else return a.length - b.length;
|
|
45
|
+
});
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const keyPath = Pointer.join(path, key);
|
|
48
|
+
const keyPathFromRoot = Pointer.join(pathFromRoot, key);
|
|
49
|
+
const value = obj[key];
|
|
50
|
+
const childScopeBase = dynamicIdScope && value && typeof value === "object" && !ArrayBuffer.isView(value) ? getSchemaBasePath(currentScopeBase, value) : currentScopeBase;
|
|
51
|
+
if ($Ref.isAllowed$Ref(value)) inventory$Ref(obj, key, keyPath, childScopeBase, dynamicIdScope, keyPathFromRoot, indirections, inventory, $refs, options);
|
|
52
|
+
else crawl(obj, key, keyPath, childScopeBase, dynamicIdScope, keyPathFromRoot, indirections, inventory, $refs, options);
|
|
53
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
54
|
+
if ("$ref" in value) bundleOptions?.onBundle?.(value["$ref"], obj[key], obj, key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Inventories the given JSON Reference (i.e. records detailed information about it so we can
|
|
62
|
+
* optimize all $refs in the schema), and then crawls the resolved value.
|
|
63
|
+
*
|
|
64
|
+
* @param $refParent - The object that contains a JSON Reference as one of its keys
|
|
65
|
+
* @param $refKey - The key in `$refParent` that is a JSON Reference
|
|
66
|
+
* @param path - The full path of the JSON Reference at `$refKey`, possibly with a JSON Pointer in the hash
|
|
67
|
+
* @param indirections - unknown
|
|
68
|
+
* @param pathFromRoot - The path of the JSON Reference at `$refKey`, from the schema root
|
|
69
|
+
* @param inventory - An array of already-inventoried $ref pointers
|
|
70
|
+
* @param $refs
|
|
71
|
+
* @param options
|
|
72
|
+
*/
|
|
73
|
+
function inventory$Ref($refParent, $refKey, path, scopeBase, dynamicIdScope, pathFromRoot, indirections, inventory, $refs, options) {
|
|
74
|
+
const $ref = $refKey === null ? $refParent : $refParent[$refKey];
|
|
75
|
+
const $refPath = resolve(dynamicIdScope ? scopeBase : path, $ref.$ref);
|
|
76
|
+
const pointer = $refs._resolve($refPath, pathFromRoot, options);
|
|
77
|
+
if (pointer === null) return;
|
|
78
|
+
const depth = Pointer.parse(pathFromRoot).length;
|
|
79
|
+
const file = stripHash(pointer.path);
|
|
80
|
+
const hash = getHash(pointer.path);
|
|
81
|
+
const external = file !== $refs._root$Ref.path && !$refs._aliases[file];
|
|
82
|
+
const extended = $Ref.isExtended$Ref($ref);
|
|
83
|
+
indirections += pointer.indirections;
|
|
84
|
+
const existingEntry = findInInventory(inventory, $refParent, $refKey);
|
|
85
|
+
if (existingEntry) if (depth < existingEntry.depth || indirections < existingEntry.indirections) removeFromInventory(inventory, existingEntry);
|
|
86
|
+
else return;
|
|
87
|
+
inventory.push({
|
|
88
|
+
$ref,
|
|
89
|
+
parent: $refParent,
|
|
90
|
+
key: $refKey,
|
|
91
|
+
pathFromRoot,
|
|
92
|
+
depth,
|
|
93
|
+
file,
|
|
94
|
+
hash,
|
|
95
|
+
value: pointer.value,
|
|
96
|
+
circular: pointer.circular,
|
|
97
|
+
extended,
|
|
98
|
+
external,
|
|
99
|
+
indirections
|
|
100
|
+
});
|
|
101
|
+
if (!existingEntry || external) crawl(pointer.value, null, pointer.path, pointer.$ref.path, pointer.$ref.dynamicIdScope, pathFromRoot, indirections + 1, inventory, $refs, options);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Re-maps every $ref pointer, so that they're all relative to the root of the JSON Schema.
|
|
105
|
+
* Each referenced value is dereferenced EXACTLY ONCE. All subsequent references to the same
|
|
106
|
+
* value are re-mapped to point to the first reference.
|
|
107
|
+
*
|
|
108
|
+
* @example: {
|
|
109
|
+
* first: { $ref: somefile.json#/some/part },
|
|
110
|
+
* second: { $ref: somefile.json#/another/part },
|
|
111
|
+
* third: { $ref: somefile.json },
|
|
112
|
+
* fourth: { $ref: somefile.json#/some/part/sub/part }
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* In this example, there are four references to the same file, but since the third reference points
|
|
116
|
+
* to the ENTIRE file, that's the only one we need to dereference. The other three can just be
|
|
117
|
+
* remapped to point inside the third one.
|
|
118
|
+
*
|
|
119
|
+
* On the other hand, if the third reference DIDN'T exist, then the first and second would both need
|
|
120
|
+
* to be dereferenced, since they point to different parts of the file. The fourth reference does NOT
|
|
121
|
+
* need to be dereferenced, because it can be remapped to point inside the first one.
|
|
122
|
+
*
|
|
123
|
+
* @param inventory
|
|
124
|
+
*/
|
|
125
|
+
function remap(inventory, options, rootId) {
|
|
126
|
+
inventory.sort((a, b) => {
|
|
127
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
128
|
+
else if (a.hash !== b.hash) return a.hash < b.hash ? -1 : 1;
|
|
129
|
+
else if (a.circular !== b.circular) return a.circular ? -1 : 1;
|
|
130
|
+
else if (a.extended !== b.extended) return a.extended ? 1 : -1;
|
|
131
|
+
else if (a.indirections !== b.indirections) return a.indirections - b.indirections;
|
|
132
|
+
else if (a.depth !== b.depth) return a.depth - b.depth;
|
|
133
|
+
else {
|
|
134
|
+
const aDefinitionsIndex = Math.max(a.pathFromRoot.lastIndexOf("/definitions"), a.pathFromRoot.lastIndexOf("/$defs"));
|
|
135
|
+
const bDefinitionsIndex = Math.max(b.pathFromRoot.lastIndexOf("/definitions"), b.pathFromRoot.lastIndexOf("/$defs"));
|
|
136
|
+
if (aDefinitionsIndex !== bDefinitionsIndex) return bDefinitionsIndex - aDefinitionsIndex;
|
|
137
|
+
else return a.pathFromRoot.length - b.pathFromRoot.length;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
let file, hash, pathFromRoot;
|
|
141
|
+
for (const entry of inventory) {
|
|
142
|
+
const bundleOpts = options.bundle || {};
|
|
143
|
+
if (!entry.external) {
|
|
144
|
+
if (bundleOpts.optimizeInternalRefs !== false) entry.$ref.$ref = entry.hash;
|
|
145
|
+
} else if (entry.file === file && entry.hash === hash) if (rootId && isInsideIdScope(inventory, entry)) entry.$ref.$ref = rootId + pathFromRoot;
|
|
146
|
+
else entry.$ref.$ref = pathFromRoot;
|
|
147
|
+
else if (entry.file === file && entry.hash.indexOf(hash + "/") === 0) {
|
|
148
|
+
const subPath = Pointer.join(pathFromRoot, Pointer.parse(entry.hash.replace(hash, "#")));
|
|
149
|
+
if (rootId && isInsideIdScope(inventory, entry)) entry.$ref.$ref = rootId + subPath;
|
|
150
|
+
else entry.$ref.$ref = subPath;
|
|
151
|
+
} else {
|
|
152
|
+
file = entry.file;
|
|
153
|
+
hash = entry.hash;
|
|
154
|
+
pathFromRoot = entry.pathFromRoot;
|
|
155
|
+
entry.$ref = entry.parent[entry.key] = $Ref.dereference(entry.$ref, entry.value, options);
|
|
156
|
+
if (entry.circular) entry.$ref.$ref = entry.pathFromRoot;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* TODO
|
|
162
|
+
*/
|
|
163
|
+
function findInInventory(inventory, $refParent, $refKey) {
|
|
164
|
+
for (const existingEntry of inventory) if (existingEntry && existingEntry.parent === $refParent && existingEntry.key === $refKey) return existingEntry;
|
|
165
|
+
}
|
|
166
|
+
function removeFromInventory(inventory, entry) {
|
|
167
|
+
const index = inventory.indexOf(entry);
|
|
168
|
+
inventory.splice(index, 1);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* After remapping, some $ref paths may traverse through other $ref nodes.
|
|
172
|
+
* JSON pointer resolution does not follow $ref indirection, so these paths are invalid.
|
|
173
|
+
* This function detects and fixes such paths by following any intermediate $refs
|
|
174
|
+
* to compute a valid direct path.
|
|
175
|
+
*/
|
|
176
|
+
function fixRefsThroughRefs(inventory, schema) {
|
|
177
|
+
for (const entry of inventory) {
|
|
178
|
+
if (!entry.$ref || typeof entry.$ref !== "object" || !("$ref" in entry.$ref)) continue;
|
|
179
|
+
const refValue = entry.$ref.$ref;
|
|
180
|
+
if (typeof refValue !== "string" || !refValue.startsWith("#/")) continue;
|
|
181
|
+
const fixedPath = resolvePathThroughRefs(schema, refValue);
|
|
182
|
+
if (fixedPath !== refValue) entry.$ref.$ref = fixedPath;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Walks a JSON pointer path through the schema. If any intermediate value
|
|
187
|
+
* is a $ref, follows it and adjusts the path accordingly.
|
|
188
|
+
* Returns the corrected path that doesn't traverse through any $ref.
|
|
189
|
+
*/
|
|
190
|
+
function resolvePathThroughRefs(schema, refPath) {
|
|
191
|
+
if (!refPath.startsWith("#/")) return refPath;
|
|
192
|
+
const segments = refPath.slice(2).split("/");
|
|
193
|
+
let current = schema;
|
|
194
|
+
const resolvedSegments = [];
|
|
195
|
+
for (const seg of segments) {
|
|
196
|
+
if (current === null || current === void 0 || typeof current !== "object") return refPath;
|
|
197
|
+
if ("$ref" in current && typeof current.$ref === "string" && current.$ref.startsWith("#/")) {
|
|
198
|
+
const targetSegments = current.$ref.slice(2).split("/");
|
|
199
|
+
resolvedSegments.length = 0;
|
|
200
|
+
resolvedSegments.push(...targetSegments);
|
|
201
|
+
current = walkPath(schema, current.$ref);
|
|
202
|
+
if (current === null || current === void 0 || typeof current !== "object") return refPath;
|
|
203
|
+
}
|
|
204
|
+
const decoded = seg.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
205
|
+
current = current[Array.isArray(current) ? parseInt(decoded) : decoded];
|
|
206
|
+
resolvedSegments.push(seg);
|
|
207
|
+
}
|
|
208
|
+
return "#/" + resolvedSegments.join("/");
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Walks a JSON pointer path through a schema object, returning the value at that path.
|
|
212
|
+
*/
|
|
213
|
+
function walkPath(schema, path) {
|
|
214
|
+
if (!path.startsWith("#/")) return;
|
|
215
|
+
const segments = path.slice(2).split("/");
|
|
216
|
+
let current = schema;
|
|
217
|
+
for (const seg of segments) {
|
|
218
|
+
if (current === null || current === void 0 || typeof current !== "object") return;
|
|
219
|
+
const decoded = seg.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
220
|
+
current = current[Array.isArray(current) ? parseInt(decoded) : decoded];
|
|
221
|
+
}
|
|
222
|
+
return current;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Checks whether the given inventory entry is located inside a sub-schema that has its own $id.
|
|
226
|
+
* If so, root-relative JSON Pointer $refs placed at this location would be resolved against
|
|
227
|
+
* the $id base URI rather than the document root, making them invalid.
|
|
228
|
+
*/
|
|
229
|
+
function isInsideIdScope(inventory, entry) {
|
|
230
|
+
for (const other of inventory) {
|
|
231
|
+
if (other.pathFromRoot === "#" || other.pathFromRoot === "#/") continue;
|
|
232
|
+
if (entry.pathFromRoot.startsWith(other.pathFromRoot + "/")) {
|
|
233
|
+
if (other.value && typeof other.value === "object" && "$id" in other.value) return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
export { bundle as default };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { cwd, resolve } from "./util/url.js";
|
|
2
|
+
import { TimeoutError } from "./util/errors.js";
|
|
3
|
+
import { getSchemaBasePath } from "./util/schema-resources.js";
|
|
4
|
+
import Pointer from "./pointer.js";
|
|
5
|
+
import $Ref from "./ref.js";
|
|
6
|
+
//#region ../../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
|
|
7
|
+
var dereference_default = dereference;
|
|
8
|
+
/**
|
|
9
|
+
* Crawls the JSON schema, finds all JSON references, and dereferences them.
|
|
10
|
+
* This method mutates the JSON schema object, replacing JSON references with their resolved value.
|
|
11
|
+
*
|
|
12
|
+
* @param parser
|
|
13
|
+
* @param options
|
|
14
|
+
*/
|
|
15
|
+
function dereference(parser, options) {
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
const rootScopeBase = parser.$refs._root$Ref.dynamicIdScope ? getSchemaBasePath(parser.$refs._root$Ref.path, parser.schema) : parser.$refs._root$Ref.path;
|
|
18
|
+
const dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, rootScopeBase, parser.$refs._root$Ref.dynamicIdScope, "#", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), /* @__PURE__ */ new Map(), parser.$refs, options, start, 0);
|
|
19
|
+
parser.$refs.circular = dereferenced.circular;
|
|
20
|
+
parser.schema = dereferenced.value;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Recursively crawls the given value, and dereferences any JSON references.
|
|
24
|
+
*
|
|
25
|
+
* @param obj - The value to crawl. If it's not an object or array, it will be ignored.
|
|
26
|
+
* @param path - The full path of `obj`, possibly with a JSON Pointer in the hash
|
|
27
|
+
* @param pathFromRoot - The path of `obj` from the schema root
|
|
28
|
+
* @param parents - An array of the parent objects that have already been dereferenced
|
|
29
|
+
* @param processedObjects - An array of all the objects that have already been processed
|
|
30
|
+
* @param dereferencedCache - An map of all the dereferenced objects
|
|
31
|
+
* @param $refs
|
|
32
|
+
* @param options
|
|
33
|
+
* @param startTime - The time when the dereferencing started
|
|
34
|
+
* @param depth - The current recursion depth
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function crawl(obj, path, scopeBase, dynamicIdScope, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth) {
|
|
38
|
+
let dereferenced;
|
|
39
|
+
const result = {
|
|
40
|
+
value: obj,
|
|
41
|
+
circular: false
|
|
42
|
+
};
|
|
43
|
+
checkDereferenceTimeout(startTime, options);
|
|
44
|
+
const derefOptions = options.dereference || {};
|
|
45
|
+
const maxDepth = derefOptions.maxDepth ?? 500;
|
|
46
|
+
if (depth > maxDepth) throw new RangeError(`Maximum dereference depth (${maxDepth}) exceeded at ${pathFromRoot}. This likely indicates an extremely deep or recursive schema. You can increase this limit with the dereference.maxDepth option.`);
|
|
47
|
+
const isExcludedPath = derefOptions.excludedPathMatcher || (() => false);
|
|
48
|
+
if (derefOptions?.circular === "ignore" || !processedObjects.has(obj)) {
|
|
49
|
+
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
|
|
50
|
+
parents.add(obj);
|
|
51
|
+
processedObjects.add(obj);
|
|
52
|
+
const currentScopeBase = scopeBase;
|
|
53
|
+
if ($Ref.isAllowed$Ref(obj, options)) {
|
|
54
|
+
dereferenced = dereference$Ref(obj, path, currentScopeBase, dynamicIdScope, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth);
|
|
55
|
+
result.circular = dereferenced.circular;
|
|
56
|
+
result.value = dereferenced.value;
|
|
57
|
+
} else for (const key of Object.keys(obj)) {
|
|
58
|
+
checkDereferenceTimeout(startTime, options);
|
|
59
|
+
const keyPath = Pointer.join(path, key);
|
|
60
|
+
const keyPathFromRoot = Pointer.join(pathFromRoot, key);
|
|
61
|
+
if (isExcludedPath(keyPathFromRoot)) continue;
|
|
62
|
+
const value = obj[key];
|
|
63
|
+
const childScopeBase = dynamicIdScope && value && typeof value === "object" && !ArrayBuffer.isView(value) ? getSchemaBasePath(currentScopeBase, value) : currentScopeBase;
|
|
64
|
+
let circular;
|
|
65
|
+
if ($Ref.isAllowed$Ref(value, options)) {
|
|
66
|
+
dereferenced = dereference$Ref(value, keyPath, childScopeBase, dynamicIdScope, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth);
|
|
67
|
+
circular = dereferenced.circular;
|
|
68
|
+
if (obj[key] !== dereferenced.value) {
|
|
69
|
+
const preserved = /* @__PURE__ */ new Map();
|
|
70
|
+
if (derefOptions?.preservedProperties) {
|
|
71
|
+
if (typeof obj[key] === "object" && !Array.isArray(obj[key])) derefOptions?.preservedProperties.forEach((prop) => {
|
|
72
|
+
if (prop in obj[key]) preserved.set(prop, obj[key][prop]);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
let assignedValue = dereferenced.value;
|
|
76
|
+
if (derefOptions?.cloneReferences && !circular && assignedValue && typeof assignedValue === "object") assignedValue = structuredClone(assignedValue);
|
|
77
|
+
obj[key] = assignedValue;
|
|
78
|
+
if (derefOptions?.preservedProperties) {
|
|
79
|
+
if (preserved.size && typeof obj[key] === "object" && !Array.isArray(obj[key])) preserved.forEach((value, prop) => {
|
|
80
|
+
obj[key][prop] = value;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
derefOptions?.onDereference?.(value.$ref, obj[key], obj, key);
|
|
84
|
+
}
|
|
85
|
+
} else if (!parents.has(value)) {
|
|
86
|
+
dereferenced = crawl(value, keyPath, childScopeBase, dynamicIdScope, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth + 1);
|
|
87
|
+
circular = dereferenced.circular;
|
|
88
|
+
if (obj[key] !== dereferenced.value) obj[key] = dereferenced.value;
|
|
89
|
+
} else circular = foundCircularReference(keyPath, $refs, options);
|
|
90
|
+
result.circular = result.circular || circular;
|
|
91
|
+
}
|
|
92
|
+
parents.delete(obj);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Dereferences the given JSON Reference, and then crawls the resulting value.
|
|
99
|
+
*
|
|
100
|
+
* @param $ref - The JSON Reference to resolve
|
|
101
|
+
* @param path - The full path of `$ref`, possibly with a JSON Pointer in the hash
|
|
102
|
+
* @param pathFromRoot - The path of `$ref` from the schema root
|
|
103
|
+
* @param parents - An array of the parent objects that have already been dereferenced
|
|
104
|
+
* @param processedObjects - An array of all the objects that have already been dereferenced
|
|
105
|
+
* @param dereferencedCache - An map of all the dereferenced objects
|
|
106
|
+
* @param $refs
|
|
107
|
+
* @param options
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
function dereference$Ref($ref, path, scopeBase, dynamicIdScope, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth) {
|
|
111
|
+
const $refPath = resolve($Ref.isExternal$Ref($ref) && options?.dereference?.externalReferenceResolution === "root" ? cwd() : dynamicIdScope ? scopeBase : path, $ref.$ref);
|
|
112
|
+
const cache = dereferencedCache.get($refPath);
|
|
113
|
+
if (cache) {
|
|
114
|
+
if (!cache.circular) {
|
|
115
|
+
const refKeys = Object.keys($ref);
|
|
116
|
+
if (refKeys.length > 1) {
|
|
117
|
+
const extraKeys = {};
|
|
118
|
+
for (const key of refKeys) if (key !== "$ref" && !(key in cache.value)) extraKeys[key] = $ref[key];
|
|
119
|
+
return {
|
|
120
|
+
circular: cache.circular,
|
|
121
|
+
value: Object.assign({}, cache.value, extraKeys)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return cache;
|
|
125
|
+
}
|
|
126
|
+
if (typeof cache.value === "object" && "$ref" in cache.value && "$ref" in $ref) {
|
|
127
|
+
if (cache.value.$ref === $ref.$ref) {
|
|
128
|
+
foundCircularReference(path, $refs, options);
|
|
129
|
+
return cache;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
foundCircularReference(path, $refs, options);
|
|
133
|
+
return cache;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const pointer = $refs._resolve($refPath, path, options);
|
|
137
|
+
if (pointer === null) return {
|
|
138
|
+
circular: false,
|
|
139
|
+
value: null
|
|
140
|
+
};
|
|
141
|
+
const directCircular = pointer.circular;
|
|
142
|
+
let circular = directCircular || parents.has(pointer.value);
|
|
143
|
+
if (circular) foundCircularReference(path, $refs, options);
|
|
144
|
+
let dereferencedValue = $Ref.dereference($ref, pointer.value, options);
|
|
145
|
+
if (!circular) {
|
|
146
|
+
const dereferenced = crawl(dereferencedValue, pointer.path, pointer.$ref.path, pointer.$ref.dynamicIdScope, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options, startTime, depth + 1);
|
|
147
|
+
circular = dereferenced.circular;
|
|
148
|
+
dereferencedValue = dereferenced.value;
|
|
149
|
+
}
|
|
150
|
+
if (circular && !directCircular && options.dereference?.circular === "ignore") dereferencedValue = $ref;
|
|
151
|
+
if (directCircular) dereferencedValue.$ref = pathFromRoot;
|
|
152
|
+
const dereferencedObject = {
|
|
153
|
+
circular,
|
|
154
|
+
value: dereferencedValue
|
|
155
|
+
};
|
|
156
|
+
if (Object.keys($ref).length === 1) dereferencedCache.set($refPath, dereferencedObject);
|
|
157
|
+
return dereferencedObject;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if we've run past our allowed timeout and throw an error if we have.
|
|
161
|
+
*
|
|
162
|
+
* @param startTime - The time when the dereferencing started.
|
|
163
|
+
* @param options
|
|
164
|
+
*/
|
|
165
|
+
function checkDereferenceTimeout(startTime, options) {
|
|
166
|
+
if (options && options.timeoutMs) {
|
|
167
|
+
if (Date.now() - startTime > options.timeoutMs) throw new TimeoutError(options.timeoutMs);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Called when a circular reference is found.
|
|
172
|
+
* It sets the {@link $Refs#circular} flag, executes the options.dereference.onCircular callback,
|
|
173
|
+
* and throws an error if options.dereference.circular is false.
|
|
174
|
+
*
|
|
175
|
+
* @param keyPath - The JSON Reference path of the circular reference
|
|
176
|
+
* @param $refs
|
|
177
|
+
* @param options
|
|
178
|
+
* @returns - always returns true, to indicate that a circular reference was found
|
|
179
|
+
*/
|
|
180
|
+
function foundCircularReference(keyPath, $refs, options) {
|
|
181
|
+
$refs.circular = true;
|
|
182
|
+
options?.dereference?.onCircular?.(keyPath);
|
|
183
|
+
if (!options.dereference.circular) throw /* @__PURE__ */ new ReferenceError(`Circular $ref pointer found at ${keyPath}`);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
export { dereference_default as default };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { $RefsCallback, FileInfo, HTTPResolverOptions, JSONSchema, Plugin, ResolverOptions, SchemaCallback } from "./types/index.js";
|
|
2
|
+
import { ParserOptions } from "./options.js";
|
|
3
|
+
import { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
|
|
4
|
+
import { $Refs } from "./refs.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../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
|
|
7
|
+
/**
|
|
8
|
+
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
|
9
|
+
* and provides methods for traversing, manipulating, and dereferencing those references.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
*/
|
|
13
|
+
declare class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
14
|
+
/**
|
|
15
|
+
* The parsed (and possibly dereferenced) JSON schema object
|
|
16
|
+
*
|
|
17
|
+
* @type {object}
|
|
18
|
+
* @readonly
|
|
19
|
+
*/
|
|
20
|
+
schema: S | null;
|
|
21
|
+
/**
|
|
22
|
+
* The resolved JSON references
|
|
23
|
+
*
|
|
24
|
+
* @type {$Refs}
|
|
25
|
+
* @readonly
|
|
26
|
+
*/
|
|
27
|
+
$refs: $Refs<S, O>;
|
|
28
|
+
/**
|
|
29
|
+
* Parses the given JSON schema.
|
|
30
|
+
* This method does not resolve any JSON references.
|
|
31
|
+
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
|
32
|
+
*
|
|
33
|
+
* @param [path] - The file path or URL of the JSON schema
|
|
34
|
+
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
35
|
+
* @param [options] - Options that determine how the schema is parsed
|
|
36
|
+
* @param [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
|
37
|
+
* @returns - The returned promise resolves with the parsed JSON schema object.
|
|
38
|
+
*/
|
|
39
|
+
parse(schema: S | string | unknown): Promise<S>;
|
|
40
|
+
parse(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
41
|
+
parse(schema: S | string | unknown, options: O): Promise<S>;
|
|
42
|
+
parse(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
43
|
+
parse(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
44
|
+
parse(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
45
|
+
static parse<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
|
|
46
|
+
static parse<S extends object = JSONSchema>(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
47
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O): Promise<S>;
|
|
48
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
49
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
50
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
53
|
+
*
|
|
54
|
+
* Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
|
55
|
+
*
|
|
56
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#resolveschema-options-callback
|
|
57
|
+
*
|
|
58
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
59
|
+
* @param options (optional)
|
|
60
|
+
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
61
|
+
*/
|
|
62
|
+
resolve(schema: S | string | unknown): Promise<$Refs<S, O>>;
|
|
63
|
+
resolve(schema: S | string | unknown, callback: $RefsCallback<S, O>): Promise<void>;
|
|
64
|
+
resolve(schema: S | string | unknown, options: O): Promise<$Refs<S, O>>;
|
|
65
|
+
resolve(schema: S | string | unknown, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
66
|
+
resolve(path: string, schema: S | string | unknown, options: O): Promise<$Refs<S, O>>;
|
|
67
|
+
resolve(path: string, schema: S | string | unknown, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
70
|
+
*
|
|
71
|
+
* Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
|
72
|
+
*
|
|
73
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#resolveschema-options-callback
|
|
74
|
+
*
|
|
75
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
76
|
+
* @param options (optional)
|
|
77
|
+
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
78
|
+
*/
|
|
79
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown): Promise<$Refs<S, O>>;
|
|
80
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, callback: $RefsCallback<S, O>): Promise<void>;
|
|
81
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O): Promise<$Refs<S, O>>;
|
|
82
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
83
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O): Promise<$Refs<S, O>>;
|
|
84
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
|
87
|
+
*
|
|
88
|
+
* This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
|
|
89
|
+
*
|
|
90
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#bundleschema-options-callback
|
|
91
|
+
*
|
|
92
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
93
|
+
* @param options (optional)
|
|
94
|
+
* @param callback (optional) A callback that will receive the bundled schema object
|
|
95
|
+
*/
|
|
96
|
+
static bundle<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
|
|
97
|
+
static bundle<S extends object = JSONSchema>(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
98
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O): Promise<S>;
|
|
99
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
100
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
101
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<S>;
|
|
102
|
+
/**
|
|
103
|
+
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
|
104
|
+
*
|
|
105
|
+
* This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
|
|
106
|
+
*
|
|
107
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#bundleschema-options-callback
|
|
108
|
+
*
|
|
109
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
110
|
+
* @param options (optional)
|
|
111
|
+
* @param callback (optional) A callback that will receive the bundled schema object
|
|
112
|
+
*/
|
|
113
|
+
bundle(schema: S | string | unknown): Promise<S>;
|
|
114
|
+
bundle(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
115
|
+
bundle(schema: S | string | unknown, options: O): Promise<S>;
|
|
116
|
+
bundle(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
117
|
+
bundle(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
118
|
+
bundle(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
|
121
|
+
*
|
|
122
|
+
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the schema using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
|
123
|
+
*
|
|
124
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback
|
|
125
|
+
*
|
|
126
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
127
|
+
* @param options (optional)
|
|
128
|
+
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
129
|
+
*/
|
|
130
|
+
static dereference<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
|
|
131
|
+
static dereference<S extends object = JSONSchema>(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
132
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O): Promise<S>;
|
|
133
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
134
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
135
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
|
138
|
+
*
|
|
139
|
+
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the schema using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
|
140
|
+
*
|
|
141
|
+
* See https://apidevtools.com/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback
|
|
142
|
+
*
|
|
143
|
+
* @param path
|
|
144
|
+
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
145
|
+
* @param options (optional)
|
|
146
|
+
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
147
|
+
*/
|
|
148
|
+
dereference(path: string, schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
149
|
+
dereference(schema: S | string | unknown, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
150
|
+
dereference(schema: S | string | unknown, callback: SchemaCallback<S>): Promise<void>;
|
|
151
|
+
dereference(path: string, schema: S | string | unknown, options: O): Promise<S>;
|
|
152
|
+
dereference(schema: S | string | unknown, options: O): Promise<S>;
|
|
153
|
+
dereference(schema: S | string | unknown): Promise<S>;
|
|
154
|
+
}
|
|
155
|
+
declare const bundle: typeof $RefParser.bundle;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { bundle };
|