@scalar/openapi-parser 0.10.15 → 0.10.17
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/CHANGELOG.md +12 -0
- package/README.md +0 -22
- package/dist/configuration/index.js +19 -22
- package/dist/configuration/index.js.map +7 -0
- package/dist/declarations.d.js +1 -0
- package/dist/declarations.d.js.map +7 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -29
- package/dist/index.js.map +7 -0
- package/dist/lib/Validator/Validator.d.ts +2 -2
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +99 -119
- package/dist/lib/Validator/Validator.js.map +7 -0
- package/dist/lib/Validator/Validator.test.js +8 -0
- package/dist/lib/Validator/Validator.test.js.map +7 -0
- package/dist/lib/Validator/index.d.ts +2 -2
- package/dist/lib/Validator/index.d.ts.map +1 -1
- package/dist/lib/Validator/index.js +3 -0
- package/dist/lib/Validator/index.js.map +7 -0
- package/dist/plugins/fetch-urls/fetchUrls.d.ts +1 -2
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.js +36 -111
- package/dist/plugins/fetch-urls/fetchUrls.js.map +7 -0
- package/dist/plugins/fetch-urls/fetchUrls.test.js +50 -0
- package/dist/plugins/fetch-urls/fetchUrls.test.js.map +7 -0
- package/dist/plugins/fetch-urls/index.d.ts +1 -1
- package/dist/plugins/fetch-urls/index.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/index.js +2 -1
- package/dist/plugins/fetch-urls/index.js.map +7 -0
- package/dist/plugins/read-files/index.d.ts +1 -1
- package/dist/plugins/read-files/index.d.ts.map +1 -1
- package/dist/plugins/read-files/index.js +2 -1
- package/dist/plugins/read-files/index.js.map +7 -0
- package/dist/plugins/read-files/readFiles.d.ts +1 -1
- package/dist/plugins/read-files/readFiles.d.ts.map +1 -1
- package/dist/plugins/read-files/readFiles.js +50 -70
- package/dist/plugins/read-files/readFiles.js.map +7 -0
- package/dist/plugins/read-files/readFiles.test.js +20 -0
- package/dist/plugins/read-files/readFiles.test.js.map +7 -0
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +5 -0
- package/dist/polyfills/index.js.map +7 -0
- package/dist/polyfills/path.js +155 -98
- package/dist/polyfills/path.js.map +7 -0
- package/dist/schemas/v2.0/schema.d.ts +1405 -0
- package/dist/schemas/v2.0/schema.d.ts.map +1 -0
- package/dist/schemas/v2.0/schema.js +1463 -0
- package/dist/schemas/v2.0/schema.js.map +7 -0
- package/dist/schemas/v3.0/schema.d.ts +1264 -0
- package/dist/schemas/v3.0/schema.d.ts.map +1 -0
- package/dist/schemas/v3.0/schema.js +1493 -0
- package/dist/schemas/v3.0/schema.js.map +7 -0
- package/dist/schemas/v3.1/schema.d.ts +1225 -0
- package/dist/schemas/v3.1/schema.d.ts.map +1 -0
- package/dist/schemas/v3.1/schema.js +1296 -0
- package/dist/schemas/v3.1/schema.js.map +7 -0
- package/dist/types/index.d.ts +5 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/helpers.js +88 -93
- package/dist/utils/betterAjvErrors/helpers.js.map +7 -0
- package/dist/utils/betterAjvErrors/index.js +14 -13
- package/dist/utils/betterAjvErrors/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.js +27 -0
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/index.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/index.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/index.js +5 -0
- package/dist/utils/betterAjvErrors/json/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/json/utils.d.ts +2 -0
- package/dist/utils/betterAjvErrors/json/utils.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/json/utils.js +11 -0
- package/dist/utils/betterAjvErrors/json/utils.js.map +7 -0
- package/dist/utils/betterAjvErrors/utils.js +21 -14
- package/dist/utils/betterAjvErrors/utils.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +23 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.js +6 -10
- package/dist/utils/betterAjvErrors/validation-errors/base.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/default.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +11 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +19 -29
- package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.js +15 -0
- package/dist/utils/betterAjvErrors/validation-errors/index.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/required.js.map +7 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +10 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +8 -9
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +7 -0
- package/dist/utils/dereference.d.ts +2 -2
- package/dist/utils/dereference.d.ts.map +1 -1
- package/dist/utils/dereference.js +17 -19
- package/dist/utils/dereference.js.map +7 -0
- package/dist/utils/dereference.test.js +300 -0
- package/dist/utils/dereference.test.js.map +7 -0
- package/dist/utils/details.d.ts +1 -1
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +26 -28
- package/dist/utils/details.js.map +7 -0
- package/dist/utils/errors.test.js +48 -0
- package/dist/utils/errors.test.js.map +7 -0
- package/dist/utils/escapeJsonPointer.js +5 -8
- package/dist/utils/escapeJsonPointer.js.map +7 -0
- package/dist/utils/escapeJsonPointer.test.js +11 -0
- package/dist/utils/escapeJsonPointer.test.js.map +7 -0
- package/dist/utils/filter.d.ts +1 -1
- package/dist/utils/filter.d.ts.map +1 -1
- package/dist/utils/filter.js +13 -15
- package/dist/utils/filter.js.map +7 -0
- package/dist/utils/getEntrypoint.d.ts +1 -1
- package/dist/utils/getEntrypoint.d.ts.map +1 -1
- package/dist/utils/getEntrypoint.js +5 -6
- package/dist/utils/getEntrypoint.js.map +7 -0
- package/dist/utils/getEntrypoint.test.js +18 -0
- package/dist/utils/getEntrypoint.test.js.map +7 -0
- package/dist/utils/getListOfReferences.d.ts +1 -1
- package/dist/utils/getListOfReferences.d.ts.map +1 -1
- package/dist/utils/getListOfReferences.js +15 -22
- package/dist/utils/getListOfReferences.js.map +7 -0
- package/dist/utils/getSegmentsFromPath.js +8 -15
- package/dist/utils/getSegmentsFromPath.js.map +7 -0
- package/dist/utils/getSegmentsFromPath.test.js +13 -0
- package/dist/utils/getSegmentsFromPath.test.js.map +7 -0
- package/dist/utils/index.d.ts +26 -26
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +27 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/isFilesystem.d.ts +1 -2
- package/dist/utils/isFilesystem.d.ts.map +1 -1
- package/dist/utils/isFilesystem.js +5 -9
- package/dist/utils/isFilesystem.js.map +7 -0
- package/dist/utils/isJson.js +10 -9
- package/dist/utils/isJson.js.map +7 -0
- package/dist/utils/isObject.js +5 -6
- package/dist/utils/isObject.js.map +7 -0
- package/dist/utils/isObject.test.js +23 -0
- package/dist/utils/isObject.test.js.map +7 -0
- package/dist/utils/isYaml.js +16 -17
- package/dist/utils/isYaml.js.map +7 -0
- package/dist/utils/load/index.d.ts +1 -1
- package/dist/utils/load/index.d.ts.map +1 -1
- package/dist/utils/load/index.js +2 -0
- package/dist/utils/load/index.js.map +7 -0
- package/dist/utils/load/load.d.ts +3 -12
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +89 -149
- package/dist/utils/load/load.js.map +7 -0
- package/dist/utils/load/load.test.js +361 -0
- package/dist/utils/load/load.test.js.map +7 -0
- package/dist/utils/makeFilesystem.d.ts +2 -19
- package/dist/utils/makeFilesystem.d.ts.map +1 -1
- package/dist/utils/makeFilesystem.js +20 -68
- package/dist/utils/makeFilesystem.js.map +7 -0
- package/dist/utils/makeFilesystem.test.js +15 -0
- package/dist/utils/makeFilesystem.test.js.map +7 -0
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +22 -27
- package/dist/utils/normalize.js.map +7 -0
- package/dist/utils/normalize.test.js +88 -0
- package/dist/utils/normalize.test.js.map +7 -0
- package/dist/utils/openapi/actions/details.d.ts +2 -2
- package/dist/utils/openapi/actions/details.d.ts.map +1 -1
- package/dist/utils/openapi/actions/details.js +9 -11
- package/dist/utils/openapi/actions/details.js.map +7 -0
- package/dist/utils/openapi/actions/files.d.ts +1 -1
- package/dist/utils/openapi/actions/files.d.ts.map +1 -1
- package/dist/utils/openapi/actions/files.js +7 -9
- package/dist/utils/openapi/actions/files.js.map +7 -0
- package/dist/utils/openapi/actions/get.d.ts +1 -1
- package/dist/utils/openapi/actions/get.d.ts.map +1 -1
- package/dist/utils/openapi/actions/get.js +9 -11
- package/dist/utils/openapi/actions/get.js.map +7 -0
- package/dist/utils/openapi/actions/toJson.d.ts +1 -1
- package/dist/utils/openapi/actions/toJson.d.ts.map +1 -1
- package/dist/utils/openapi/actions/toJson.js +9 -11
- package/dist/utils/openapi/actions/toJson.js.map +7 -0
- package/dist/utils/openapi/actions/toYaml.d.ts +1 -1
- package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -1
- package/dist/utils/openapi/actions/toYaml.js +9 -11
- package/dist/utils/openapi/actions/toYaml.js.map +7 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts +5 -5
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/dereferenceCommand.js +25 -27
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts +9 -9
- package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/filterCommand.js +24 -26
- package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts +1174 -1174
- package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/loadCommand.js +40 -42
- package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts +311 -311
- package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/upgradeCommand.js +27 -29
- package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts +311 -311
- package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -1
- package/dist/utils/openapi/commands/validateCommand.js +31 -33
- package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
- package/dist/utils/openapi/index.d.ts +1 -1
- package/dist/utils/openapi/index.d.ts.map +1 -1
- package/dist/utils/openapi/index.js +2 -0
- package/dist/utils/openapi/index.js.map +7 -0
- package/dist/utils/openapi/openapi.d.ts +700 -700
- package/dist/utils/openapi/openapi.d.ts.map +1 -1
- package/dist/utils/openapi/openapi.js +13 -16
- package/dist/utils/openapi/openapi.js.map +7 -0
- package/dist/utils/openapi/openapi.test-d.js +14 -0
- package/dist/utils/openapi/openapi.test-d.js.map +7 -0
- package/dist/utils/openapi/openapi.test.js +309 -0
- package/dist/utils/openapi/openapi.test.js.map +7 -0
- package/dist/utils/openapi/utils/queueTask.d.ts +1 -1
- package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -1
- package/dist/utils/openapi/utils/queueTask.js +8 -9
- package/dist/utils/openapi/utils/queueTask.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts +1 -1
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
- package/dist/utils/openapi/utils/workThroughQueue.js +49 -64
- package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.test.js +244 -0
- package/dist/utils/openapi/utils/workThroughQueue.test.js.map +7 -0
- package/dist/utils/resolveReferences.d.ts +1 -7
- package/dist/utils/resolveReferences.d.ts.map +1 -1
- package/dist/utils/resolveReferences.js +91 -149
- package/dist/utils/resolveReferences.js.map +7 -0
- package/dist/utils/resolveReferences.test.js +567 -0
- package/dist/utils/resolveReferences.test.js.map +7 -0
- package/dist/utils/toJson.d.ts +1 -1
- package/dist/utils/toJson.d.ts.map +1 -1
- package/dist/utils/toJson.js +4 -2
- package/dist/utils/toJson.js.map +7 -0
- package/dist/utils/toYaml.d.ts +1 -1
- package/dist/utils/toYaml.d.ts.map +1 -1
- package/dist/utils/toYaml.js +5 -4
- package/dist/utils/toYaml.js.map +7 -0
- package/dist/utils/transform/index.d.ts +1 -1
- package/dist/utils/transform/index.d.ts.map +1 -1
- package/dist/utils/transform/index.js +2 -0
- package/dist/utils/transform/index.js.map +7 -0
- package/dist/utils/transform/sanitize.d.ts +3 -3
- package/dist/utils/transform/sanitize.d.ts.map +1 -1
- package/dist/utils/transform/sanitize.js +22 -21
- package/dist/utils/transform/sanitize.js.map +7 -0
- package/dist/utils/transform/sanitize.test.js +148 -0
- package/dist/utils/transform/sanitize.test.js.map +7 -0
- package/dist/utils/transform/utils/addInfoObject.d.ts +1 -1
- package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
- package/dist/utils/transform/utils/addInfoObject.js +14 -10
- package/dist/utils/transform/utils/addInfoObject.js.map +7 -0
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js +8 -5
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +7 -0
- package/dist/utils/transform/utils/addMissingTags.d.ts +1 -1
- package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
- package/dist/utils/transform/utils/addMissingTags.js +26 -27
- package/dist/utils/transform/utils/addMissingTags.js.map +7 -0
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js +36 -40
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +7 -0
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js +8 -6
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +7 -0
- package/dist/utils/transformErrors.d.ts +1 -1
- package/dist/utils/transformErrors.d.ts.map +1 -1
- package/dist/utils/transformErrors.js +18 -21
- package/dist/utils/transformErrors.js.map +7 -0
- package/dist/utils/transformErrors.test.js +17 -0
- package/dist/utils/transformErrors.test.js.map +7 -0
- package/dist/utils/traverse.d.ts +1 -1
- package/dist/utils/traverse.d.ts.map +1 -1
- package/dist/utils/traverse.js +19 -22
- package/dist/utils/traverse.js.map +7 -0
- package/dist/utils/traverse.test.js +68 -0
- package/dist/utils/traverse.test.js.map +7 -0
- package/dist/utils/unescapeJsonPointer.js +5 -9
- package/dist/utils/unescapeJsonPointer.js.map +7 -0
- package/dist/utils/unescapeJsonPointer.test.js +19 -0
- package/dist/utils/unescapeJsonPointer.test.js.map +7 -0
- package/dist/utils/upgrade.d.ts +1 -1
- package/dist/utils/upgrade.d.ts.map +1 -1
- package/dist/utils/upgrade.js +22 -22
- package/dist/utils/upgrade.js.map +7 -0
- package/dist/utils/upgrade.test-d.js +16 -0
- package/dist/utils/upgrade.test-d.js.map +7 -0
- package/dist/utils/upgrade.test.js +57 -0
- package/dist/utils/upgrade.test.js.map +7 -0
- package/dist/utils/upgradeFromThreeToThreeOne.js +114 -140
- package/dist/utils/upgradeFromThreeToThreeOne.js.map +7 -0
- package/dist/utils/upgradeFromThreeToThreeOne.test.js +462 -0
- package/dist/utils/upgradeFromThreeToThreeOne.test.js.map +7 -0
- package/dist/utils/upgradeFromTwoToThree.js +212 -219
- package/dist/utils/upgradeFromTwoToThree.js.map +7 -0
- package/dist/utils/upgradeFromTwoToThree.test.js +589 -0
- package/dist/utils/upgradeFromTwoToThree.test.js.map +7 -0
- package/dist/utils/validate.d.ts +1 -1
- package/dist/utils/validate.d.ts.map +1 -1
- package/dist/utils/validate.js +14 -16
- package/dist/utils/validate.js.map +7 -0
- package/dist/utils/validate.test.js +64 -0
- package/dist/utils/validate.test.js.map +7 -0
- package/package.json +6 -8
- package/dist/schemas/v2.0/schema.json.js +0 -1623
- package/dist/schemas/v3.0/schema.json.js +0 -1673
- package/dist/schemas/v3.1/schema.json.js +0 -1451
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { workThroughQueue } from "./workThroughQueue.js";
|
|
3
|
+
describe("workThroughQueue", () => {
|
|
4
|
+
it("loads a specification", async () => {
|
|
5
|
+
const result = workThroughQueue({
|
|
6
|
+
input: {
|
|
7
|
+
openapi: "3.1.0",
|
|
8
|
+
info: {
|
|
9
|
+
title: "Hello World",
|
|
10
|
+
version: "1.0.0"
|
|
11
|
+
},
|
|
12
|
+
paths: {}
|
|
13
|
+
},
|
|
14
|
+
specification: {
|
|
15
|
+
openapi: "3.1.1",
|
|
16
|
+
info: {
|
|
17
|
+
title: "Hello World",
|
|
18
|
+
version: "1.0.0"
|
|
19
|
+
},
|
|
20
|
+
paths: {}
|
|
21
|
+
},
|
|
22
|
+
tasks: [
|
|
23
|
+
{
|
|
24
|
+
name: "load"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
expect(await result).toStrictEqual({
|
|
29
|
+
errors: [],
|
|
30
|
+
specification: {
|
|
31
|
+
info: {
|
|
32
|
+
title: "Hello World",
|
|
33
|
+
version: "1.0.0"
|
|
34
|
+
},
|
|
35
|
+
openapi: "3.1.0",
|
|
36
|
+
paths: {}
|
|
37
|
+
},
|
|
38
|
+
filesystem: [
|
|
39
|
+
{
|
|
40
|
+
dir: "./",
|
|
41
|
+
filename: null,
|
|
42
|
+
isEntrypoint: true,
|
|
43
|
+
references: [],
|
|
44
|
+
specification: {
|
|
45
|
+
info: {
|
|
46
|
+
title: "Hello World",
|
|
47
|
+
version: "1.0.0"
|
|
48
|
+
},
|
|
49
|
+
openapi: "3.1.0",
|
|
50
|
+
paths: {}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it("validates a specification", async () => {
|
|
57
|
+
const result = workThroughQueue({
|
|
58
|
+
input: {
|
|
59
|
+
openapi: "3.1.0",
|
|
60
|
+
info: {
|
|
61
|
+
title: "Hello World",
|
|
62
|
+
version: "1.0.0"
|
|
63
|
+
},
|
|
64
|
+
paths: {}
|
|
65
|
+
},
|
|
66
|
+
specification: {
|
|
67
|
+
openapi: "3.1.0",
|
|
68
|
+
info: {
|
|
69
|
+
title: "Hello World",
|
|
70
|
+
version: "1.0.0"
|
|
71
|
+
},
|
|
72
|
+
paths: {}
|
|
73
|
+
},
|
|
74
|
+
tasks: [
|
|
75
|
+
{
|
|
76
|
+
name: "load"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "validate"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
expect(await result).toStrictEqual({
|
|
84
|
+
errors: [],
|
|
85
|
+
valid: true,
|
|
86
|
+
version: "3.1",
|
|
87
|
+
filesystem: [
|
|
88
|
+
{
|
|
89
|
+
dir: "./",
|
|
90
|
+
filename: null,
|
|
91
|
+
isEntrypoint: true,
|
|
92
|
+
references: [],
|
|
93
|
+
specification: {
|
|
94
|
+
info: {
|
|
95
|
+
title: "Hello World",
|
|
96
|
+
version: "1.0.0"
|
|
97
|
+
},
|
|
98
|
+
openapi: "3.1.0",
|
|
99
|
+
paths: {}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
specification: {
|
|
104
|
+
openapi: "3.1.0",
|
|
105
|
+
info: {
|
|
106
|
+
title: "Hello World",
|
|
107
|
+
version: "1.0.0"
|
|
108
|
+
},
|
|
109
|
+
paths: {}
|
|
110
|
+
},
|
|
111
|
+
schema: {
|
|
112
|
+
info: {
|
|
113
|
+
title: "Hello World",
|
|
114
|
+
version: "1.0.0"
|
|
115
|
+
},
|
|
116
|
+
openapi: "3.1.0",
|
|
117
|
+
paths: {}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it("dereferences a specification", async () => {
|
|
122
|
+
const result = workThroughQueue({
|
|
123
|
+
input: {
|
|
124
|
+
openapi: "3.1.0",
|
|
125
|
+
info: {
|
|
126
|
+
title: "Hello World",
|
|
127
|
+
version: "1.0.0"
|
|
128
|
+
},
|
|
129
|
+
paths: {}
|
|
130
|
+
},
|
|
131
|
+
specification: {
|
|
132
|
+
openapi: "3.1.0",
|
|
133
|
+
info: {
|
|
134
|
+
title: "Hello World",
|
|
135
|
+
version: "1.0.0"
|
|
136
|
+
},
|
|
137
|
+
paths: {}
|
|
138
|
+
},
|
|
139
|
+
tasks: [
|
|
140
|
+
{
|
|
141
|
+
name: "load"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "dereference"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
});
|
|
148
|
+
expect(await result).toStrictEqual({
|
|
149
|
+
errors: [],
|
|
150
|
+
specificationType: "openapi",
|
|
151
|
+
specificationVersion: "3.1.0",
|
|
152
|
+
version: "3.1",
|
|
153
|
+
filesystem: [
|
|
154
|
+
{
|
|
155
|
+
dir: "./",
|
|
156
|
+
filename: null,
|
|
157
|
+
isEntrypoint: true,
|
|
158
|
+
references: [],
|
|
159
|
+
specification: {
|
|
160
|
+
info: {
|
|
161
|
+
title: "Hello World",
|
|
162
|
+
version: "1.0.0"
|
|
163
|
+
},
|
|
164
|
+
openapi: "3.1.0",
|
|
165
|
+
paths: {}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
specification: {
|
|
170
|
+
openapi: "3.1.0",
|
|
171
|
+
info: {
|
|
172
|
+
title: "Hello World",
|
|
173
|
+
version: "1.0.0"
|
|
174
|
+
},
|
|
175
|
+
paths: {}
|
|
176
|
+
},
|
|
177
|
+
schema: {
|
|
178
|
+
info: {
|
|
179
|
+
title: "Hello World",
|
|
180
|
+
version: "1.0.0"
|
|
181
|
+
},
|
|
182
|
+
openapi: "3.1.0",
|
|
183
|
+
paths: {}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
it("upgrades a specification", async () => {
|
|
188
|
+
const result = workThroughQueue({
|
|
189
|
+
input: {
|
|
190
|
+
openapi: "3.0.0",
|
|
191
|
+
info: {
|
|
192
|
+
title: "Hello World",
|
|
193
|
+
version: "1.0.0"
|
|
194
|
+
},
|
|
195
|
+
paths: {}
|
|
196
|
+
},
|
|
197
|
+
specification: {
|
|
198
|
+
openapi: "3.0.0",
|
|
199
|
+
info: {
|
|
200
|
+
title: "Hello World",
|
|
201
|
+
version: "1.0.0"
|
|
202
|
+
},
|
|
203
|
+
paths: {}
|
|
204
|
+
},
|
|
205
|
+
tasks: [
|
|
206
|
+
{
|
|
207
|
+
name: "load"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "upgrade"
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
});
|
|
214
|
+
expect(await result).toStrictEqual({
|
|
215
|
+
errors: [],
|
|
216
|
+
version: "3.1",
|
|
217
|
+
specification: {
|
|
218
|
+
openapi: "3.1.1",
|
|
219
|
+
info: {
|
|
220
|
+
title: "Hello World",
|
|
221
|
+
version: "1.0.0"
|
|
222
|
+
},
|
|
223
|
+
paths: {}
|
|
224
|
+
},
|
|
225
|
+
filesystem: [
|
|
226
|
+
{
|
|
227
|
+
dir: "./",
|
|
228
|
+
filename: null,
|
|
229
|
+
isEntrypoint: true,
|
|
230
|
+
references: [],
|
|
231
|
+
specification: {
|
|
232
|
+
info: {
|
|
233
|
+
title: "Hello World",
|
|
234
|
+
version: "1.0.0"
|
|
235
|
+
},
|
|
236
|
+
openapi: "3.1.1",
|
|
237
|
+
paths: {}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
//# sourceMappingURL=workThroughQueue.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/utils/openapi/utils/workThroughQueue.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { workThroughQueue } from './workThroughQueue'\n\ndescribe('workThroughQueue', () => {\n it('loads a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.1',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n })\n })\n\n it('validates a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'validate',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n valid: true,\n version: '3.1',\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n schema: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n })\n })\n\n it('dereferences a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'dereference',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n specificationType: 'openapi',\n specificationVersion: '3.1.0',\n version: '3.1',\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n schema: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n })\n })\n\n it('upgrades a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.0.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.0.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'upgrade',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n version: '3.1',\n specification: {\n openapi: '3.1.1',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.1',\n paths: {},\n },\n },\n ],\n })\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,wBAAwB;AAEj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,OAAO,CAAC;AAAA,MACV;AAAA,MACA,YAAY;AAAA,QACV;AAAA,UACE,KAAK;AAAA,UACL,UAAU;AAAA,UACV,cAAc;AAAA,UACd,YAAY,CAAC;AAAA,UACb,eAAe;AAAA,YACb,MAAM;AAAA,cACJ,OAAO;AAAA,cACP,SAAS;AAAA,YACX;AAAA,YACA,SAAS;AAAA,YACT,OAAO,CAAC;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAPI } from '@scalar/openapi-types';
|
|
2
|
-
import type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index.
|
|
2
|
+
import type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index.js';
|
|
3
3
|
export type ResolveReferencesResult = {
|
|
4
4
|
valid: boolean;
|
|
5
5
|
errors: ErrorObject[];
|
|
@@ -15,12 +15,6 @@ export type ResolveReferencesOptions = ThrowOnErrorOption & {
|
|
|
15
15
|
schema: AnyObject;
|
|
16
16
|
ref: string;
|
|
17
17
|
}) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to resolve internal references.
|
|
20
|
-
*
|
|
21
|
-
* @default true
|
|
22
|
-
*/
|
|
23
|
-
resolveInternalRefs?: boolean;
|
|
24
18
|
};
|
|
25
19
|
/**
|
|
26
20
|
* Takes a specification and resolves all references.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveReferences.d.ts","sourceRoot":"","sources":["../../src/utils/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"resolveReferences.d.ts","sourceRoot":"","sources":["../../src/utils/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAe7G,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACnE,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAE/B,KAAK,EAAE,SAAS,GAAG,UAAU,EAE7B,OAAO,CAAC,EAAE,wBAAwB,EAElC,IAAI,CAAC,EAAE,eAAe,EAEtB,MAAM,GAAE,WAAW,EAAO,GACzB,uBAAuB,CA0BzB"}
|
|
@@ -1,160 +1,102 @@
|
|
|
1
|
-
import { ERRORS } from
|
|
2
|
-
import { getEntrypoint } from
|
|
3
|
-
import { getSegmentsFromPath } from
|
|
4
|
-
import { makeFilesystem } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const clonedInput = structuredClone(input);
|
|
20
|
-
// Make it a filesystem, even if it’s just one file
|
|
21
|
-
const filesystem = makeFilesystem(clonedInput);
|
|
22
|
-
// Get the main file
|
|
23
|
-
const entrypoint = getEntrypoint(filesystem);
|
|
24
|
-
const finalInput = file?.content ?? entrypoint.content;
|
|
25
|
-
// Recursively resolve all references
|
|
26
|
-
dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options);
|
|
27
|
-
// Remove duplicats (according to message) from errors
|
|
28
|
-
errors = errors.filter((error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code));
|
|
29
|
-
// Return the resolved specification
|
|
30
|
-
return {
|
|
31
|
-
valid: errors.length === 0,
|
|
32
|
-
errors,
|
|
33
|
-
schema: finalInput,
|
|
34
|
-
};
|
|
1
|
+
import { ERRORS } from "../configuration/index.js";
|
|
2
|
+
import { getEntrypoint } from "./getEntrypoint.js";
|
|
3
|
+
import { getSegmentsFromPath } from "./getSegmentsFromPath.js";
|
|
4
|
+
import { makeFilesystem } from "./makeFilesystem.js";
|
|
5
|
+
function resolveReferences(input, options, file, errors = []) {
|
|
6
|
+
const clonedInput = structuredClone(input);
|
|
7
|
+
const filesystem = makeFilesystem(clonedInput);
|
|
8
|
+
const entrypoint = getEntrypoint(filesystem);
|
|
9
|
+
const finalInput = file?.specification ?? entrypoint.specification;
|
|
10
|
+
dereference(finalInput, filesystem, file ?? entrypoint, /* @__PURE__ */ new WeakSet(), errors, options);
|
|
11
|
+
errors = errors.filter(
|
|
12
|
+
(error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code)
|
|
13
|
+
);
|
|
14
|
+
return {
|
|
15
|
+
valid: errors.length === 0,
|
|
16
|
+
errors,
|
|
17
|
+
schema: finalInput
|
|
18
|
+
};
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
function dereference(schema, filesystem, entrypoint, resolvedSchemas, errors, options) {
|
|
21
|
+
if (schema === null || resolvedSchemas.has(schema)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
resolvedSchemas.add(schema);
|
|
25
|
+
function resolveExternal(externalFile) {
|
|
26
|
+
dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options);
|
|
27
|
+
return externalFile;
|
|
28
|
+
}
|
|
29
|
+
while (schema.$ref !== void 0) {
|
|
30
|
+
const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors);
|
|
31
|
+
if (typeof resolved !== "object" || resolved === null) {
|
|
32
|
+
break;
|
|
46
33
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
const dereferencedRef = schema.$ref;
|
|
35
|
+
delete schema.$ref;
|
|
36
|
+
for (const key of Object.keys(resolved)) {
|
|
37
|
+
if (schema[key] === void 0) {
|
|
38
|
+
schema[key] = resolved[key];
|
|
39
|
+
}
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Only if the option is set …
|
|
55
|
-
options?.resolveInternalRefs === false &&
|
|
56
|
-
// and it’s obviously internal
|
|
57
|
-
schema.$ref?.startsWith('#');
|
|
58
|
-
if (skipReference) {
|
|
59
|
-
return;
|
|
41
|
+
if (dereferencedRef) {
|
|
42
|
+
options?.onDereference?.({ schema, ref: dereferencedRef });
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (typeof resolved !== 'object' || resolved === null) {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
const dereferencedRef = schema.$ref;
|
|
69
|
-
// Get rid of the reference
|
|
70
|
-
delete schema.$ref;
|
|
71
|
-
for (const key of Object.keys(resolved)) {
|
|
72
|
-
if (schema[key] === undefined) {
|
|
73
|
-
schema[key] = resolved[key];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (dereferencedRef) {
|
|
77
|
-
options?.onDereference?.({ schema, ref: dereferencedRef });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Iterate over the whole object
|
|
81
|
-
for (const value of Object.values(schema)) {
|
|
82
|
-
if (typeof value === 'object' && value !== null) {
|
|
83
|
-
dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options);
|
|
84
|
-
}
|
|
44
|
+
}
|
|
45
|
+
for (const value of Object.values(schema)) {
|
|
46
|
+
if (typeof value === "object" && value !== null) {
|
|
47
|
+
dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options);
|
|
85
48
|
}
|
|
49
|
+
}
|
|
86
50
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*/
|
|
92
|
-
function resolveUri(
|
|
93
|
-
// 'foobar.json#/foo/bar'
|
|
94
|
-
uri, options,
|
|
95
|
-
// { uri: './foobar.json '}
|
|
96
|
-
file,
|
|
97
|
-
// [ { uri: './foobar.json '} ]
|
|
98
|
-
filesystem,
|
|
99
|
-
// a function to resolve references in external file
|
|
100
|
-
resolve, errors) {
|
|
101
|
-
// Ignore invalid URIs
|
|
102
|
-
if (typeof uri !== 'string') {
|
|
103
|
-
if (options?.throwOnError) {
|
|
104
|
-
throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri));
|
|
105
|
-
}
|
|
106
|
-
errors.push({
|
|
107
|
-
code: 'INVALID_REFERENCE',
|
|
108
|
-
message: ERRORS.INVALID_REFERENCE.replace('%s', uri),
|
|
109
|
-
});
|
|
110
|
-
return undefined;
|
|
51
|
+
function resolveUri(uri, options, file, filesystem, resolve, errors) {
|
|
52
|
+
if (typeof uri !== "string") {
|
|
53
|
+
if (options?.throwOnError) {
|
|
54
|
+
throw new Error(ERRORS.INVALID_REFERENCE.replace("%s", uri));
|
|
111
55
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (path === undefined) {
|
|
134
|
-
return externalReference.content;
|
|
135
|
-
}
|
|
136
|
-
// $ref: 'other-file.yaml#/foo/bar'
|
|
137
|
-
// resolve refs first before accessing properties directly
|
|
138
|
-
return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors);
|
|
56
|
+
errors.push({
|
|
57
|
+
code: "INVALID_REFERENCE",
|
|
58
|
+
message: ERRORS.INVALID_REFERENCE.replace("%s", uri)
|
|
59
|
+
});
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
const [prefix, path] = uri.split("#", 2);
|
|
63
|
+
const isDifferentFile = prefix !== file.filename;
|
|
64
|
+
if (prefix && isDifferentFile) {
|
|
65
|
+
const externalReference = filesystem.find((entry) => {
|
|
66
|
+
return entry.filename === prefix;
|
|
67
|
+
});
|
|
68
|
+
if (!externalReference) {
|
|
69
|
+
if (options?.throwOnError) {
|
|
70
|
+
throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s", prefix));
|
|
71
|
+
}
|
|
72
|
+
errors.push({
|
|
73
|
+
code: "EXTERNAL_REFERENCE_NOT_FOUND",
|
|
74
|
+
message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s", prefix)
|
|
75
|
+
});
|
|
76
|
+
return void 0;
|
|
139
77
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// Internal references
|
|
143
|
-
try {
|
|
144
|
-
return segments.reduce((acc, key) => {
|
|
145
|
-
return acc[key];
|
|
146
|
-
}, file.content);
|
|
78
|
+
if (path === void 0) {
|
|
79
|
+
return externalReference.specification;
|
|
147
80
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
81
|
+
return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors);
|
|
82
|
+
}
|
|
83
|
+
const segments = getSegmentsFromPath(path);
|
|
84
|
+
try {
|
|
85
|
+
return segments.reduce((acc, key) => {
|
|
86
|
+
return acc[key];
|
|
87
|
+
}, file.specification);
|
|
88
|
+
} catch (_error) {
|
|
89
|
+
if (options?.throwOnError) {
|
|
90
|
+
throw new Error(ERRORS.INVALID_REFERENCE.replace("%s", uri));
|
|
156
91
|
}
|
|
157
|
-
|
|
92
|
+
errors.push({
|
|
93
|
+
code: "INVALID_REFERENCE",
|
|
94
|
+
message: ERRORS.INVALID_REFERENCE.replace("%s", uri)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
158
98
|
}
|
|
159
|
-
|
|
160
|
-
|
|
99
|
+
export {
|
|
100
|
+
resolveReferences
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=resolveReferences.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/resolveReferences.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport { ERRORS } from '../configuration/index'\nimport type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index'\nimport { getEntrypoint } from './getEntrypoint'\nimport { getSegmentsFromPath } from './getSegmentsFromPath'\nimport { makeFilesystem } from './makeFilesystem'\n\n// TODO: Add support for all pointer words\n// export const pointerWords = new Set([\n// '$ref',\n// '$id',\n// '$anchor',\n// '$dynamicRef',\n// '$dynamicAnchor',\n// '$schema',\n// ])\n\nexport type ResolveReferencesResult = {\n valid: boolean\n errors: ErrorObject[]\n schema: OpenAPI.Document\n}\n\nexport type ResolveReferencesOptions = ThrowOnErrorOption & {\n /**\n * Fired when dereferenced a schema.\n *\n * Note that for object schemas, its properties may not be dereferenced when the hook is called.\n */\n onDereference?: (data: { schema: AnyObject; ref: string }) => void\n}\n\n/**\n * Takes a specification and resolves all references.\n */\nexport function resolveReferences(\n // Just a specification, or a set of files.\n input: AnyObject | Filesystem,\n // Additional options to control the behaviour\n options?: ResolveReferencesOptions,\n // Fallback to the entrypoint\n file?: FilesystemEntry,\n // Errors that occurred during the process\n errors: ErrorObject[] = [],\n): ResolveReferencesResult {\n // Detach from input\n const clonedInput = structuredClone(input)\n\n // Make it a filesystem, even if it\u2019s just one file\n const filesystem = makeFilesystem(clonedInput)\n\n // Get the main file\n const entrypoint = getEntrypoint(filesystem)\n\n const finalInput = file?.specification ?? entrypoint.specification\n\n // Recursively resolve all references\n dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options)\n\n // Remove duplicats (according to message) from errors\n errors = errors.filter(\n (error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code),\n )\n\n // Return the resolved specification\n return {\n valid: errors.length === 0,\n errors,\n schema: finalInput as OpenAPI.Document,\n }\n}\n\n/**\n * Resolves the circular reference to an object and deletes the $ref properties (in-place).\n */\nfunction dereference(\n schema: AnyObject,\n filesystem: Filesystem,\n entrypoint: FilesystemEntry,\n // references to resolved object\n resolvedSchemas: WeakSet<object>,\n // error output\n errors: ErrorObject[],\n\n options?: ResolveReferencesOptions,\n): void {\n if (schema === null || resolvedSchemas.has(schema)) {\n return\n }\n resolvedSchemas.add(schema)\n\n function resolveExternal(externalFile: FilesystemEntry) {\n dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options)\n\n return externalFile\n }\n\n while (schema.$ref !== undefined) {\n // Find the referenced content\n const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors)\n\n // invalid\n if (typeof resolved !== 'object' || resolved === null) {\n break\n }\n const dereferencedRef = schema.$ref\n\n // Get rid of the reference\n delete schema.$ref\n\n for (const key of Object.keys(resolved)) {\n if (schema[key] === undefined) {\n schema[key] = resolved[key]\n }\n }\n\n if (dereferencedRef) {\n options?.onDereference?.({ schema, ref: dereferencedRef })\n }\n }\n\n // Iterate over the whole object\n for (const value of Object.values(schema)) {\n if (typeof value === 'object' && value !== null) {\n dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options)\n }\n }\n}\n\n/**\n * Resolves a URI to a part of the specification\n *\n * The output is not necessarily dereferenced\n */\nfunction resolveUri(\n // 'foobar.json#/foo/bar'\n uri: string,\n options: ResolveReferencesOptions,\n // { filename: './foobar.json '}\n file: FilesystemEntry,\n // [ { filename: './foobar.json '} ]\n filesystem: Filesystem,\n\n // a function to resolve references in external file\n resolve: (file: FilesystemEntry) => FilesystemEntry,\n\n errors: ErrorObject[],\n): AnyObject | undefined {\n // Ignore invalid URIs\n if (typeof uri !== 'string') {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n\n return undefined\n }\n\n // Understand the URI\n const [prefix, path] = uri.split('#', 2)\n\n /** Check whether the file is pointing to itself */\n const isDifferentFile = prefix !== file.filename\n\n // External references\n if (prefix && isDifferentFile) {\n const externalReference = filesystem.find((entry) => {\n return entry.filename === prefix\n })\n\n if (!externalReference) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix))\n }\n\n errors.push({\n code: 'EXTERNAL_REFERENCE_NOT_FOUND',\n message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix),\n })\n\n return undefined\n }\n // $ref: 'other-file.yaml'\n if (path === undefined) {\n return externalReference.specification\n }\n\n // $ref: 'other-file.yaml#/foo/bar'\n // resolve refs first before accessing properties directly\n return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors)\n }\n\n // Pointers\n const segments = getSegmentsFromPath(path)\n\n // Try to find the URI\n try {\n return segments.reduce((acc, key) => {\n return acc[key]\n }, file.specification)\n } catch (_error) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('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