@scalar/openapi-parser 0.11.1 → 0.12.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 +6 -0
- package/dist/configuration/index.js.map +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -4
- package/dist/index.js.map +2 -2
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +2 -2
- package/dist/lib/Validator/Validator.js.map +1 -1
- package/dist/lib/Validator/index.d.ts +1 -2
- package/dist/lib/Validator/index.d.ts.map +1 -1
- package/dist/lib/Validator/index.js +4 -2
- package/dist/lib/Validator/index.js.map +2 -2
- package/dist/plugins/fetch-urls/{fetchUrls.d.ts → fetch-urls.d.ts} +1 -1
- package/dist/plugins/fetch-urls/fetch-urls.d.ts.map +1 -0
- package/dist/plugins/fetch-urls/{fetchUrls.js → fetch-urls.js} +1 -1
- package/dist/plugins/fetch-urls/fetch-urls.js.map +7 -0
- package/dist/plugins/fetch-urls/{fetchUrls.test.js → fetch-urls.test.js} +2 -2
- package/dist/plugins/fetch-urls/fetch-urls.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 +5 -1
- package/dist/plugins/fetch-urls/index.js.map +2 -2
- 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 +4 -1
- package/dist/plugins/read-files/index.js.map +2 -2
- package/dist/plugins/read-files/{readFiles.d.ts → read-files.d.ts} +1 -1
- package/dist/plugins/read-files/read-files.d.ts.map +1 -0
- package/dist/plugins/read-files/{readFiles.js → read-files.js} +3 -3
- package/dist/plugins/read-files/read-files.js.map +7 -0
- package/dist/plugins/read-files/{readFiles.test.js → read-files.test.js} +2 -2
- package/dist/plugins/read-files/read-files.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 +22 -2
- package/dist/polyfills/index.js.map +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/betterAjvErrors/validation-errors/base.js.map +1 -1
- package/dist/utils/dereference.d.ts +1 -1
- package/dist/utils/dereference.d.ts.map +1 -1
- package/dist/utils/dereference.js +3 -3
- package/dist/utils/dereference.js.map +1 -1
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js.map +1 -1
- package/dist/utils/{escapeJsonPointer.d.ts → escape-json-pointer.d.ts} +1 -1
- package/dist/utils/escape-json-pointer.d.ts.map +1 -0
- package/dist/utils/{escapeJsonPointer.js → escape-json-pointer.js} +1 -1
- package/dist/utils/{escapeJsonPointer.js.map → escape-json-pointer.js.map} +1 -1
- package/dist/utils/{escapeJsonPointer.test.js → escape-json-pointer.test.js} +2 -2
- package/dist/utils/escape-json-pointer.test.js.map +7 -0
- package/dist/utils/filter.d.ts.map +1 -1
- package/dist/utils/filter.js +2 -2
- package/dist/utils/filter.js.map +1 -1
- package/dist/utils/{getEntrypoint.d.ts → get-entrypoint.d.ts} +1 -1
- package/dist/utils/get-entrypoint.d.ts.map +1 -0
- package/dist/utils/{getEntrypoint.js → get-entrypoint.js} +1 -1
- package/dist/utils/get-entrypoint.js.map +7 -0
- package/dist/utils/{getEntrypoint.test.js → get-entrypoint.test.js} +3 -3
- package/dist/utils/get-entrypoint.test.js.map +7 -0
- package/dist/utils/{getListOfReferences.d.ts → get-list-of-references.d.ts} +1 -1
- package/dist/utils/get-list-of-references.d.ts.map +1 -0
- package/dist/utils/{getListOfReferences.js → get-list-of-references.js} +1 -1
- package/dist/utils/get-list-of-references.js.map +7 -0
- package/dist/utils/{getSegmentsFromPath.d.ts → get-segments-from-path.d.ts} +1 -1
- package/dist/utils/get-segments-from-path.d.ts.map +1 -0
- package/dist/utils/{getSegmentsFromPath.js → get-segments-from-path.js} +2 -2
- package/dist/utils/get-segments-from-path.js.map +7 -0
- package/dist/utils/{getSegmentsFromPath.test.js → get-segments-from-path.test.js} +2 -2
- package/dist/utils/get-segments-from-path.test.js.map +7 -0
- package/dist/utils/{isFilesystem.d.ts → is-filesystem.d.ts} +1 -1
- package/dist/utils/is-filesystem.d.ts.map +1 -0
- package/dist/utils/{isFilesystem.js → is-filesystem.js} +1 -1
- package/dist/utils/is-filesystem.js.map +7 -0
- package/dist/utils/{makeFilesystem.test.js → is-filesystem.test.js} +3 -3
- package/dist/utils/is-filesystem.test.js.map +7 -0
- package/dist/utils/{isJson.d.ts → is-json.d.ts} +1 -1
- package/dist/utils/is-json.d.ts.map +1 -0
- package/dist/utils/{isJson.js → is-json.js} +1 -1
- package/dist/utils/{isJson.js.map → is-json.js.map} +1 -1
- package/dist/utils/{isObject.d.ts → is-object.d.ts} +1 -1
- package/dist/utils/is-object.d.ts.map +1 -0
- package/dist/utils/{isObject.js → is-object.js} +1 -1
- package/dist/utils/{isObject.js.map → is-object.js.map} +1 -1
- package/dist/utils/{isObject.test.js → is-object.test.js} +2 -2
- package/dist/utils/is-object.test.js.map +7 -0
- package/dist/utils/{isYaml.d.ts → is-yaml.d.ts} +1 -1
- package/dist/utils/is-yaml.d.ts.map +1 -0
- package/dist/utils/{isYaml.js → is-yaml.js} +1 -1
- package/dist/utils/{isYaml.js.map → is-yaml.js.map} +1 -1
- 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 +4 -1
- package/dist/utils/load/index.js.map +2 -2
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +4 -4
- package/dist/utils/load/load.js.map +1 -1
- package/dist/utils/load/load.test.js +3 -3
- package/dist/utils/load/load.test.js.map +1 -1
- package/dist/utils/{makeFilesystem.d.ts → make-filesystem.d.ts} +1 -1
- package/dist/utils/make-filesystem.d.ts.map +1 -0
- package/dist/utils/{makeFilesystem.js → make-filesystem.js} +3 -3
- package/dist/utils/make-filesystem.js.map +7 -0
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +1 -1
- package/dist/utils/normalize.js.map +1 -1
- package/dist/utils/{resolveReferences.d.ts → resolve-references.d.ts} +1 -1
- package/dist/utils/{resolveReferences.d.ts.map → resolve-references.d.ts.map} +1 -1
- package/dist/utils/{resolveReferences.js → resolve-references.js} +4 -4
- package/dist/utils/resolve-references.js.map +7 -0
- package/dist/utils/{resolveReferences.test.js → resolve-references.test.js} +4 -4
- package/dist/utils/{resolveReferences.test.js.map → resolve-references.test.js.map} +3 -3
- package/dist/utils/{toJson.d.ts → to-json.d.ts} +1 -1
- package/dist/utils/to-json.d.ts.map +1 -0
- package/dist/utils/{toJson.js → to-json.js} +1 -1
- package/dist/utils/to-json.js.map +7 -0
- package/dist/utils/{toYaml.d.ts → to-yaml.d.ts} +1 -1
- package/dist/utils/to-yaml.d.ts.map +1 -0
- package/dist/utils/{toYaml.js → to-yaml.js} +1 -1
- package/dist/utils/{toYaml.js.map → to-yaml.js.map} +2 -2
- package/dist/utils/transform/sanitize.d.ts +2 -0
- package/dist/utils/transform/sanitize.d.ts.map +1 -1
- package/dist/utils/transform/sanitize.js.map +2 -2
- package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
- package/dist/utils/transform/utils/addInfoObject.js.map +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +1 -1
- package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
- package/dist/utils/transform/utils/addMissingTags.js.map +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +1 -1
- package/dist/utils/{transformErrors.d.ts → transform-errors.d.ts} +1 -1
- package/dist/utils/transform-errors.d.ts.map +1 -0
- package/dist/utils/{transformErrors.js → transform-errors.js} +1 -1
- package/dist/utils/transform-errors.js.map +7 -0
- package/dist/utils/{transformErrors.test.js → transform-errors.test.js} +3 -3
- package/dist/utils/transform-errors.test.js.map +7 -0
- package/dist/utils/traverse.d.ts.map +1 -1
- package/dist/utils/traverse.js.map +1 -1
- package/dist/utils/{unescapeJsonPointer.d.ts → unescape-json-pointer.d.ts} +1 -1
- package/dist/utils/unescape-json-pointer.d.ts.map +1 -0
- package/dist/utils/{unescapeJsonPointer.js → unescape-json-pointer.js} +1 -1
- package/dist/utils/{unescapeJsonPointer.js.map → unescape-json-pointer.js.map} +1 -1
- package/dist/utils/{unescapeJsonPointer.test.js → unescape-json-pointer.test.js} +2 -2
- package/dist/utils/unescape-json-pointer.test.js.map +7 -0
- package/dist/utils/{upgradeFromThreeToThreeOne.d.ts → upgrade-from-three-to-three-one.d.ts} +1 -1
- package/dist/utils/upgrade-from-three-to-three-one.d.ts.map +1 -0
- package/dist/utils/{upgradeFromThreeToThreeOne.js → upgrade-from-three-to-three-one.js} +1 -2
- package/dist/utils/upgrade-from-three-to-three-one.js.map +7 -0
- package/dist/utils/{upgradeFromThreeToThreeOne.test.js → upgrade-from-three-to-three-one.test.js} +2 -2
- package/dist/utils/upgrade-from-three-to-three-one.test.js.map +7 -0
- package/dist/utils/{upgradeFromTwoToThree.d.ts → upgrade-from-two-to-three.d.ts} +1 -1
- package/dist/utils/upgrade-from-two-to-three.d.ts.map +1 -0
- package/dist/utils/{upgradeFromTwoToThree.js → upgrade-from-two-to-three.js} +1 -1
- package/dist/utils/{upgradeFromTwoToThree.js.map → upgrade-from-two-to-three.js.map} +1 -1
- package/dist/utils/{upgradeFromTwoToThree.test.js → upgrade-from-two-to-three.test.js} +2 -2
- package/dist/utils/upgrade-from-two-to-three.test.js.map +7 -0
- package/dist/utils/upgrade.bench.js +1 -1
- package/dist/utils/upgrade.bench.js.map +1 -1
- package/dist/utils/upgrade.d.ts.map +1 -1
- package/dist/utils/upgrade.js +4 -4
- package/dist/utils/upgrade.js.map +1 -1
- package/dist/utils/upgrade.test.js +1 -1
- package/dist/utils/upgrade.test.js.map +1 -1
- package/dist/utils/validate.d.ts.map +1 -1
- package/dist/utils/validate.js +1 -1
- package/dist/utils/validate.js.map +1 -1
- package/package.json +2 -2
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +0 -1
- package/dist/plugins/fetch-urls/fetchUrls.js.map +0 -7
- package/dist/plugins/fetch-urls/fetchUrls.test.js.map +0 -7
- package/dist/plugins/read-files/readFiles.d.ts.map +0 -1
- package/dist/plugins/read-files/readFiles.js.map +0 -7
- package/dist/plugins/read-files/readFiles.test.js.map +0 -7
- package/dist/utils/escapeJsonPointer.d.ts.map +0 -1
- package/dist/utils/escapeJsonPointer.test.js.map +0 -7
- package/dist/utils/getEntrypoint.d.ts.map +0 -1
- package/dist/utils/getEntrypoint.js.map +0 -7
- package/dist/utils/getEntrypoint.test.js.map +0 -7
- package/dist/utils/getListOfReferences.d.ts.map +0 -1
- package/dist/utils/getListOfReferences.js.map +0 -7
- package/dist/utils/getSegmentsFromPath.d.ts.map +0 -1
- package/dist/utils/getSegmentsFromPath.js.map +0 -7
- package/dist/utils/getSegmentsFromPath.test.js.map +0 -7
- package/dist/utils/index.d.ts +0 -27
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -27
- package/dist/utils/index.js.map +0 -7
- package/dist/utils/isFilesystem.d.ts.map +0 -1
- package/dist/utils/isFilesystem.js.map +0 -7
- package/dist/utils/isJson.d.ts.map +0 -1
- package/dist/utils/isObject.d.ts.map +0 -1
- package/dist/utils/isObject.test.js.map +0 -7
- package/dist/utils/isYaml.d.ts.map +0 -1
- package/dist/utils/makeFilesystem.d.ts.map +0 -1
- package/dist/utils/makeFilesystem.js.map +0 -7
- package/dist/utils/makeFilesystem.test.js.map +0 -7
- package/dist/utils/openapi/actions/details.d.ts +0 -7
- package/dist/utils/openapi/actions/details.d.ts.map +0 -1
- package/dist/utils/openapi/actions/details.js +0 -11
- package/dist/utils/openapi/actions/details.js.map +0 -7
- package/dist/utils/openapi/actions/files.d.ts +0 -6
- package/dist/utils/openapi/actions/files.d.ts.map +0 -1
- package/dist/utils/openapi/actions/files.js +0 -9
- package/dist/utils/openapi/actions/files.js.map +0 -7
- package/dist/utils/openapi/actions/get.d.ts +0 -6
- package/dist/utils/openapi/actions/get.d.ts.map +0 -1
- package/dist/utils/openapi/actions/get.js +0 -11
- package/dist/utils/openapi/actions/get.js.map +0 -7
- package/dist/utils/openapi/actions/toJson.d.ts +0 -6
- package/dist/utils/openapi/actions/toJson.d.ts.map +0 -1
- package/dist/utils/openapi/actions/toJson.js +0 -11
- package/dist/utils/openapi/actions/toJson.js.map +0 -7
- package/dist/utils/openapi/actions/toYaml.d.ts +0 -6
- package/dist/utils/openapi/actions/toYaml.d.ts.map +0 -1
- package/dist/utils/openapi/actions/toYaml.js +0 -11
- package/dist/utils/openapi/actions/toYaml.js.map +0 -7
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts +0 -27
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +0 -1
- package/dist/utils/openapi/commands/dereferenceCommand.js +0 -27
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +0 -7
- package/dist/utils/openapi/commands/filterCommand.d.ts +0 -41
- package/dist/utils/openapi/commands/filterCommand.d.ts.map +0 -1
- package/dist/utils/openapi/commands/filterCommand.js +0 -26
- package/dist/utils/openapi/commands/filterCommand.js.map +0 -7
- package/dist/utils/openapi/commands/loadCommand.d.ts +0 -8321
- package/dist/utils/openapi/commands/loadCommand.d.ts.map +0 -1
- package/dist/utils/openapi/commands/loadCommand.js +0 -42
- package/dist/utils/openapi/commands/loadCommand.js.map +0 -7
- package/dist/utils/openapi/commands/upgradeCommand.d.ts +0 -3406
- package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +0 -1
- package/dist/utils/openapi/commands/upgradeCommand.js +0 -29
- package/dist/utils/openapi/commands/upgradeCommand.js.map +0 -7
- package/dist/utils/openapi/commands/validateCommand.d.ts +0 -3451
- package/dist/utils/openapi/commands/validateCommand.d.ts.map +0 -1
- package/dist/utils/openapi/commands/validateCommand.js +0 -33
- package/dist/utils/openapi/commands/validateCommand.js.map +0 -7
- package/dist/utils/openapi/index.d.ts +0 -2
- package/dist/utils/openapi/index.d.ts.map +0 -1
- package/dist/utils/openapi/index.js +0 -2
- package/dist/utils/openapi/index.js.map +0 -7
- package/dist/utils/openapi/openapi.d.ts +0 -1272
- package/dist/utils/openapi/openapi.d.ts.map +0 -1
- package/dist/utils/openapi/openapi.js +0 -15
- package/dist/utils/openapi/openapi.js.map +0 -7
- package/dist/utils/openapi/openapi.test-d.d.ts +0 -2
- package/dist/utils/openapi/openapi.test-d.d.ts.map +0 -1
- package/dist/utils/openapi/openapi.test-d.js +0 -14
- package/dist/utils/openapi/openapi.test-d.js.map +0 -7
- package/dist/utils/openapi/openapi.test.js +0 -309
- package/dist/utils/openapi/openapi.test.js.map +0 -7
- package/dist/utils/openapi/utils/queueTask.d.ts +0 -6
- package/dist/utils/openapi/utils/queueTask.d.ts.map +0 -1
- package/dist/utils/openapi/utils/queueTask.js +0 -10
- package/dist/utils/openapi/utils/queueTask.js.map +0 -7
- package/dist/utils/openapi/utils/workThroughQueue.d.ts +0 -6
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +0 -1
- package/dist/utils/openapi/utils/workThroughQueue.js +0 -52
- package/dist/utils/openapi/utils/workThroughQueue.js.map +0 -7
- package/dist/utils/openapi/utils/workThroughQueue.test.js +0 -244
- package/dist/utils/openapi/utils/workThroughQueue.test.js.map +0 -7
- package/dist/utils/resolveReferences.js.map +0 -7
- package/dist/utils/toJson.d.ts.map +0 -1
- package/dist/utils/toJson.js.map +0 -7
- package/dist/utils/toYaml.d.ts.map +0 -1
- package/dist/utils/transform/index.d.ts +0 -2
- package/dist/utils/transform/index.d.ts.map +0 -1
- package/dist/utils/transform/index.js +0 -2
- package/dist/utils/transform/index.js.map +0 -7
- package/dist/utils/transformErrors.d.ts.map +0 -1
- package/dist/utils/transformErrors.js.map +0 -7
- package/dist/utils/transformErrors.test.js.map +0 -7
- package/dist/utils/unescapeJsonPointer.d.ts.map +0 -1
- package/dist/utils/unescapeJsonPointer.test.js.map +0 -7
- package/dist/utils/upgradeFromThreeToThreeOne.d.ts.map +0 -1
- package/dist/utils/upgradeFromThreeToThreeOne.js.map +0 -7
- package/dist/utils/upgradeFromThreeToThreeOne.test.js.map +0 -7
- package/dist/utils/upgradeFromTwoToThree.d.ts.map +0 -1
- package/dist/utils/upgradeFromTwoToThree.test.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ERRORS } from "../configuration/index.js";
|
|
2
|
-
import { getEntrypoint } from "./
|
|
3
|
-
import { getSegmentsFromPath } from "./
|
|
4
|
-
import { makeFilesystem } from "./
|
|
2
|
+
import { getEntrypoint } from "./get-entrypoint.js";
|
|
3
|
+
import { getSegmentsFromPath } from "./get-segments-from-path.js";
|
|
4
|
+
import { makeFilesystem } from "./make-filesystem.js";
|
|
5
5
|
function resolveReferences(input, options, file, errors = []) {
|
|
6
6
|
const clonedInput = structuredClone(input);
|
|
7
7
|
const filesystem = makeFilesystem(clonedInput);
|
|
@@ -99,4 +99,4 @@ function resolveUri(uri, options, file, filesystem, resolve, errors) {
|
|
|
99
99
|
export {
|
|
100
100
|
resolveReferences
|
|
101
101
|
};
|
|
102
|
-
//# sourceMappingURL=
|
|
102
|
+
//# sourceMappingURL=resolve-references.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/resolve-references.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport { ERRORS } from '@/configuration'\nimport type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '@/types/index'\nimport { getEntrypoint } from './get-entrypoint'\nimport { getSegmentsFromPath } from './get-segments-from-path'\nimport { makeFilesystem } from './make-filesystem'\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('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n }\n\n return undefined\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,cAAc;AAEvB,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AA8BxB,SAAS,kBAEd,OAEA,SAEA,MAEA,SAAwB,CAAC,GACA;AAEzB,QAAM,cAAc,gBAAgB,KAAK;AAGzC,QAAM,aAAa,eAAe,WAAW;AAG7C,QAAM,aAAa,cAAc,UAAU;AAE3C,QAAM,aAAa,MAAM,iBAAiB,WAAW;AAGrD,cAAY,YAAY,YAAY,QAAQ,YAAY,oBAAI,QAAQ,GAAG,QAAQ,OAAO;AAGtF,WAAS,OAAO;AAAA,IACd,CAAC,OAAO,OAAO,SAAS,UAAU,KAAK,UAAU,CAAC,MAAM,EAAE,YAAY,MAAM,WAAW,EAAE,SAAS,MAAM,IAAI;AAAA,EAC9G;AAGA,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,IACA,QAAQ;AAAA,EACV;AACF;AAKA,SAAS,YACP,QACA,YACA,YAEA,iBAEA,QAEA,SACM;AACN,MAAI,WAAW,QAAQ,gBAAgB,IAAI,M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WAAW,KAAK,CAAC,UAAU;AACnD,aAAO,MAAM,aAAa;AAAA,IAC5B,CAAC;AAED,QAAI,CAAC,mBAAmB;AACtB,UAAI,SAAS,cAAc;AACzB,cAAM,IAAI,MAAM,OAAO,6BAA6B,QAAQ,MAAM,MAAM,CAAC;AAAA,MAC3E;AAEA,aAAO,KAAK;AAAA,QACV,MAAM;AAAA,QACN,SAAS,OAAO,6BAA6B,QAAQ,MAAM,MAAM;AAAA,MACnE,CAAC;AAED,aAAO;AAAA,IACT;AAEA,QAAI,SAAS,QAAW;AACtB,aAAO,kBAAkB;AAAA,IAC3B;AAIA,WAAO,WAAW,IAAI,IAAI,IAAI,SAAS,QAAQ,iBAAiB,GAAG,YAAY,SAAS,MAAM;AAAA,EAChG;AAGA,QAAM,WAAW,oBAAoB,IAAI;AAGzC,MAAI;AACF,WAAO,SAAS,OAAO,CAAC,KAAK,QAAQ;AACnC,aAAO,IAAI,GAAG;AAAA,IAChB,GAAG,KAAK,aAAa;AAAA,EACvB,SAAS,QAAQ;AACf,QAAI,SAAS,cAAc;AACzB,YAAM,IAAI,MAAM,OAAO,kBAAkB,QAAQ,MAAM,GAAG,CAAC;AAAA,IAC7D;AAEA,WAAO,KAAK;AAAA,MACV,MAAM;AAAA,MACN,SAAS,OAAO,kBAAkB,QAAQ,MAAM,GAAG;AAAA,IACrD,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
2
1
|
import path from "node:path";
|
|
2
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
|
-
import { readFiles } from "../plugins/read-files/
|
|
4
|
+
import { readFiles } from "../plugins/read-files/read-files.js";
|
|
5
5
|
import { load } from "./load/load.js";
|
|
6
|
-
import { resolveReferences } from "./
|
|
6
|
+
import { resolveReferences } from "./resolve-references.js";
|
|
7
7
|
const EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, "../../../tests/filesystem/api/openapi.yaml");
|
|
8
8
|
describe("resolveReferences", () => {
|
|
9
9
|
it("resolves a single reference", async () => {
|
|
@@ -564,4 +564,4 @@ describe("resolveReferences", () => {
|
|
|
564
564
|
expect(schema.paths["/foobar"].post.requestBody.content["application/json"].schema.example).toBe("foobar");
|
|
565
565
|
});
|
|
566
566
|
});
|
|
567
|
-
//# sourceMappingURL=
|
|
567
|
+
//# sourceMappingURL=resolve-references.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
4
|
-
"sourcesContent": ["/**\n * This file has some simple tests to cover the basics of the resolveReferences function.\n * Doesn\u2019t cover all edge cases, doesn\u2019t have big files, but if this works you\u2019re almost there.\n */\nimport SwaggerParser from '@apidevtools/swagger-parser'\nimport path from 'node:path'\nimport { describe, expect, it } from 'vitest'\n\nimport { readFiles } from '../plugins/read-files/readFiles'\nimport type { AnyObject } from '../types/index'\nimport { load } from './load/load'\nimport { resolveReferences } from './resolveReferences'\n\nconst EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, '../../../tests/filesystem/api/openapi.yaml')\n\ndescribe('resolveReferences', () => {\n it('resolves a single reference', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {},\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content).not.toBe(undefined)\n })\n\n it('returns an error when a reference can\u2019t be found', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/WrongReference',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { valid, errors } = resolveReferences(specification)\n\n // Assertion\n expect(errors).not.toBe(undefined)\n expect(errors).not.toStrictEqual([])\n expect(errors[0].message).toBe('Can\u2019t resolve reference: #/components/WrongReference')\n expect(errors.length).toBe(1)\n expect(valid).toBe(false)\n })\n\n it('returns an error when an external reference can\u2019t be found', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'foo/bar/foobar.yaml#/components/WrongReference',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { valid, errors } = resolveReferences(specification)\n\n // Assertion\n expect(errors).not.toBe(undefined)\n expect(errors).not.toStrictEqual([])\n expect(errors[0].message).toBe('Can\u2019t resolve external reference: foo/bar/foobar.yaml')\n expect(errors.length).toBe(1)\n expect(valid).toBe(false)\n })\n\n it('matches output of @apidevtools/swagger-parser', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {},\n },\n },\n },\n }\n\n // Run the specification through the old parser\n const oldSchema = (await new Promise((resolve, reject) => {\n SwaggerParser.dereference(structuredClone(specification) as never, (error, result) => {\n if (error) {\n reject(error)\n }\n\n if (result === undefined) {\n reject('Couldn\u2019t parse the Swagger file.')\n\n return\n }\n resolve(result)\n })\n }).catch((error) => {\n console.error('[@apidevtools/swagger-parser]', error)\n })) as any\n\n // Run the specification through our new parser\n const newParser = resolveReferences(specification)\n\n // Assertion\n expect(newParser.schema.paths['/foobar'].post.requestBody).toMatchObject(\n oldSchema.paths['/foobar'].post.requestBody,\n )\n })\n\n it('resolves references inside references', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n\n components: {\n requestBodies: {\n CursorRequest: {\n content: {},\n },\n Foobar: {\n // This is a reference to another reference\n $ref: '#/components/requestBodies/CursorRequest',\n },\n },\n },\n }\n\n // Run the specification through the old parser\n const oldSchema = (await new Promise((resolve, reject) => {\n SwaggerParser.dereference(structuredClone(specification) as never, (error, result) => {\n if (error) {\n reject(error)\n }\n\n if (result === undefined) {\n reject('Couldn\u2019t parse the Swagger file.')\n\n return\n }\n resolve(result)\n })\n }).catch((error) => {\n console.error('[@apidevtools/swagger-parser]', error)\n })) as any\n\n // Run the specification through our new parser\n const newParser = resolveReferences(specification)\n\n // Assertion\n expect(newParser.schema.paths['/foobar'].post.requestBody).toMatchObject(\n oldSchema.paths['/foobar'].post.requestBody,\n )\n })\n\n it('resolves references in arrays', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n\n components: {\n schemas: {\n Barfoo: {\n type: 'string',\n example: 'barfoo',\n },\n },\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n oneOf: [\n {\n $ref: '#/components/schemas/Barfoo',\n },\n ],\n },\n },\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.oneOf[0]).toMatchObject({\n type: 'string',\n example: 'barfoo',\n })\n })\n\n it('merges original properties and referenced content', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n schemas: {\n Barfoo: {\n type: 'string',\n example: 'barfoo',\n },\n },\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n oneOf: [\n {\n description: 'This is a barfoo',\n $ref: '#/components/schemas/Barfoo',\n },\n ],\n },\n },\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.oneOf[0]).toMatchObject({\n type: 'string',\n example: 'barfoo',\n description: 'This is a barfoo',\n })\n })\n\n it('references inside references still keep the reference to the original JS object', async () => {\n const specification = {\n swagger: '2.0',\n info: {\n title: 'Branded Fares Upsell',\n version: '1.0.1',\n },\n paths: {\n '/foobar': {\n post: {\n responses: {\n '200': {\n $ref: '#/responses/returnUpsell',\n },\n },\n },\n },\n },\n responses: {\n returnUpsell: {\n schema: {\n type: 'object',\n properties: {\n dictionaries: {\n $ref: '#/definitions/LocationEntry',\n },\n },\n },\n },\n },\n definitions: {\n Dictionaries: {\n type: 'object',\n properties: {\n locations: {\n $ref: '#/definitions/LocationEntry',\n },\n },\n },\n LocationEntry: {\n additionalProperties: {\n $ref: '#/definitions/LocationValue',\n },\n },\n LocationValue: {\n properties: {\n cityCode: {\n description: 'City code associated to the airport',\n example: 'PAR',\n type: 'string',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.swagger).toBe('2.0')\n expect(\n schema.paths['/foobar'].post.responses[200].schema.properties.dictionaries.additionalProperties,\n ).toMatchObject({\n properties: {\n cityCode: {\n description: 'City code associated to the airport',\n example: 'PAR',\n type: 'string',\n },\n },\n })\n })\n\n it('resolves a simple circular reference', async () => {\n const partialSpecification: AnyObject = {\n foo: {\n bar: {\n $ref: '#/foo',\n },\n },\n }\n\n const { schema } = resolveReferences(partialSpecification)\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n\n // Sky is the limit\n expect(schema.foo.bar.bar.bar.bar.bar.bar.bar.bar).toBeTypeOf('object')\n })\n\n it('resolves a more advanced circular reference', async () => {\n const partialSpecification: AnyObject = {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n foobar: { $ref: '#/schemas/foobar' },\n },\n schemas: {\n element: {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n },\n foobar: {\n type: 'object',\n properties: {\n foobar: { $ref: '#/schemas/foobar' },\n },\n },\n },\n }\n\n // Typecasting: We\u2019re misusing the function and pass a partial specification only.\n const { schema } = resolveReferences(partialSpecification) as any\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n\n // Sky is the liit\n expect(schema.schemas.element.properties.element.properties.element.properties.element).toBeTypeOf('object')\n })\n\n it('resolves an OpenAPI-like circular reference', async () => {\n const specification = {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n schemas: {\n element: {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n },\n },\n }\n\n const { schema } = resolveReferences(specification)\n\n // Original specification should not be mutated\n expect(specification.properties.element.$ref).toBeTypeOf('string')\n\n // Circular dependency should be resolved\n expect(schema.properties.element.type).toBe('object')\n expect(schema.properties.element.properties.element.type).toBe('object')\n expect(schema.properties.element.properties.element.properties.element.type).toBe('object')\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n })\n\n it('composes two files', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'other/folder/foobar.json',\n specification: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves reference to a part of an external file', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'other/folder/foobar.json',\n specification: {\n components: {\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves references in external files', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: ['barfoo.json'],\n filename: 'other/folder/foobar.json',\n specification: {\n components: {\n requestBodies: {\n Foobar: {\n $ref: 'barfoo.json',\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'barfoo.json',\n specification: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves from filesystem', async () => {\n const { filesystem } = await load(EXAMPLE_FILE, {\n plugins: [readFiles()],\n })\n\n const { schema } = resolveReferences(filesystem)\n\n // Resolve the *path* from the given file\n expect(schema.components.schemas.Upload.allOf[0].title).toBe('Coordinates')\n })\n\n it('resolves reference to self by filename', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: [],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'openapi.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAIA,OAAO,mBAAmB;AAC1B,OAAO,UAAU;AACjB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,YAAY;AACrB,SAAS,yBAAyB;AAElC,MAAM,eAAe,KAAK,KAAK,IAAI,IAAI,YAAY,GAAG,EAAE,UAAU,4CAA4C;AAE9G,SAAS,qBAAqB,MAAM;AAClC,KAAG,+BAA+B,YAAY;AAC5C,UAAM,gBAAgB;AAAA,MACpB,SAAS;AAAA,MACT,MAAM,CAAC;AAAA,MACP,OAAO;AAAA,QACL,WAAW;AAAA,UACT,MAAM;AAAA,YACJ,aAAa;AAAA,cACX,MAAM;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,YAAY;AAAA,QACV,eAAe;AAAA,UACb,QAAQ;AAAA,YACN,SAAS,CAAC;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,UAAM,EAAE,OAAO,IAAI,kBAAkB,aAAa;AAGlD,WAAO,OAAO,MAAM,SAAS,EAAE,KAAK,YAAY,OAAO,EAAE,IAAI,KAAK,MAAS;AAAA,EAC7E,CAAC;AAED,KAAG,yDAAoD,YAAY;AACjE,UAAM,gBAAgB;AAAA,MACpB,SAAS;AAAA,MACT,MAAM,CAAC;AAAA,MACP,OAAO;AAAA,QACL,WAAW;AAAA,UACT,MAAM;AAAA,YACJ,a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,CAAC,UAAU,CAAC;AAAA,IACvB,CAAC;AAED,UAAM,EAAE,OAAO,IAAI,kBAAkB,UAAU;AAG/C,WAAO,OAAO,WAAW,QAAQ,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,aAAa;AAAA,EAC5E,CAAC;AAED,KAAG,0CAA0C,YAAY;AACvD,UAAM,aAAa;AAAA,MACjB;AAAA,QACE,KAAK;AAAA,QACL,cAAc;AAAA,QACd,YAAY,CAAC;AAAA,QACb,UAAU;AAAA,QACV,eAAe;AAAA,UACb,SAAS;AAAA,UACT,MAAM,CAAC;AAAA,UACP,OAAO;AAAA,YACL,WAAW;AAAA,cACT,MAAM;AAAA,gBACJ,aAAa;AAAA,kBACX,MAAM;AAAA,gBACR;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA,YAAY;AAAA,YACV,eAAe;AAAA,cACb,QAAQ;AAAA,gBACN,SAAS;AAAA,kBACP,oBAAoB;AAAA,oBAClB,QAAQ;AAAA,sBACN,MAAM;AAAA,sBACN,SAAS;AAAA,oBACX;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI,kBAAkB,UAAU;AAC/C,WAAO,OAAO,MAAM,SAAS,EAAE,KAAK,YAAY,QAAQ,kBAAkB,EAAE,OAAO,OAAO,EAAE,KAAK,QAAQ;AAAA,EAC3G,CAAC;AACH,CAAC;",
|
|
3
|
+
"sources": ["../../src/utils/resolve-references.test.ts"],
|
|
4
|
+
"sourcesContent": ["import path from 'node:path'\n/**\n * This file has some simple tests to cover the basics of the resolveReferences function.\n * Doesn\u2019t cover all edge cases, doesn\u2019t have big files, but if this works you\u2019re almost there.\n */\nimport SwaggerParser from '@apidevtools/swagger-parser'\nimport { describe, expect, it } from 'vitest'\n\nimport { readFiles } from '@/plugins/read-files/read-files'\nimport type { AnyObject } from '@/types/index'\nimport { load } from './load/load'\nimport { resolveReferences } from './resolve-references'\n\nconst EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, '../../../tests/filesystem/api/openapi.yaml')\n\ndescribe('resolveReferences', () => {\n it('resolves a single reference', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {},\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content).not.toBe(undefined)\n })\n\n it('returns an error when a reference can\u2019t be found', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/WrongReference',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { valid, errors } = resolveReferences(specification)\n\n // Assertion\n expect(errors).not.toBe(undefined)\n expect(errors).not.toStrictEqual([])\n expect(errors[0].message).toBe('Can\u2019t resolve reference: #/components/WrongReference')\n expect(errors.length).toBe(1)\n expect(valid).toBe(false)\n })\n\n it('returns an error when an external reference can\u2019t be found', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'foo/bar/foobar.yaml#/components/WrongReference',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { valid, errors } = resolveReferences(specification)\n\n // Assertion\n expect(errors).not.toBe(undefined)\n expect(errors).not.toStrictEqual([])\n expect(errors[0].message).toBe('Can\u2019t resolve external reference: foo/bar/foobar.yaml')\n expect(errors.length).toBe(1)\n expect(valid).toBe(false)\n })\n\n it('matches output of @apidevtools/swagger-parser', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {},\n },\n },\n },\n }\n\n // Run the specification through the old parser\n const oldSchema = (await new Promise((resolve, reject) => {\n SwaggerParser.dereference(structuredClone(specification) as never, (error, result) => {\n if (error) {\n reject(error)\n }\n\n if (result === undefined) {\n reject('Couldn\u2019t parse the Swagger file.')\n\n return\n }\n resolve(result)\n })\n }).catch((error) => {\n console.error('[@apidevtools/swagger-parser]', error)\n })) as any\n\n // Run the specification through our new parser\n const newParser = resolveReferences(specification)\n\n // Assertion\n expect(newParser.schema.paths['/foobar'].post.requestBody).toMatchObject(\n oldSchema.paths['/foobar'].post.requestBody,\n )\n })\n\n it('resolves references inside references', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n\n components: {\n requestBodies: {\n CursorRequest: {\n content: {},\n },\n Foobar: {\n // This is a reference to another reference\n $ref: '#/components/requestBodies/CursorRequest',\n },\n },\n },\n }\n\n // Run the specification through the old parser\n const oldSchema = (await new Promise((resolve, reject) => {\n SwaggerParser.dereference(structuredClone(specification) as never, (error, result) => {\n if (error) {\n reject(error)\n }\n\n if (result === undefined) {\n reject('Couldn\u2019t parse the Swagger file.')\n\n return\n }\n resolve(result)\n })\n }).catch((error) => {\n console.error('[@apidevtools/swagger-parser]', error)\n })) as any\n\n // Run the specification through our new parser\n const newParser = resolveReferences(specification)\n\n // Assertion\n expect(newParser.schema.paths['/foobar'].post.requestBody).toMatchObject(\n oldSchema.paths['/foobar'].post.requestBody,\n )\n })\n\n it('resolves references in arrays', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n\n components: {\n schemas: {\n Barfoo: {\n type: 'string',\n example: 'barfoo',\n },\n },\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n oneOf: [\n {\n $ref: '#/components/schemas/Barfoo',\n },\n ],\n },\n },\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.oneOf[0]).toMatchObject({\n type: 'string',\n example: 'barfoo',\n })\n })\n\n it('merges original properties and referenced content', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: '#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n schemas: {\n Barfoo: {\n type: 'string',\n example: 'barfoo',\n },\n },\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n oneOf: [\n {\n description: 'This is a barfoo',\n $ref: '#/components/schemas/Barfoo',\n },\n ],\n },\n },\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.oneOf[0]).toMatchObject({\n type: 'string',\n example: 'barfoo',\n description: 'This is a barfoo',\n })\n })\n\n it('references inside references still keep the reference to the original JS object', async () => {\n const specification = {\n swagger: '2.0',\n info: {\n title: 'Branded Fares Upsell',\n version: '1.0.1',\n },\n paths: {\n '/foobar': {\n post: {\n responses: {\n '200': {\n $ref: '#/responses/returnUpsell',\n },\n },\n },\n },\n },\n responses: {\n returnUpsell: {\n schema: {\n type: 'object',\n properties: {\n dictionaries: {\n $ref: '#/definitions/LocationEntry',\n },\n },\n },\n },\n },\n definitions: {\n Dictionaries: {\n type: 'object',\n properties: {\n locations: {\n $ref: '#/definitions/LocationEntry',\n },\n },\n },\n LocationEntry: {\n additionalProperties: {\n $ref: '#/definitions/LocationValue',\n },\n },\n LocationValue: {\n properties: {\n cityCode: {\n description: 'City code associated to the airport',\n example: 'PAR',\n type: 'string',\n },\n },\n },\n },\n }\n\n // Run the specification through our new parser\n const { schema } = resolveReferences(specification)\n\n // Assertion\n expect(schema.swagger).toBe('2.0')\n expect(\n schema.paths['/foobar'].post.responses[200].schema.properties.dictionaries.additionalProperties,\n ).toMatchObject({\n properties: {\n cityCode: {\n description: 'City code associated to the airport',\n example: 'PAR',\n type: 'string',\n },\n },\n })\n })\n\n it('resolves a simple circular reference', async () => {\n const partialSpecification: AnyObject = {\n foo: {\n bar: {\n $ref: '#/foo',\n },\n },\n }\n\n const { schema } = resolveReferences(partialSpecification)\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n\n // Sky is the limit\n expect(schema.foo.bar.bar.bar.bar.bar.bar.bar.bar).toBeTypeOf('object')\n })\n\n it('resolves a more advanced circular reference', async () => {\n const partialSpecification: AnyObject = {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n foobar: { $ref: '#/schemas/foobar' },\n },\n schemas: {\n element: {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n },\n foobar: {\n type: 'object',\n properties: {\n foobar: { $ref: '#/schemas/foobar' },\n },\n },\n },\n }\n\n // Typecasting: We\u2019re misusing the function and pass a partial specification only.\n const { schema } = resolveReferences(partialSpecification) as any\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n\n // Sky is the liit\n expect(schema.schemas.element.properties.element.properties.element.properties.element).toBeTypeOf('object')\n })\n\n it('resolves an OpenAPI-like circular reference', async () => {\n const specification = {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n schemas: {\n element: {\n type: 'object',\n properties: {\n element: { $ref: '#/schemas/element' },\n },\n },\n },\n }\n\n const { schema } = resolveReferences(specification)\n\n // Original specification should not be mutated\n expect(specification.properties.element.$ref).toBeTypeOf('string')\n\n // Circular dependency should be resolved\n expect(schema.properties.element.type).toBe('object')\n expect(schema.properties.element.properties.element.type).toBe('object')\n expect(schema.properties.element.properties.element.properties.element.type).toBe('object')\n\n // Circular references can\u2019t be JSON.stringify\u2019d (easily)\n expect(() => JSON.stringify(schema, null, 2)).toThrow()\n })\n\n it('composes two files', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'other/folder/foobar.json',\n specification: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves reference to a part of an external file', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'other/folder/foobar.json',\n specification: {\n components: {\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves references in external files', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: ['other/folder/foobar.json'],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'other/folder/foobar.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: ['barfoo.json'],\n filename: 'other/folder/foobar.json',\n specification: {\n components: {\n requestBodies: {\n Foobar: {\n $ref: 'barfoo.json',\n },\n },\n },\n },\n },\n {\n dir: '/Foobar/other/folder',\n isEntrypoint: false,\n references: [],\n filename: 'barfoo.json',\n specification: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n\n it('resolves from filesystem', async () => {\n const { filesystem } = await load(EXAMPLE_FILE, {\n plugins: [readFiles()],\n })\n\n const { schema } = resolveReferences(filesystem)\n\n // Resolve the *path* from the given file\n expect(schema.components.schemas.Upload.allOf[0].title).toBe('Coordinates')\n })\n\n it('resolves reference to self by filename', async () => {\n const filesystem = [\n {\n dir: '/Foobar',\n isEntrypoint: true,\n references: [],\n filename: 'openapi.json',\n specification: {\n openapi: '3.1.0',\n info: {},\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'openapi.json#/components/requestBodies/Foobar',\n },\n },\n },\n },\n components: {\n requestBodies: {\n Foobar: {\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n },\n ]\n\n const { schema } = resolveReferences(filesystem)\n expect(schema.paths['/foobar'].post.requestBody.content['application/json'].schema.example).toBe('foobar')\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,UAAU;AAKjB,OAAO,mBAAmB;AAC1B,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,YAAY;AACrB,SAAS,yBAAyB;AAElC,MAAM,eAAe,KAAK,KAAK,IAAI,IAAI,YAAY,GAAG,EAAE,UAAU,4CAA4C;AAE9G,SAAS,qBAAqB,MAAM;AAClC,KAAG,+BAA+B,YAAY;AAC5C,UAAM,gBAAgB;AAAA,MACpB,SAAS;AAAA,MACT,MAAM,CAAC;AAAA,MACP,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;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI,kBAAkB,UAAU;AAC/C,WAAO,OAAO,MAAM,SAAS,EAAE,KAAK,YAAY,QAAQ,kBAAkB,EAAE,OAAO,OAAO,EAAE,KAAK,QAAQ;AAAA,EAC3G,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-json.d.ts","sourceRoot":"","sources":["../../src/utils/to-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,MAAM,UAAW,SAAS,WAAmC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/to-json.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const toJson = (value: AnyObject) => JSON.stringify(value, null, 2)\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,SAAS,CAAC,UAAqB,KAAK,UAAU,OAAO,MAAM,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-yaml.d.ts","sourceRoot":"","sources":["../../src/utils/to-yaml.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,MAAM,UAAW,SAAS,WAAqB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
4
|
-
"sourcesContent": ["import { stringify } from 'yaml'\n\nimport type { AnyObject } from '
|
|
3
|
+
"sources": ["../../src/utils/to-yaml.ts"],
|
|
4
|
+
"sourcesContent": ["import { stringify } from 'yaml'\n\nimport type { AnyObject } from '@/types/index'\n\nexport const toYaml = (value: AnyObject) => stringify(value)\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,iBAAiB;AAInB,MAAM,SAAS,CAAC,UAAqB,UAAU,KAAK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,6 +4,8 @@ export { DEFAULT_OPENAPI_VERSION } from './utils/addLatestOpenApiVersion.js';
|
|
|
4
4
|
export { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/addInfoObject.js';
|
|
5
5
|
/**
|
|
6
6
|
* Make an OpenAPI document a valid and clean OpenAPI document
|
|
7
|
+
*
|
|
8
|
+
* @deprecated We’re about to drop this from the package.
|
|
7
9
|
*/
|
|
8
10
|
export declare function sanitize(definition: AnyObject): OpenAPI.Document;
|
|
9
11
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/utils/transform/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/utils/transform/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAO9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEtE;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAUhE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/transform/sanitize.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport type { AnyObject } from '
|
|
5
|
-
"mappings": "AAGA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;AAEvC,SAAS,+BAA+B;AACxC,SAAS,eAAe,uBAAuB;
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport type { AnyObject } from '@/types/index'\nimport { addInfoObject } from './utils/addInfoObject'\nimport { addLatestOpenApiVersion } from './utils/addLatestOpenApiVersion'\nimport { addMissingTags } from './utils/addMissingTags'\nimport { normalizeSecuritySchemes } from './utils/normalizeSecuritySchemes'\nimport { rejectSwaggerDocuments } from './utils/rejectSwaggerDocuments'\n\nexport { DEFAULT_OPENAPI_VERSION } from './utils/addLatestOpenApiVersion'\nexport { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/addInfoObject'\n\n/**\n * Make an OpenAPI document a valid and clean OpenAPI document\n *\n * @deprecated We\u2019re about to drop this from the package.\n */\nexport function sanitize(definition: AnyObject): OpenAPI.Document {\n const transformers = [\n rejectSwaggerDocuments,\n addLatestOpenApiVersion,\n addInfoObject,\n addMissingTags,\n normalizeSecuritySchemes,\n ]\n\n return transformers.reduce((doc, transformer) => transformer(doc), definition)\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;AAEvC,SAAS,+BAA+B;AACxC,SAAS,eAAe,uBAAuB;AAOxC,SAAS,SAAS,YAAyC;AAChE,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,aAAa,OAAO,CAAC,KAAK,gBAAgB,YAAY,GAAG,GAAG,UAAU;AAC/E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addInfoObject.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addInfoObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"addInfoObject.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addInfoObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,aAAa,QAAQ,CAAA;AAClC,eAAO,MAAM,eAAe,QAAQ,CAAA;AAEpC,eAAO,MAAM,aAAa,eAAgB,SAAS;;CAOjD,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/transform/utils/addInfoObject.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const DEFAULT_TITLE = 'API'\nexport const DEFAULT_VERSION = '1.0'\n\nexport const addInfoObject = (definition: AnyObject) => ({\n ...definition,\n info: {\n ...definition.info,\n title: definition.info?.title ?? DEFAULT_TITLE,\n version: definition.info?.version ?? DEFAULT_VERSION,\n },\n})\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AAExB,MAAM,gBAAgB,CAAC,gBAA2B;AAAA,EACvD,GAAG;AAAA,EACH,MAAM;AAAA,IACJ,GAAG,WAAW;AAAA,IACd,OAAO,WAAW,MAAM,SAAS;AAAA,IACjC,SAAS,WAAW,MAAM,WAAW;AAAA,EACvC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addLatestOpenApiVersion.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addLatestOpenApiVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"addLatestOpenApiVersion.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addLatestOpenApiVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,uBAAuB,UAAU,CAAA;AAE9C,eAAO,MAAM,uBAAuB,eAAgB,SAAS;;CAG3D,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/transform/utils/addLatestOpenApiVersion.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const DEFAULT_OPENAPI_VERSION = '3.1.1'\n\nexport const addLatestOpenApiVersion = (definition: AnyObject) => ({\n openapi: definition.openapi ?? DEFAULT_OPENAPI_VERSION,\n ...definition,\n})\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,0BAA0B;AAEhC,MAAM,0BAA0B,CAAC,gBAA2B;AAAA,EACjE,SAAS,WAAW,WAAW;AAAA,EAC/B,GAAG;AACL;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addMissingTags.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addMissingTags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"addMissingTags.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/addMissingTags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,cAAc,eAAgB,SAAS,cAmCnD,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/transform/utils/addMissingTags.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const addMissingTags = (definition: AnyObject) => {\n if (!definition.paths) {\n return definition\n }\n\n // Collect all unique tags used in operations\n const usedTags = new Set<string>()\n for (const path of Object.values(definition.paths)) {\n if (typeof path === 'object' && path !== null) {\n for (const operation of Object.values(path)) {\n if (typeof operation === 'object' && operation !== null && 'tags' in operation) {\n const tags = operation.tags\n\n if (Array.isArray(tags)) {\n tags.forEach((tag) => usedTags.add(String(tag)))\n }\n }\n }\n }\n }\n\n // Convert tags to array of tag objects if not already present\n const existingTags = new Set(\n (Array.isArray(definition.tags) ? definition.tags : [])\n .map((tag) => (typeof tag === 'object' && tag !== null ? String(tag.name) : null))\n .filter(Boolean),\n )\n\n // Add missing tags\n const missingTags = [...usedTags].filter((tag) => !existingTags.has(tag)).map((name) => ({ name }))\n\n return {\n ...definition,\n tags: [...(Array.isArray(definition.tags) ? definition.tags : []), ...missingTags],\n }\n}\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,iBAAiB,CAAC,eAA0B;AACvD,MAAI,CAAC,WAAW,OAAO;AACrB,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,oBAAI,IAAY;AACjC,aAAW,QAAQ,OAAO,OAAO,WAAW,KAAK,GAAG;AAClD,QAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC7C,iBAAW,aAAa,OAAO,OAAO,IAAI,GAAG;AAC3C,YAAI,OAAO,cAAc,YAAY,cAAc,QAAQ,UAAU,WAAW;AAC9E,gBAAM,OAAO,UAAU;AAEvB,cAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,iBAAK,QAAQ,CAAC,QAAQ,SAAS,IAAI,OAAO,GAAG,CAAC,CAAC;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,QAAM,eAAe,IAAI;AAAA,KACtB,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,GAClD,IAAI,CAAC,QAAS,OAAO,QAAQ,YAAY,QAAQ,OAAO,OAAO,IAAI,IAAI,IAAI,IAAK,EAChF,OAAO,OAAO;AAAA,EACnB;AAGA,QAAM,cAAc,CAAC,GAAG,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAElG,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM,CAAC,GAAI,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,GAAI,GAAG,WAAW;AAAA,EACnF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeSecuritySchemes.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/normalizeSecuritySchemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"normalizeSecuritySchemes.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/normalizeSecuritySchemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,wBAAwB,eAAgB,SAAS,cAiD7D,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/transform/utils/normalizeSecuritySchemes.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const normalizeSecuritySchemes = (definition: AnyObject) => {\n if (!definition.components?.securitySchemes) {\n return definition\n }\n\n const securitySchemes = { ...definition.components.securitySchemes }\n\n for (const scheme of Object.values(securitySchemes)) {\n if (typeof scheme === 'object' && scheme !== null && 'type' in scheme) {\n const type = String(scheme.type).toLowerCase()\n scheme.type =\n {\n apikey: 'apiKey',\n oauth2: 'oauth2',\n http: 'http',\n mutualtls: 'mutualTLS',\n openidconnect: 'openIdConnect',\n }[type] ?? type\n }\n }\n\n // Convert array scopes to objects\n for (const scheme of Object.values(securitySchemes)) {\n if (\n typeof scheme === 'object' &&\n scheme !== null &&\n 'type' in scheme &&\n scheme.type === 'oauth2' &&\n 'flows' in scheme\n ) {\n const flows = scheme.flows as AnyObject\n for (const flow of Object.values(flows)) {\n if (typeof flow === 'object' && flow !== null && 'scopes' in flow && Array.isArray(flow.scopes)) {\n flow.scopes = flow.scopes.reduce((acc: AnyObject, scope: string) => {\n acc[scope] = ''\n return acc\n }, {})\n }\n }\n }\n }\n\n return {\n ...definition,\n components: {\n ...definition.components,\n securitySchemes,\n },\n }\n}\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,2BAA2B,CAAC,eAA0B;AACjE,MAAI,CAAC,WAAW,YAAY,iBAAiB;AAC3C,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,EAAE,GAAG,WAAW,WAAW,gBAAgB;AAEnE,aAAW,UAAU,OAAO,OAAO,eAAe,GAAG;AACnD,QAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,UAAU,QAAQ;AACrE,YAAM,OAAO,OAAO,OAAO,IAAI,EAAE,YAAY;AAC7C,aAAO,OACL;AAAA,QACE,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,WAAW;AAAA,QACX,eAAe;AAAA,MACjB,EAAE,IAAI,KAAK;AAAA,IACf;AAAA,EACF;AAGA,aAAW,UAAU,OAAO,OAAO,eAAe,GAAG;AACnD,QACE,OAAO,WAAW,YAClB,WAAW,QACX,UAAU,UACV,OAAO,SAAS,YAChB,WAAW,QACX;AACA,YAAM,QAAQ,OAAO;AACrB,iBAAW,QAAQ,OAAO,OAAO,KAAK,GAAG;AACvC,YAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,YAAY,QAAQ,MAAM,QAAQ,KAAK,MAAM,GAAG;AAC/F,eAAK,SAAS,KAAK,OAAO,OAAO,CAAC,KAAgB,UAAkB;AAClE,gBAAI,KAAK,IAAI;AACb,mBAAO;AAAA,UACT,GAAG,CAAC,CAAC;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY;AAAA,MACV,GAAG,WAAW;AAAA,MACd;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rejectSwaggerDocuments.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/rejectSwaggerDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rejectSwaggerDocuments.d.ts","sourceRoot":"","sources":["../../../../src/utils/transform/utils/rejectSwaggerDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,sBAAsB,cAAe,SAAS,cAM1D,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/transform/utils/rejectSwaggerDocuments.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\nexport const rejectSwaggerDocuments = (defintion: AnyObject) => {\n if ('swagger' in defintion) {\n throw new Error('Swagger 2.0 documents are not supported. Please upgrade to OpenAPI 3.x.')\n }\n\n return defintion\n}\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,yBAAyB,CAAC,cAAyB;AAC9D,MAAI,aAAa,WAAW;AAC1B,UAAM,IAAI,MAAM,yEAAyE;AAAA,EAC3F;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,4 +3,4 @@ import type { AnyObject } from '../types/index.js';
|
|
|
3
3
|
* Transforms ajv errors, finds the positions in the schema and returns an enriched format.
|
|
4
4
|
*/
|
|
5
5
|
export declare function transformErrors(specification: AnyObject, errors: any): any;
|
|
6
|
-
//# sourceMappingURL=
|
|
6
|
+
//# sourceMappingURL=transform-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-errors.d.ts","sourceRoot":"","sources":["../../src/utils/transform-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C;;GAEG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAkBpE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/transform-errors.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\nimport { betterAjvErrors } from './betterAjvErrors/index'\n\n/**\n * Transforms ajv errors, finds the positions in the schema and returns an enriched format.\n */\nexport function transformErrors(specification: AnyObject, errors: any) {\n // TODO: This should work with multiple files\n\n if (typeof errors === 'string') {\n return [\n {\n message: errors,\n },\n ]\n }\n\n return betterAjvErrors(specification, null, errors, {\n indent: 2,\n }).map((error) => {\n error.message = error.message.trim()\n\n return error\n })\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,uBAAuB;AAKzB,SAAS,gBAAgB,eAA0B,QAAa;AAGrE,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,MACL;AAAA,QACE,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAEA,SAAO,gBAAgB,eAAe,MAAM,QAAQ;AAAA,IAClD,QAAQ;AAAA,EACV,CAAC,EAAE,IAAI,CAAC,UAAU;AAChB,UAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,WAAO;AAAA,EACT,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { makeFilesystem } from "./
|
|
3
|
-
import { transformErrors } from "./
|
|
2
|
+
import { makeFilesystem } from "./make-filesystem.js";
|
|
3
|
+
import { transformErrors } from "./transform-errors.js";
|
|
4
4
|
describe("transformErrors", () => {
|
|
5
5
|
it("transforms a string to a proper error object", () => {
|
|
6
6
|
const result = transformErrors(
|
|
@@ -14,4 +14,4 @@ describe("transformErrors", () => {
|
|
|
14
14
|
]);
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=transform-errors.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/transform-errors.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { makeFilesystem } from './make-filesystem'\nimport { transformErrors } from './transform-errors'\n\ndescribe('transformErrors', () => {\n it('transforms a string to a proper error object', () => {\n const result = transformErrors(\n makeFilesystem('').find((entrypoint) => entrypoint.isEntrypoint),\n 'example error message',\n )\n\n expect(result).toEqual([\n {\n message: 'example error message',\n },\n ])\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,SAAS,mBAAmB,MAAM;AAChC,KAAG,gDAAgD,MAAM;AACvD,UAAM,SAAS;AAAA,MACb,eAAe,EAAE,EAAE,KAAK,CAAC,eAAe,WAAW,YAAY;AAAA,MAC/D;AAAA,IACF;AAEA,WAAO,MAAM,EAAE,QAAQ;AAAA,MACrB;AAAA,QACE,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/utils/traverse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/utils/traverse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,aAAa,EACrE,IAAI,GAAE,MAAM,EAAO,iBA6BpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/traverse.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\nimport type { UnknownObject } from '@scalar/types/utils'\n\n/**\n * Recursively traverses the content and applies the transform function to each node.\n */\nexport function traverse(\n content: UnknownObject,\n transform: (content: UnknownObject, path?: string[]) => UnknownObject,\n path: string[] = [],\n) {\n const result: AnyObject = {}\n\n for (const [key, value] of Object.entries(content)) {\n const currentPath = [...path, key]\n\n if (Array.isArray(value)) {\n result[key] = value.map((item, index) => {\n if (typeof item === 'object' && !Array.isArray(item) && item !== null) {\n return traverse(item, transform, [...currentPath, index.toString()])\n }\n\n return item\n })\n\n continue\n }\n\n if (typeof value === 'object' && value !== null) {\n result[key] = traverse(value as UnknownObject, transform, currentPath)\n\n continue\n }\n\n result[key] = value\n }\n\n return transform(result, path)\n}\n"],
|
|
5
5
|
"mappings": "AAMO,SAAS,SACd,SACA,WACA,OAAiB,CAAC,GAClB;AACA,QAAM,SAAoB,CAAC;AAE3B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAEjC,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,aAAO,GAAG,IAAI,MAAM,IAAI,CAAC,MAAM,UAAU;AACvC,YAAI,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI,KAAK,SAAS,MAAM;AACrE,iBAAO,SAAS,MAAM,WAAW,CAAC,GAAG,aAAa,MAAM,SAAS,CAAC,CAAC;AAAA,QACrE;AAEA,eAAO;AAAA,MACT,CAAC;AAED;AAAA,IACF;AAEA,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,aAAO,GAAG,IAAI,SAAS,OAAwB,WAAW,WAAW;AAErE;AAAA,IACF;AAEA,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO,UAAU,QAAQ,IAAI;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unescape-json-pointer.d.ts","sourceRoot":"","sources":["../../src/utils/unescape-json-pointer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,UAE9C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
3
|
+
"sources": ["../../src/utils/unescape-json-pointer.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Unescape JSON pointer\n *\n * Examples:\n * /foo~1bar~0baz -> /foo/bar~baz\n */\nexport function unescapeJsonPointer(uri: string) {\n return decodeURI(uri.replace(/~1/g, '/').replace(/~0/g, '~'))\n}\n"],
|
|
5
5
|
"mappings": "AAMO,SAAS,oBAAoB,KAAa;AAC/C,SAAO,UAAU,IAAI,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,CAAC;AAC9D;",
|
|
6
6
|
"names": []
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { unescapeJsonPointer } from "./
|
|
2
|
+
import { unescapeJsonPointer } from "./unescape-json-pointer.js";
|
|
3
3
|
describe("unescapeJsonPointer", async () => {
|
|
4
4
|
it("unescapes a slash", () => {
|
|
5
5
|
expect(unescapeJsonPointer("/foo~1bar~1baz")).toBe("/foo/bar/baz");
|
|
@@ -16,4 +16,4 @@ describe("unescapeJsonPointer", async () => {
|
|
|
16
16
|
expect(unescapeJsonPointer("foo%20bar")).toBe("foo bar");
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=unescape-json-pointer.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/unescape-json-pointer.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { unescapeJsonPointer } from './unescape-json-pointer'\n\ndescribe('unescapeJsonPointer', async () => {\n it('unescapes a slash', () => {\n expect(unescapeJsonPointer('/foo~1bar~1baz')).toBe('/foo/bar/baz')\n })\n\n it('unescapes multiple slashes', () => {\n expect(unescapeJsonPointer('#/paths/~1upload/post/responses/401/content/application~1problem+json/schema')).toBe(\n '#/paths//upload/post/responses/401/content/application/problem+json/schema',\n )\n })\n\n it('unescapes a tilde', () => {\n expect(unescapeJsonPointer('/foo~0bar~0baz')).toBe('/foo~bar~baz')\n })\n\n it('unescapes a space', () => {\n expect(unescapeJsonPointer('foo%20bar')).toBe('foo bar')\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,2BAA2B;AAEpC,SAAS,uBAAuB,YAAY;AAC1C,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,gBAAgB,CAAC,EAAE,KAAK,cAAc;AAAA,EACnE,CAAC;AAED,KAAG,8BAA8B,MAAM;AACrC,WAAO,oBAAoB,8EAA8E,CAAC,EAAE;AAAA,MAC1G;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,gBAAgB,CAAC,EAAE,KAAK,cAAc;AAAA,EACnE,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,WAAO,oBAAoB,WAAW,CAAC,EAAE,KAAK,SAAS;AAAA,EACzD,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -28,4 +28,4 @@ export declare function upgradeFromThreeToThreeOne(originalContent: UnknownObjec
|
|
|
28
28
|
[customExtension: `x-${string}`]: any;
|
|
29
29
|
[key: string]: any;
|
|
30
30
|
}) | UnknownObject;
|
|
31
|
-
//# sourceMappingURL=
|
|
31
|
+
//# sourceMappingURL=upgrade-from-three-to-three-one.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/utils/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgBxD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAiBpD;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;mBAcxE"}
|
|
@@ -9,7 +9,6 @@ const SCHEMA_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
9
9
|
"additionalProperties",
|
|
10
10
|
"schema"
|
|
11
11
|
]);
|
|
12
|
-
const SCHEMA_PATHS = /* @__PURE__ */ new Set(["components/schemas"]);
|
|
13
12
|
function isSchemaPath(path) {
|
|
14
13
|
if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {
|
|
15
14
|
return true;
|
|
@@ -107,4 +106,4 @@ export {
|
|
|
107
106
|
isSchemaPath,
|
|
108
107
|
upgradeFromThreeToThreeOne
|
|
109
108
|
};
|
|
110
|
-
//# sourceMappingURL=
|
|
109
|
+
//# sourceMappingURL=upgrade-from-three-to-three-one.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/upgrade-from-three-to-three-one.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n// Create Sets for faster schema path lookups\nconst SCHEMA_SEGMENTS = new Set([\n 'properties',\n 'items',\n 'allOf',\n 'anyOf',\n 'oneOf',\n 'not',\n 'additionalProperties',\n 'schema',\n])\n\n/** Determine if the current path is within a schema - optimized version */\nexport function isSchemaPath(path: string[]): boolean {\n // Check for schema segments first (most common case)\n if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {\n return true\n }\n\n // Check for schema suffix\n if (path.some((segment) => segment.endsWith('Schema'))) {\n return true\n }\n\n // Check for components/schemas path\n if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {\n return true\n }\n\n return false\n}\n\n/**\n * Upgrade from OpenAPI 3.0.x to 3.1.1\n *\n * https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n */\nexport function upgradeFromThreeToThreeOne(originalContent: UnknownObject) {\n let content = originalContent\n\n // Version check - early return if not 3.0.x\n if (content === null || typeof content.openapi !== 'string' || !content.openapi.startsWith('3.0')) {\n return content\n }\n\n content.openapi = '3.1.1'\n\n // Single traversal that handles all transformations\n content = traverse(content, applyChangesToDocument)\n\n return content as OpenAPIV3_1.Document\n}\n\nconst applyChangesToDocument = (schema: UnknownObject, path: string[]) => {\n // 1. Handle nullable types\n if (schema.type !== 'undefined' && schema.nullable === true) {\n schema.type = [schema.type, 'null']\n delete schema.nullable\n }\n\n // 2. Handle exclusiveMinimum and exclusiveMaximum\n if (schema.exclusiveMinimum === true) {\n schema.exclusiveMinimum = schema.minimum\n delete schema.minimum\n } else if (schema.exclusiveMinimum === false) {\n delete schema.exclusiveMinimum\n }\n\n if (schema.exclusiveMaximum === true) {\n schema.exclusiveMaximum = schema.maximum\n delete schema.maximum\n } else if (schema.exclusiveMaximum === false) {\n delete schema.exclusiveMaximum\n }\n\n // 3. Handle examples\n if (schema.example !== undefined) {\n if (isSchemaPath(path)) {\n schema.examples = [schema.example]\n } else {\n schema.examples = {\n default: {\n value: schema.example,\n },\n }\n }\n delete schema.example\n }\n\n // 4. Handle multipart file uploads\n if (schema.type === 'object' && schema.properties !== undefined) {\n const parentPath = path.slice(0, -1)\n const isMultipart = parentPath.some((segment, index) => {\n return segment === 'content' && path[index + 1] === 'multipart/form-data'\n })\n\n if (isMultipart) {\n for (const value of Object.values(schema.properties)) {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n 'format' in value &&\n value.type === 'string' &&\n value.format === 'binary'\n ) {\n ;(value as any).contentMediaType = 'application/octet-stream'\n delete (value as any).format\n }\n }\n }\n }\n\n // 5. Handle binary file uploads\n if (path.includes('content') && path.includes('application/octet-stream')) {\n return {}\n }\n\n if (schema.type === 'string') {\n if (schema.format === 'binary') {\n return {\n type: 'string',\n contentMediaType: 'application/octet-stream',\n }\n }\n\n if (schema.format === 'base64') {\n return {\n type: 'string',\n contentEncoding: 'base64',\n }\n }\n\n if (schema.format === 'byte') {\n const parentPath = path.slice(0, -1)\n const contentMediaType = parentPath.find((_, index) => path[index - 1] === 'content')\n return {\n type: 'string',\n contentEncoding: 'base64',\n contentMediaType,\n }\n }\n }\n\n return schema\n}\n"],
|
|
5
|
+
"m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