@scalar/openapi-parser 0.10.16 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +0 -27
- 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 -1
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.js +36 -39
- 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 -55
- 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 +1 -1
- 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 +2 -1
- 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 +1 -1
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +89 -110
- 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 +1 -1
- package/dist/utils/makeFilesystem.d.ts.map +1 -1
- package/dist/utils/makeFilesystem.js +20 -22
- 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 +994 -994
- 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 +702 -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 -1
- package/dist/utils/resolveReferences.d.ts.map +1 -1
- package/dist/utils/resolveReferences.js +91 -139
- 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 +3 -3
- package/dist/utils/traverse.d.ts.map +1 -1
- package/dist/utils/traverse.js +22 -23
- 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.bench.d.ts +2 -0
- package/dist/utils/upgrade.bench.d.ts.map +1 -0
- package/dist/utils/upgrade.bench.js +31 -0
- package/dist/utils/upgrade.bench.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 +28 -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.d.ts +3 -3
- package/dist/utils/upgradeFromThreeToThreeOne.d.ts.map +1 -1
- package/dist/utils/upgradeFromThreeToThreeOne.js +107 -144
- 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.d.ts.map +1 -1
- 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 +7 -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,300 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { dereference } from "./dereference.js";
|
|
3
|
+
describe("dereference", async () => {
|
|
4
|
+
it("dereferences an OpenAPI 3.1.0 file", async () => {
|
|
5
|
+
const result = await dereference(`{
|
|
6
|
+
"openapi": "3.1.0",
|
|
7
|
+
"info": {
|
|
8
|
+
"title": "Hello World",
|
|
9
|
+
"version": "1.0.0"
|
|
10
|
+
},
|
|
11
|
+
"paths": {}
|
|
12
|
+
}`);
|
|
13
|
+
expect(result.errors).toStrictEqual([]);
|
|
14
|
+
expect(result.schema.info.title).toBe("Hello World");
|
|
15
|
+
});
|
|
16
|
+
it("dereferences an OpenAPI 3.0.0 file", async () => {
|
|
17
|
+
const result = await dereference(`{
|
|
18
|
+
"openapi": "3.0.0",
|
|
19
|
+
"info": {
|
|
20
|
+
"title": "Hello World",
|
|
21
|
+
"version": "1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"paths": {}
|
|
24
|
+
}`);
|
|
25
|
+
expect(result.errors).toStrictEqual([]);
|
|
26
|
+
expect(result.schema.info.title).toBe("Hello World");
|
|
27
|
+
});
|
|
28
|
+
it("dereferences an Swagger 2.0 file", async () => {
|
|
29
|
+
const result = await dereference(`{
|
|
30
|
+
"swagger": "2.0",
|
|
31
|
+
"info": {
|
|
32
|
+
"title": "Hello World",
|
|
33
|
+
"version": "1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"paths": {}
|
|
36
|
+
}`);
|
|
37
|
+
expect(result.errors).toStrictEqual([]);
|
|
38
|
+
expect(result.schema.info.title).toBe("Hello World");
|
|
39
|
+
});
|
|
40
|
+
it("returns version 3.1", async () => {
|
|
41
|
+
const result = await dereference(`{
|
|
42
|
+
"openapi": "3.1.0",
|
|
43
|
+
"info": {
|
|
44
|
+
"title": "Hello World",
|
|
45
|
+
"version": "1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"paths": {}
|
|
48
|
+
}`);
|
|
49
|
+
expect(result.errors).toStrictEqual([]);
|
|
50
|
+
expect(result.version).toBe("3.1");
|
|
51
|
+
});
|
|
52
|
+
it("returns version 3.0", async () => {
|
|
53
|
+
const result = await dereference(`{
|
|
54
|
+
"openapi": "3.0.0",
|
|
55
|
+
"info": {
|
|
56
|
+
"title": "Hello World",
|
|
57
|
+
"version": "1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"paths": {}
|
|
60
|
+
}`);
|
|
61
|
+
expect(result.errors).toStrictEqual([]);
|
|
62
|
+
expect(result.version).toBe("3.0");
|
|
63
|
+
});
|
|
64
|
+
it("returns version 2.0", async () => {
|
|
65
|
+
const result = await dereference(`{
|
|
66
|
+
"swagger": "2.0",
|
|
67
|
+
"info": {
|
|
68
|
+
"title": "Hello World",
|
|
69
|
+
"version": "1.0.0"
|
|
70
|
+
},
|
|
71
|
+
"paths": {}
|
|
72
|
+
}`);
|
|
73
|
+
expect(result.errors).toStrictEqual([]);
|
|
74
|
+
expect(result.version).toBe("2.0");
|
|
75
|
+
});
|
|
76
|
+
it("doesn\u2019t return version 4.0", async () => {
|
|
77
|
+
const result = await dereference(`{
|
|
78
|
+
"openapi": "4.0",
|
|
79
|
+
"info": {
|
|
80
|
+
"title": "Hello World",
|
|
81
|
+
"version": "1.0.0"
|
|
82
|
+
},
|
|
83
|
+
"paths": {}
|
|
84
|
+
}`);
|
|
85
|
+
expect(result.version).toBe(void 0);
|
|
86
|
+
});
|
|
87
|
+
it("dereferences a simple reference", async () => {
|
|
88
|
+
const openapi = {
|
|
89
|
+
openapi: "3.1.0",
|
|
90
|
+
info: {
|
|
91
|
+
title: "Hello World",
|
|
92
|
+
version: "1.0.0"
|
|
93
|
+
},
|
|
94
|
+
paths: {
|
|
95
|
+
"/test": {
|
|
96
|
+
get: {
|
|
97
|
+
responses: {
|
|
98
|
+
"200": {
|
|
99
|
+
// TODO: This is valid in @apidevtools/swagger, but not with our implementation
|
|
100
|
+
description: "foobar",
|
|
101
|
+
content: {
|
|
102
|
+
"application/json": {
|
|
103
|
+
schema: {
|
|
104
|
+
$ref: "#/components/schemas/Test"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
components: {
|
|
114
|
+
schemas: {
|
|
115
|
+
Test: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
id: {
|
|
119
|
+
type: "string"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const result = await dereference(openapi);
|
|
127
|
+
expect(result.errors).toStrictEqual([]);
|
|
128
|
+
expect(result.specification.paths["/test"].get.responses["200"].content["application/json"].schema).toEqual({
|
|
129
|
+
$ref: "#/components/schemas/Test"
|
|
130
|
+
});
|
|
131
|
+
expect(result.schema.paths["/test"].get.responses["200"].content["application/json"].schema).toEqual({
|
|
132
|
+
type: "object",
|
|
133
|
+
properties: {
|
|
134
|
+
id: {
|
|
135
|
+
type: "string"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it("throws an error", async () => {
|
|
141
|
+
expect(async () => {
|
|
142
|
+
await dereference(
|
|
143
|
+
{
|
|
144
|
+
openapi: "3.1.0",
|
|
145
|
+
info: {},
|
|
146
|
+
paths: {
|
|
147
|
+
"/foobar": {
|
|
148
|
+
post: {
|
|
149
|
+
requestBody: {
|
|
150
|
+
$ref: "#/components/requestBodies/DoesNotExist"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
throwOnError: true
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}).rejects.toThrowError("Can\u2019t resolve reference: #/components/requestBodies/DoesNotExist");
|
|
161
|
+
});
|
|
162
|
+
it("resolves external file references", async () => {
|
|
163
|
+
const filesystem = [
|
|
164
|
+
{
|
|
165
|
+
isEntrypoint: true,
|
|
166
|
+
specification: {
|
|
167
|
+
openapi: "3.1.0",
|
|
168
|
+
info: {
|
|
169
|
+
title: "File Reference",
|
|
170
|
+
version: "1.0.0"
|
|
171
|
+
},
|
|
172
|
+
paths: {},
|
|
173
|
+
components: {
|
|
174
|
+
schemas: {
|
|
175
|
+
ExternalSchema: {
|
|
176
|
+
$ref: "valid.yaml#/components/schemas/ExampleSchema"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
filename: "file-reference.yaml",
|
|
182
|
+
dir: "./",
|
|
183
|
+
references: ["valid.yaml"]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
isEntrypoint: false,
|
|
187
|
+
specification: {
|
|
188
|
+
openapi: "3.1.0",
|
|
189
|
+
info: {
|
|
190
|
+
title: "Hello World",
|
|
191
|
+
version: "1.0.0"
|
|
192
|
+
},
|
|
193
|
+
paths: {},
|
|
194
|
+
components: {
|
|
195
|
+
schemas: {
|
|
196
|
+
ExampleSchema: {
|
|
197
|
+
type: "object",
|
|
198
|
+
properties: {
|
|
199
|
+
id: {
|
|
200
|
+
type: "integer",
|
|
201
|
+
description: "Unique identifier for the example"
|
|
202
|
+
},
|
|
203
|
+
name: {
|
|
204
|
+
type: "string",
|
|
205
|
+
description: "Name of the example"
|
|
206
|
+
},
|
|
207
|
+
description: {
|
|
208
|
+
type: "string",
|
|
209
|
+
description: "Detailed description of the example"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
required: ["id", "name"]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
filename: "valid.yaml",
|
|
218
|
+
dir: "./",
|
|
219
|
+
references: []
|
|
220
|
+
}
|
|
221
|
+
];
|
|
222
|
+
const result = await dereference(filesystem);
|
|
223
|
+
expect(result.errors).toStrictEqual([]);
|
|
224
|
+
expect(result.schema.components.schemas.ExternalSchema).toEqual({
|
|
225
|
+
type: "object",
|
|
226
|
+
properties: {
|
|
227
|
+
id: {
|
|
228
|
+
type: "integer",
|
|
229
|
+
description: "Unique identifier for the example"
|
|
230
|
+
},
|
|
231
|
+
name: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Name of the example"
|
|
234
|
+
},
|
|
235
|
+
description: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "Detailed description of the example"
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
required: ["id", "name"]
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
it("calls onDereference when resolving references", async () => {
|
|
244
|
+
const openapi = {
|
|
245
|
+
openapi: "3.1.0",
|
|
246
|
+
info: {
|
|
247
|
+
title: "Hello World",
|
|
248
|
+
version: "1.0.0"
|
|
249
|
+
},
|
|
250
|
+
paths: {
|
|
251
|
+
"/test": {
|
|
252
|
+
get: {
|
|
253
|
+
responses: {
|
|
254
|
+
"200": {
|
|
255
|
+
description: "foobar",
|
|
256
|
+
content: {
|
|
257
|
+
"application/json": {
|
|
258
|
+
schema: {
|
|
259
|
+
$ref: "#/components/schemas/Test"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
components: {
|
|
269
|
+
schemas: {
|
|
270
|
+
Test: {
|
|
271
|
+
type: "object",
|
|
272
|
+
properties: {
|
|
273
|
+
id: {
|
|
274
|
+
type: "string"
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const dereferencedSchemas = [];
|
|
282
|
+
const result = await dereference(openapi, {
|
|
283
|
+
onDereference: ({ schema, ref }) => {
|
|
284
|
+
expect(schema).toEqual({
|
|
285
|
+
type: "object",
|
|
286
|
+
properties: {
|
|
287
|
+
id: {
|
|
288
|
+
type: "string"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
expect(ref).toEqual("#/components/schemas/Test");
|
|
293
|
+
dereferencedSchemas.push({ schema, ref });
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
expect(result.errors).toStrictEqual([]);
|
|
297
|
+
expect(dereferencedSchemas).toHaveLength(1);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
//# sourceMappingURL=dereference.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/dereference.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { dereference } from './dereference'\n\ndescribe('dereference', async () => {\n it('dereferences an OpenAPI 3.1.0 file', async () => {\n const result = await dereference(`{\n \"openapi\": \"3.1.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.schema.info.title).toBe('Hello World')\n })\n\n it('dereferences an OpenAPI 3.0.0 file', async () => {\n const result = await dereference(`{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.schema.info.title).toBe('Hello World')\n })\n\n it('dereferences an Swagger 2.0 file', async () => {\n const result = await dereference(`{\n \"swagger\": \"2.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.schema.info.title).toBe('Hello World')\n })\n\n it('returns version 3.1', async () => {\n const result = await dereference(`{\n \"openapi\": \"3.1.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.version).toBe('3.1')\n })\n\n it('returns version 3.0', async () => {\n const result = await dereference(`{\n \"openapi\": \"3.0.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.version).toBe('3.0')\n })\n\n it('returns version 2.0', async () => {\n const result = await dereference(`{\n \"swagger\": \"2.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.errors).toStrictEqual([])\n expect(result.version).toBe('2.0')\n })\n\n it('doesn\u2019t return version 4.0', async () => {\n const result = await dereference(`{\n \"openapi\": \"4.0\",\n \"info\": {\n \"title\": \"Hello World\",\n \"version\": \"1.0.0\"\n },\n \"paths\": {}\n }`)\n\n expect(result.version).toBe(undefined)\n })\n\n it('dereferences a simple reference', async () => {\n const openapi = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/test': {\n get: {\n responses: {\n '200': {\n // TODO: This is valid in @apidevtools/swagger, but not with our implementation\n description: 'foobar',\n content: {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/Test',\n },\n },\n },\n },\n },\n },\n },\n },\n components: {\n schemas: {\n Test: {\n type: 'object',\n properties: {\n id: {\n type: 'string',\n },\n },\n },\n },\n },\n }\n\n const result = await dereference(openapi)\n\n expect(result.errors).toStrictEqual([])\n\n // Original\n expect(result.specification.paths['/test'].get.responses['200'].content['application/json'].schema).toEqual({\n $ref: '#/components/schemas/Test',\n })\n\n // Resolved references\n expect(result.schema.paths['/test'].get.responses['200'].content['application/json'].schema).toEqual({\n type: 'object',\n properties: {\n id: {\n type: 'string',\n },\n },\n })\n })\n\n it('throws an error', async () => {\n expect(async () => {\n await dereference(\n {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/DoesNotExist',\n },\n },\n },\n },\n },\n {\n throwOnError: true,\n },\n )\n }).rejects.toThrowError('Can\u2019t resolve reference: #/components/requestBodies/DoesNotExist')\n })\n\n it('resolves external file references', async () => {\n const filesystem = [\n {\n isEntrypoint: true,\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'File Reference',\n version: '1.0.0',\n },\n paths: {},\n components: {\n schemas: {\n ExternalSchema: {\n $ref: 'valid.yaml#/components/schemas/ExampleSchema',\n },\n },\n },\n },\n filename: 'file-reference.yaml',\n dir: './',\n references: ['valid.yaml'],\n },\n {\n isEntrypoint: false,\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n components: {\n schemas: {\n ExampleSchema: {\n type: 'object',\n properties: {\n id: {\n type: 'integer',\n description: 'Unique identifier for the example',\n },\n name: {\n type: 'string',\n description: 'Name of the example',\n },\n description: {\n type: 'string',\n description: 'Detailed description of the example',\n },\n },\n required: ['id', 'name'],\n },\n },\n },\n },\n filename: 'valid.yaml',\n dir: './',\n references: [],\n },\n ]\n\n const result = await dereference(filesystem)\n\n expect(result.errors).toStrictEqual([])\n\n // Check if the external reference was resolved\n expect(result.schema.components.schemas.ExternalSchema).toEqual({\n type: 'object',\n properties: {\n id: {\n type: 'integer',\n description: 'Unique identifier for the example',\n },\n name: {\n type: 'string',\n description: 'Name of the example',\n },\n description: {\n type: 'string',\n description: 'Detailed description of the example',\n },\n },\n required: ['id', 'name'],\n })\n })\n\n it('calls onDereference when resolving references', async () => {\n const openapi = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/test': {\n get: {\n responses: {\n '200': {\n description: 'foobar',\n content: {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/Test',\n },\n },\n },\n },\n },\n },\n },\n },\n components: {\n schemas: {\n Test: {\n type: 'object',\n properties: {\n id: {\n type: 'string',\n },\n },\n },\n },\n },\n }\n\n const dereferencedSchemas: Array<{ schema: any; ref: string }> = []\n\n const result = await dereference(openapi, {\n onDereference: ({ schema, ref }) => {\n expect(schema).toEqual({\n type: 'object',\n properties: {\n id: {\n type: 'string',\n },\n },\n })\n\n expect(ref).toEqual('#/components/schemas/Test')\n\n dereferencedSchemas.push({ schema, ref })\n },\n })\n\n expect(result.errors).toStrictEqual([])\n expect(dereferencedSchemas).toHaveLength(1)\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,mBAAmB;AAE5B,SAAS,eAAe,YAAY;AAClC,KAAG,sCAAsC,YAAY;AACnD,UAAM,SAAS,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAO/B;AAEF,WAAO,OAAO,MAAM,EAAE,cAAc,CAAC,CAAC;AACtC,WAAO,OAAO,OAAO,KAAK,KAAK,EAAE,KAAK,aAAa;AAAA,EACrD,CAAC;AAED,KAAG,sCAAsC,YAAY;AACnD,UAAM,SAAS,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAO/B;AAEF,WAAO,OAAO,MAAM,EAAE,cAAc,CAAC,CAAC;AACtC,WAAO,OAAO,OAAO,KAAK,KAAK,EAAE,KAAK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A,EAC5C,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/utils/details.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/utils/details.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/utils/details.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD;;GAEG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,CA2BnE"}
|
package/dist/utils/details.js
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import { OpenApiVersions } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get versions of the OpenAPI document.
|
|
5
|
-
*/
|
|
1
|
+
import { OpenApiVersions } from "../configuration/index.js";
|
|
6
2
|
function details(specification) {
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
version: undefined,
|
|
10
|
-
specificationType: undefined,
|
|
11
|
-
specificationVersion: undefined,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
for (const version of new Set(OpenApiVersions)) {
|
|
15
|
-
const specificationType = version === '2.0' ? 'swagger' : 'openapi';
|
|
16
|
-
const value = specification[specificationType];
|
|
17
|
-
if (typeof value === 'string' && value.startsWith(version)) {
|
|
18
|
-
return {
|
|
19
|
-
version: version,
|
|
20
|
-
specificationType,
|
|
21
|
-
specificationVersion: value,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
3
|
+
if (specification === null) {
|
|
25
4
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
version: void 0,
|
|
6
|
+
specificationType: void 0,
|
|
7
|
+
specificationVersion: void 0
|
|
29
8
|
};
|
|
9
|
+
}
|
|
10
|
+
for (const version of new Set(OpenApiVersions)) {
|
|
11
|
+
const specificationType = version === "2.0" ? "swagger" : "openapi";
|
|
12
|
+
const value = specification[specificationType];
|
|
13
|
+
if (typeof value === "string" && value.startsWith(version)) {
|
|
14
|
+
return {
|
|
15
|
+
version,
|
|
16
|
+
specificationType,
|
|
17
|
+
specificationVersion: value
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
version: void 0,
|
|
23
|
+
specificationType: void 0,
|
|
24
|
+
specificationVersion: void 0
|
|
25
|
+
};
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
export {
|
|
28
|
+
details
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=details.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/details.ts"],
|
|
4
|
+
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\n\nimport { OpenApiVersions } from '../configuration/index'\nimport type { DetailsResult } from '../types/index'\n\n/**\n * Get versions of the OpenAPI document.\n */\nexport function details(specification: UnknownObject): DetailsResult {\n if (specification === null) {\n return {\n version: undefined,\n specificationType: undefined,\n specificationVersion: undefined,\n }\n }\n\n for (const version of new Set(OpenApiVersions)) {\n const specificationType = version === '2.0' ? 'swagger' : 'openapi'\n const value = specification[specificationType]\n\n if (typeof value === 'string' && value.startsWith(version)) {\n return {\n version: version,\n specificationType,\n specificationVersion: value,\n }\n }\n }\n\n return {\n version: undefined,\n specificationType: undefined,\n specificationVersion: undefined,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,uBAAuB;AAMzB,SAAS,QAAQ,eAA6C;AACnE,MAAI,kBAAkB,MAAM;AAC1B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,mBAAmB;AAAA,MACnB,sBAAsB;AAAA,IACxB;AAAA,EACF;AAEA,aAAW,WAAW,IAAI,IAAI,eAAe,GAAG;AAC9C,UAAM,oBAAoB,YAAY,QAAQ,YAAY;AAC1D,UAAM,QAAQ,cAAc,iBAAiB;AAE7C,QAAI,OAAO,UAAU,YAAY,MAAM,WAAW,OAAO,GAAG;AAC1D,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,EACxB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { validate } from "./validate.js";
|
|
3
|
+
describe("errors", () => {
|
|
4
|
+
it("info required", async () => {
|
|
5
|
+
const result = await validate({
|
|
6
|
+
openapi: "3.1.0",
|
|
7
|
+
paths: {}
|
|
8
|
+
});
|
|
9
|
+
expect(result).toMatchObject({
|
|
10
|
+
errors: [
|
|
11
|
+
{
|
|
12
|
+
message: `must have required property 'info'`
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
valid: false
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it("unevaluated property", async () => {
|
|
19
|
+
const spec = {
|
|
20
|
+
openapi: "3.1.0",
|
|
21
|
+
info: {
|
|
22
|
+
title: "Hello World",
|
|
23
|
+
version: "1.0.0"
|
|
24
|
+
},
|
|
25
|
+
paths: {
|
|
26
|
+
"/test": {
|
|
27
|
+
foobar: {
|
|
28
|
+
responses: {
|
|
29
|
+
200: {
|
|
30
|
+
description: "OK"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const result = await validate(spec);
|
|
38
|
+
expect(result).toMatchObject({
|
|
39
|
+
errors: [
|
|
40
|
+
{
|
|
41
|
+
message: "Property foobar is not expected to be here"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
valid: false
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=errors.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/errors.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { validate } from './validate'\n\ndescribe('errors', () => {\n it('info required', async () => {\n const result = await validate({\n openapi: '3.1.0',\n paths: {},\n })\n\n expect(result).toMatchObject({\n errors: [\n {\n message: `must have required property 'info'`,\n },\n ],\n valid: false,\n })\n })\n\n it('unevaluated property', async () => {\n const spec = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/test': {\n foobar: {\n responses: {\n 200: {\n description: 'OK',\n },\n },\n },\n },\n },\n }\n const result = await validate(spec)\n\n expect(result).toMatchObject({\n errors: [\n {\n message: 'Property foobar is not expected to be here',\n },\n ],\n valid: false,\n })\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gBAAgB;AAEzB,SAAS,UAAU,MAAM;AACvB,KAAG,iBAAiB,YAAY;AAC9B,UAAM,SAAS,MAAM,SAAS;AAAA,MAC5B,SAAS;AAAA,MACT,OAAO,CAAC;AAAA,IACV,CAAC;AAED,WAAO,MAAM,EAAE,cAAc;AAAA,MAC3B,QAAQ;AAAA,QACN;AAAA,UACE,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH,CAAC;AAED,KAAG,wBAAwB,YAAY;AACrC,UAAM,OAAO;AAAA,MACX,SAAS;AAAA,MACT,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,UACP,QAAQ;AAAA,YACN,WAAW;AAAA,cACT,KAAK;AAAA,gBACH,aAAa;AAAA,cACf;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,UAAM,SAAS,MAAM,SAAS,IAAI;AAElC,WAAO,MAAM,EAAE,cAAc;AAAA,MAC3B,QAAQ;AAAA,QACN;AAAA,UACE,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Escapes a JSON pointer string.
|
|
3
|
-
*
|
|
4
|
-
* Example: `/foo/bar~baz` -> `/foo~1bar~0baz`
|
|
5
|
-
*/
|
|
6
1
|
function escapeJsonPointer(str) {
|
|
7
|
-
|
|
2
|
+
return str.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
8
3
|
}
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export {
|
|
5
|
+
escapeJsonPointer
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=escapeJsonPointer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/escapeJsonPointer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Escapes a JSON pointer string.\n *\n * Example: `/foo/bar~baz` -> `/foo~1bar~0baz`\n */\nexport function escapeJsonPointer(str: string) {\n return str.replace(/~/g, '~0').replace(/\\//g, '~1')\n}\n"],
|
|
5
|
+
"mappings": "AAKO,SAAS,kBAAkB,KAAa;AAC7C,SAAO,IAAI,QAAQ,MAAM,IAAI,EAAE,QAAQ,OAAO,IAAI;AACpD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { escapeJsonPointer } from "./escapeJsonPointer.js";
|
|
3
|
+
describe("escapeJsonPointer", async () => {
|
|
4
|
+
it("should escape a slash", () => {
|
|
5
|
+
expect(escapeJsonPointer("application/json")).toBe("application~1json");
|
|
6
|
+
});
|
|
7
|
+
it("should escape multiple slashes", () => {
|
|
8
|
+
expect(escapeJsonPointer("/api/users/{id}/reports")).toBe("~1api~1users~1{id}~1reports");
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=escapeJsonPointer.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/escapeJsonPointer.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { escapeJsonPointer } from './escapeJsonPointer'\n\ndescribe('escapeJsonPointer', async () => {\n it('should escape a slash', () => {\n expect(escapeJsonPointer('application/json')).toBe('application~1json')\n })\n\n it('should escape multiple slashes', () => {\n expect(escapeJsonPointer('/api/users/{id}/reports')).toBe('~1api~1users~1{id}~1reports')\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,yBAAyB;AAElC,SAAS,qBAAqB,YAAY;AACxC,KAAG,yBAAyB,MAAM;AAChC,WAAO,kBAAkB,kBAAkB,CAAC,EAAE,KAAK,mBAAmB;AAAA,EACxE,CAAC;AAED,KAAG,kCAAkC,MAAM;AACzC,WAAO,kBAAkB,yBAAyB,CAAC,EAAE,KAAK,6BAA6B;AAAA,EACzF,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyApiDefinitionFormat, AnyObject, FilterResult } from '../types/index.
|
|
1
|
+
import type { AnyApiDefinitionFormat, AnyObject, FilterResult } from '../types/index.js';
|
|
2
2
|
export type FilterCallback = (schema: AnyObject) => boolean;
|
|
3
3
|
/**
|
|
4
4
|
* Filter the specification based on the callback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/utils/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/utils/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAKrF,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAA;AAE3D;;GAEG;AACH,wBAAgB,MAAM,CAAC,aAAa,EAAE,sBAAsB,EAAE,QAAQ,EAAE,cAAc,GAAG,YAAY,CAQpG"}
|
package/dist/utils/filter.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { getEntrypoint } from
|
|
2
|
-
import { makeFilesystem } from
|
|
3
|
-
import { traverse } from
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Filter the specification based on the callback
|
|
7
|
-
*/
|
|
1
|
+
import { getEntrypoint } from "./getEntrypoint.js";
|
|
2
|
+
import { makeFilesystem } from "./makeFilesystem.js";
|
|
3
|
+
import { traverse } from "./traverse.js";
|
|
8
4
|
function filter(specification, callback) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const filesystem = makeFilesystem(specification);
|
|
6
|
+
return {
|
|
7
|
+
specification: traverse(getEntrypoint(filesystem).specification, (schema) => {
|
|
8
|
+
return callback(schema) ? schema : void 0;
|
|
9
|
+
})
|
|
10
|
+
};
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
export {
|
|
13
|
+
filter
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/filter.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AnyApiDefinitionFormat, AnyObject, FilterResult } from '../types/index'\nimport { getEntrypoint } from './getEntrypoint'\nimport { makeFilesystem } from './makeFilesystem'\nimport { traverse } from './traverse'\n\nexport type FilterCallback = (schema: AnyObject) => boolean\n\n/**\n * Filter the specification based on the callback\n */\nexport function filter(specification: AnyApiDefinitionFormat, callback: FilterCallback): FilterResult {\n const filesystem = makeFilesystem(specification)\n\n return {\n specification: traverse(getEntrypoint(filesystem).specification, (schema) => {\n return callback(schema) ? schema : undefined\n }),\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AAOlB,SAAS,OAAO,eAAuC,UAAwC;AACpG,QAAM,aAAa,eAAe,aAAa;AAE/C,SAAO;AAAA,IACL,eAAe,SAAS,cAAc,UAAU,EAAE,eAAe,CAAC,WAAW;AAC3E,aAAO,SAAS,MAAM,IAAI,SAAS;AAAA,IACrC,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntrypoint.d.ts","sourceRoot":"","sources":["../../src/utils/getEntrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getEntrypoint.d.ts","sourceRoot":"","sources":["../../src/utils/getEntrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEjE;;GAEG;AACH,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,eAAe,GAAG,SAAS,CAElF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return just the entrypoint of the filesystem.
|
|
3
|
-
*/
|
|
4
1
|
function getEntrypoint(filesystem) {
|
|
5
|
-
|
|
2
|
+
return filesystem?.find((file) => file.isEntrypoint);
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export {
|
|
5
|
+
getEntrypoint
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getEntrypoint.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/getEntrypoint.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Filesystem, FilesystemEntry } from '../types/index'\n\n/**\n * Return just the entrypoint of the filesystem.\n */\nexport function getEntrypoint(filesystem?: Filesystem): FilesystemEntry | undefined {\n return filesystem?.find((file) => file.isEntrypoint)\n}\n"],
|
|
5
|
+
"mappings": "AAKO,SAAS,cAAc,YAAsD;AAClF,SAAO,YAAY,KAAK,CAAC,SAAS,KAAK,YAAY;AACrD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getEntrypoint } from "./getEntrypoint.js";
|
|
3
|
+
import { makeFilesystem } from "./makeFilesystem.js";
|
|
4
|
+
describe("getEntrypoint", () => {
|
|
5
|
+
it("keeps the object reference", () => {
|
|
6
|
+
const result = makeFilesystem({
|
|
7
|
+
foo: "bar"
|
|
8
|
+
});
|
|
9
|
+
const entrypoint = getEntrypoint(result);
|
|
10
|
+
entrypoint.specification.foo = "baz";
|
|
11
|
+
expect(result[0].specification.foo).toBe("baz");
|
|
12
|
+
});
|
|
13
|
+
it("returns undefined for an empty filesystem", () => {
|
|
14
|
+
const entrypoint = getEntrypoint([]);
|
|
15
|
+
expect(entrypoint).toBe(void 0);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=getEntrypoint.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/getEntrypoint.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { getEntrypoint } from './getEntrypoint'\nimport { makeFilesystem } from './makeFilesystem'\n\ndescribe('getEntrypoint', () => {\n it('keeps the object reference', () => {\n const result = makeFilesystem({\n foo: 'bar',\n })\n\n const entrypoint = getEntrypoint(result)\n\n // Modify the entrypoint\n entrypoint.specification.foo = 'baz'\n\n // Check whether the original was modified\n expect(result[0].specification.foo).toBe('baz')\n })\n\n it('returns undefined for an empty filesystem', () => {\n const entrypoint = getEntrypoint([])\n\n // Check whether the original was modified\n expect(entrypoint).toBe(undefined)\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAE/B,SAAS,iBAAiB,MAAM;AAC9B,KAAG,8BAA8B,MAAM;AACrC,UAAM,SAAS,eAAe;AAAA,MAC5B,KAAK;AAAA,IACP,CAAC;AAED,UAAM,aAAa,cAAc,MAAM;AAGvC,eAAW,cAAc,MAAM;AAG/B,WAAO,OAAO,CAAC,EAAE,cAAc,GAAG,EAAE,KAAK,KAAK;AAAA,EAChD,CAAC;AAED,KAAG,6CAA6C,MAAM;AACpD,UAAM,aAAa,cAAc,CAAC,CAAC;AAGnC,WAAO,UAAU,EAAE,KAAK,MAAS;AAAA,EACnC,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|