@scalar/openapi-parser 0.12.0 → 0.13.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.d.ts +2 -2
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/utils/details.d.ts +1 -2
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +12 -9
- package/dist/utils/details.js.map +2 -2
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +16 -11
- package/dist/utils/normalize.js.map +2 -2
- package/dist/utils/resolve-references.d.ts.map +1 -1
- package/dist/utils/resolve-references.js +11 -0
- package/dist/utils/resolve-references.js.map +2 -2
- package/package.json +2 -2
- package/dist/lib/Validator/Validator.test.js +0 -8
- package/dist/lib/Validator/Validator.test.js.map +0 -7
- package/dist/plugins/fetch-urls/fetch-urls.test.js +0 -50
- package/dist/plugins/fetch-urls/fetch-urls.test.js.map +0 -7
- package/dist/plugins/read-files/read-files.test.js +0 -20
- package/dist/plugins/read-files/read-files.test.js.map +0 -7
- package/dist/utils/dereference.test.js +0 -300
- package/dist/utils/dereference.test.js.map +0 -7
- package/dist/utils/errors.test.js +0 -48
- package/dist/utils/errors.test.js.map +0 -7
- package/dist/utils/escape-json-pointer.test.js +0 -11
- package/dist/utils/escape-json-pointer.test.js.map +0 -7
- package/dist/utils/get-entrypoint.test.js +0 -18
- package/dist/utils/get-entrypoint.test.js.map +0 -7
- package/dist/utils/get-segments-from-path.test.js +0 -13
- package/dist/utils/get-segments-from-path.test.js.map +0 -7
- package/dist/utils/is-filesystem.test.js +0 -15
- package/dist/utils/is-filesystem.test.js.map +0 -7
- package/dist/utils/is-object.test.js +0 -23
- package/dist/utils/is-object.test.js.map +0 -7
- package/dist/utils/load/load.test.js +0 -361
- package/dist/utils/load/load.test.js.map +0 -7
- package/dist/utils/normalize.test.js +0 -88
- package/dist/utils/normalize.test.js.map +0 -7
- package/dist/utils/resolve-references.test.js +0 -567
- package/dist/utils/resolve-references.test.js.map +0 -7
- package/dist/utils/transform/sanitize.test.js +0 -148
- package/dist/utils/transform/sanitize.test.js.map +0 -7
- package/dist/utils/transform-errors.test.js +0 -17
- package/dist/utils/transform-errors.test.js.map +0 -7
- package/dist/utils/traverse.test.js +0 -68
- package/dist/utils/traverse.test.js.map +0 -7
- package/dist/utils/unescape-json-pointer.test.js +0 -19
- package/dist/utils/unescape-json-pointer.test.js.map +0 -7
- package/dist/utils/upgrade-from-three-to-three-one.test.js +0 -462
- package/dist/utils/upgrade-from-three-to-three-one.test.js.map +0 -7
- package/dist/utils/upgrade-from-two-to-three.test.js +0 -589
- package/dist/utils/upgrade-from-two-to-three.test.js.map +0 -7
- package/dist/utils/upgrade.test.js +0 -57
- package/dist/utils/upgrade.test.js.map +0 -7
- package/dist/utils/validate.test.js +0 -64
- package/dist/utils/validate.test.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -3897,8 +3897,8 @@ export declare const OpenApiVersions: OpenApiVersion[];
|
|
|
3897
3897
|
* List of error messages used in the Validator
|
|
3898
3898
|
*/
|
|
3899
3899
|
export declare const ERRORS: {
|
|
3900
|
-
readonly EMPTY_OR_INVALID: "Can’t find JSON, YAML or filename in data";
|
|
3901
|
-
readonly OPENAPI_VERSION_NOT_SUPPORTED: "Can’t find supported Swagger/OpenAPI version in
|
|
3900
|
+
readonly EMPTY_OR_INVALID: "Can’t find JSON, YAML or filename in data.";
|
|
3901
|
+
readonly OPENAPI_VERSION_NOT_SUPPORTED: "Can’t find supported Swagger/OpenAPI version in the provided document, version must be a string.";
|
|
3902
3902
|
readonly INVALID_REFERENCE: "Can’t resolve reference: %s";
|
|
3903
3903
|
readonly EXTERNAL_REFERENCE_NOT_FOUND: "Can’t resolve external reference: %s";
|
|
3904
3904
|
readonly FILE_DOES_NOT_EXIST: "File does not exist: %s";
|
|
@@ -8,9 +8,9 @@ const OpenApiSpecifications = {
|
|
|
8
8
|
};
|
|
9
9
|
const OpenApiVersions = Object.keys(OpenApiSpecifications);
|
|
10
10
|
const ERRORS = {
|
|
11
|
-
EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data",
|
|
11
|
+
EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data.",
|
|
12
12
|
// URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',
|
|
13
|
-
OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in
|
|
13
|
+
OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in the provided document, version must be a string.",
|
|
14
14
|
INVALID_REFERENCE: "Can\u2019t resolve reference: %s",
|
|
15
15
|
EXTERNAL_REFERENCE_NOT_FOUND: "Can\u2019t resolve external reference: %s",
|
|
16
16
|
FILE_DOES_NOT_EXIST: "File does not exist: %s",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/configuration/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Swagger20 from '@/schemas/v2.0/schema'\nimport OpenApi30 from '@/schemas/v3.0/schema'\nimport OpenApi31 from '@/schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: 'Can\u2019t find JSON, YAML or filename in data',\n // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',\n OPENAPI_VERSION_NOT_SUPPORTED:\n 'Can\u2019t find supported Swagger/OpenAPI version in
|
|
4
|
+
"sourcesContent": ["import Swagger20 from '@/schemas/v2.0/schema'\nimport OpenApi30 from '@/schemas/v3.0/schema'\nimport OpenApi31 from '@/schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: 'Can\u2019t find JSON, YAML or filename in data.',\n // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',\n OPENAPI_VERSION_NOT_SUPPORTED:\n 'Can\u2019t find supported Swagger/OpenAPI version in the provided document, version must be a string.',\n INVALID_REFERENCE: 'Can\u2019t resolve reference: %s',\n EXTERNAL_REFERENCE_NOT_FOUND: 'Can\u2019t resolve external reference: %s',\n FILE_DOES_NOT_EXIST: 'File does not exist: %s',\n NO_CONTENT: 'No content found',\n} as const\n\nexport type ValidationError = keyof typeof ERRORS\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,eAAe;AAKf,MAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAIO,MAAM,kBAAkB,OAAO,KAAK,qBAAqB;AAKzD,MAAM,SAAS;AAAA,EACpB,kBAAkB;AAAA;AAAA,EAElB,+BACE;AAAA,EACF,mBAAmB;AAAA,EACnB,8BAA8B;AAAA,EAC9B,qBAAqB;AAAA,EACrB,YAAY;AACd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/utils/details.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { UnknownObject } from '@scalar/types/utils';
|
|
2
1
|
import type { DetailsResult } from '../types/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Get versions of the OpenAPI document.
|
|
5
4
|
*/
|
|
6
|
-
export declare function details(specification:
|
|
5
|
+
export declare function details(specification: unknown): DetailsResult;
|
|
7
6
|
//# sourceMappingURL=details.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/utils/details.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/utils/details.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAGlD;;GAEG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,OAAO,GAAG,aAAa,CA6B7D"}
|
package/dist/utils/details.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OpenApiVersions } from "../configuration/index.js";
|
|
2
|
+
import { isObject } from "./is-object.js";
|
|
2
3
|
function details(specification) {
|
|
3
4
|
if (specification === null) {
|
|
4
5
|
return {
|
|
@@ -7,15 +8,17 @@ function details(specification) {
|
|
|
7
8
|
specificationVersion: void 0
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
if (isObject(specification)) {
|
|
12
|
+
for (const version of new Set(OpenApiVersions)) {
|
|
13
|
+
const specificationType = version === "2.0" ? "swagger" : "openapi";
|
|
14
|
+
const value = specification[specificationType];
|
|
15
|
+
if (typeof value === "string" && value.startsWith(version)) {
|
|
16
|
+
return {
|
|
17
|
+
version,
|
|
18
|
+
specificationType,
|
|
19
|
+
specificationVersion: value
|
|
20
|
+
};
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/details.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { OpenApiVersions } from '@/configuration'\nimport type { DetailsResult } from '@/types/index'\nimport { isObject } from './is-object'\n\n/**\n * Get versions of the OpenAPI document.\n */\nexport function details(specification: unknown): DetailsResult {\n if (specification === null) {\n return {\n version: undefined,\n specificationType: undefined,\n specificationVersion: undefined,\n }\n }\n\n if (isObject(specification)) {\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\n return {\n version: undefined,\n specificationType: undefined,\n specificationVersion: undefined,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAEhC,SAAS,gBAAgB;AAKlB,SAAS,QAAQ,eAAuC;AAC7D,MAAI,kBAAkB,MAAM;AAC1B,WAAO;AAAA,MACL,SAAS;AAAA,MACT,mBAAmB;AAAA,MACnB,sBAAsB;AAAA,IACxB;AAAA,EACF;AAEA,MAAI,SAAS,aAAa,GAAG;AAC3B,eAAW,WAAW,IAAI,IAAI,eAAe,GAAG;AAC9C,YAAM,oBAAoB,YAAY,QAAQ,YAAY;AAC1D,YAAM,QAAQ,cAAc,iBAAiB;AAE7C,UAAI,OAAO,UAAU,YAAY,MAAM,WAAW,OAAO,GAAG;AAC1D,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,sBAAsB;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,EACxB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,5 +5,5 @@ import type { Filesystem } from '../types/index.js';
|
|
|
5
5
|
*
|
|
6
6
|
* Doesn’t modify the object if it’s a `Filesystem` (multiple files) already.
|
|
7
7
|
*/
|
|
8
|
-
export declare function normalize(
|
|
8
|
+
export declare function normalize(content: string | UnknownObject | Filesystem): UnknownObject | Filesystem;
|
|
9
9
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAgClG"}
|
package/dist/utils/normalize.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { parse } from "yaml";
|
|
2
2
|
import { isFilesystem } from "./is-filesystem.js";
|
|
3
|
-
function normalize(
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
3
|
+
function normalize(content) {
|
|
4
|
+
if (content === null) {
|
|
5
|
+
return void 0;
|
|
6
6
|
}
|
|
7
|
-
if (typeof
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
7
|
+
if (typeof content === "string") {
|
|
8
|
+
if (content.trim() === "") {
|
|
9
|
+
return void 0;
|
|
10
10
|
}
|
|
11
11
|
try {
|
|
12
|
-
return JSON.parse(
|
|
12
|
+
return JSON.parse(content);
|
|
13
13
|
} catch (_error) {
|
|
14
|
-
|
|
14
|
+
const hasColon = /^[^:]+:/.test(content);
|
|
15
|
+
const isMultiLine = content.includes("\n");
|
|
16
|
+
if (!hasColon || !isMultiLine) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
return parse(content, {
|
|
15
20
|
maxAliasCount: 1e4
|
|
16
21
|
});
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
|
-
if (isFilesystem(
|
|
20
|
-
return
|
|
24
|
+
if (isFilesystem(content)) {
|
|
25
|
+
return content;
|
|
21
26
|
}
|
|
22
|
-
return
|
|
27
|
+
return content;
|
|
23
28
|
}
|
|
24
29
|
export {
|
|
25
30
|
normalize
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/normalize.ts"],
|
|
4
|
-
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\nimport { parse } from 'yaml'\n\nimport type { Filesystem } from '@/types/index'\nimport { isFilesystem } from './is-filesystem'\n\n/**\n * Normalize the OpenAPI document (YAML, JSON, object) to a JavaScript object.\n *\n * Doesn\u2019t modify the object if it\u2019s a `Filesystem` (multiple files) already.\n */\nexport function normalize(
|
|
5
|
-
"mappings": "AACA,SAAS,aAAa;AAGtB,SAAS,oBAAoB;AAOtB,SAAS,UAAU,
|
|
4
|
+
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\nimport { parse } from 'yaml'\n\nimport type { Filesystem } from '@/types/index'\nimport { isFilesystem } from './is-filesystem'\n\n/**\n * Normalize the OpenAPI document (YAML, JSON, object) to a JavaScript object.\n *\n * Doesn\u2019t modify the object if it\u2019s a `Filesystem` (multiple files) already.\n */\nexport function normalize(content: string | UnknownObject | Filesystem): UnknownObject | Filesystem {\n if (content === null) {\n return undefined\n }\n\n if (typeof content === 'string') {\n if (content.trim() === '') {\n return undefined\n }\n\n try {\n return JSON.parse(content)\n } catch (_error) {\n // Does it look like YAML?\n const hasColon = /^[^:]+:/.test(content)\n const isMultiLine = content.includes('\\n')\n\n if (!hasColon || !isMultiLine) {\n return undefined\n }\n\n return parse(content, {\n maxAliasCount: 10000,\n })\n }\n }\n\n if (isFilesystem(content)) {\n return content\n }\n\n return content\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,aAAa;AAGtB,SAAS,oBAAoB;AAOtB,SAAS,UAAU,SAA0E;AAClG,MAAI,YAAY,MAAM;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,QAAI,QAAQ,KAAK,MAAM,IAAI;AACzB,aAAO;AAAA,IACT;AAEA,QAAI;AACF,aAAO,KAAK,MAAM,OAAO;AAAA,IAC3B,SAAS,QAAQ;AAEf,YAAM,WAAW,UAAU,KAAK,OAAO;AACvC,YAAM,cAAc,QAAQ,SAAS,IAAI;AAEzC,UAAI,CAAC,YAAY,CAAC,aAAa;AAC7B,eAAO;AAAA,MACT;AAEA,aAAO,MAAM,SAAS;AAAA,QACpB,eAAe;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,aAAa,OAAO,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-references.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"resolve-references.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAgB5G,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACnE,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAE/B,KAAK,EAAE,SAAS,GAAG,UAAU,EAE7B,OAAO,CAAC,EAAE,wBAAwB,EAElC,IAAI,CAAC,EAAE,eAAe,EAEtB,MAAM,GAAE,WAAW,EAAO,GACzB,uBAAuB,CAuCzB"}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { ERRORS } from "../configuration/index.js";
|
|
2
2
|
import { getEntrypoint } from "./get-entrypoint.js";
|
|
3
3
|
import { getSegmentsFromPath } from "./get-segments-from-path.js";
|
|
4
|
+
import { isObject } from "./is-object.js";
|
|
4
5
|
import { makeFilesystem } from "./make-filesystem.js";
|
|
5
6
|
function resolveReferences(input, options, file, errors = []) {
|
|
6
7
|
const clonedInput = structuredClone(input);
|
|
7
8
|
const filesystem = makeFilesystem(clonedInput);
|
|
8
9
|
const entrypoint = getEntrypoint(filesystem);
|
|
9
10
|
const finalInput = file?.specification ?? entrypoint.specification;
|
|
11
|
+
if (!isObject(finalInput)) {
|
|
12
|
+
if (options?.throwOnError) {
|
|
13
|
+
throw new Error(ERRORS.NO_CONTENT);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
valid: false,
|
|
17
|
+
errors,
|
|
18
|
+
schema: finalInput
|
|
19
|
+
};
|
|
20
|
+
}
|
|
10
21
|
dereference(finalInput, filesystem, file ?? entrypoint, /* @__PURE__ */ new WeakSet(), errors, options);
|
|
11
22
|
errors = errors.filter(
|
|
12
23
|
(error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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;AAG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ar/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 { isObject } from './is-object'\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 // Does it look like an OpenAPI document?\n if (!isObject(finalInput)) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.NO_CONTENT)\n }\n\n return {\n valid: false,\n errors,\n schema: finalInput as OpenAPI.Document,\n }\n }\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,gBAAgB;AACzB,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,MAAI,CAAC,SAAS,UAAU,GAAG;AACzB,QAAI,SAAS,cAAc;AACzB,YAAM,IAAI,MAAM,OAAO,UAAU;AAAA,IACnC;AAEA,WA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AAM;AAAA,MACN,SAAS,OAAO,kBAAkB,QAAQ,MAAM,GAAG;AAAA,IACrD,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"parser",
|
|
18
18
|
"typescript"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.
|
|
20
|
+
"version": "0.13.0",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"just-diff": "^6.0.2",
|
|
64
64
|
"tinybench": "^2.8.0",
|
|
65
65
|
"vite": "5.4.19",
|
|
66
|
-
"@scalar/build-tooling": "0.2.0",
|
|
67
66
|
"@scalar/openapi-types": "0.3.1",
|
|
67
|
+
"@scalar/build-tooling": "0.2.1",
|
|
68
68
|
"@scalar/types": "0.2.1"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { Validator } from "./Validator.js";
|
|
3
|
-
describe("Validator", () => {
|
|
4
|
-
it("returns all supported versions", () => {
|
|
5
|
-
expect(Validator.supportedVersions).toMatchObject(["2.0", "3.0", "3.1"]);
|
|
6
|
-
});
|
|
7
|
-
});
|
|
8
|
-
//# sourceMappingURL=Validator.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/lib/Validator/Validator.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { Validator } from './Validator'\n\ndescribe('Validator', () => {\n it('returns all supported versions', () => {\n expect(Validator.supportedVersions).toMatchObject(['2.0', '3.0', '3.1'])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,aAAa,MAAM;AAC1B,KAAG,kCAAkC,MAAM;AACzC,WAAO,UAAU,iBAAiB,EAAE,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAAA,EACzE,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { fetchUrls } from "./fetch-urls.js";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("fetchUrls", async () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
global.fetch.mockReset();
|
|
7
|
-
});
|
|
8
|
-
it("returns true for an url", async () => {
|
|
9
|
-
expect(fetchUrls().check("http://example.com/specification/openapi.yaml")).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
it("returns false for a filename", async () => {
|
|
12
|
-
expect(fetchUrls().check("openapi.yaml")).toBe(false);
|
|
13
|
-
});
|
|
14
|
-
it("returns false for a path", async () => {
|
|
15
|
-
expect(fetchUrls().check("specification/openapi.yaml")).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
it("returns false for an object", async () => {
|
|
18
|
-
expect(fetchUrls().check({})).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
it("returns false for undefinded", async () => {
|
|
21
|
-
expect(fetchUrls().check()).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
it("fetches the URL", async () => {
|
|
24
|
-
fetch.mockImplementation(async (url) => ({
|
|
25
|
-
text: async () => {
|
|
26
|
-
if (url === "http://example.com/specification/openapi.yaml") {
|
|
27
|
-
return "OK";
|
|
28
|
-
}
|
|
29
|
-
throw new Error("Not found");
|
|
30
|
-
}
|
|
31
|
-
}));
|
|
32
|
-
expect(await fetchUrls().get("http://example.com/specification/openapi.yaml")).toBe("OK");
|
|
33
|
-
});
|
|
34
|
-
it("rewrites the URL", async () => {
|
|
35
|
-
fetch.mockImplementation(async (url) => ({
|
|
36
|
-
text: async () => {
|
|
37
|
-
if (url === "http://foobar.com/specification/openapi.yaml") {
|
|
38
|
-
return "OK";
|
|
39
|
-
}
|
|
40
|
-
throw new Error("Not found");
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
expect(
|
|
44
|
-
await fetchUrls({
|
|
45
|
-
fetch: (url) => fetch(url.replace("example", "foobar"))
|
|
46
|
-
}).get("http://foobar.com/specification/openapi.yaml")
|
|
47
|
-
).toBe("OK");
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
//# sourceMappingURL=fetch-urls.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/fetch-urls/fetch-urls.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { fetchUrls } from './fetch-urls'\n\nglobal.fetch = vi.fn()\n\ndescribe('fetchUrls', async () => {\n beforeEach(() => {\n // @ts-expect-error\n global.fetch.mockReset()\n })\n\n it('returns true for an url', async () => {\n expect(fetchUrls().check('http://example.com/specification/openapi.yaml')).toBe(true)\n })\n\n it('returns false for a filename', async () => {\n expect(fetchUrls().check('openapi.yaml')).toBe(false)\n })\n\n it('returns false for a path', async () => {\n expect(fetchUrls().check('specification/openapi.yaml')).toBe(false)\n })\n\n it('returns false for an object', async () => {\n expect(fetchUrls().check({})).toBe(false)\n })\n\n it('returns false for undefinded', async () => {\n expect(fetchUrls().check()).toBe(false)\n })\n\n it('fetches the URL', async () => {\n // @ts-expect-error\n fetch.mockImplementation(async (url: string) => ({\n text: async () => {\n if (url === 'http://example.com/specification/openapi.yaml') {\n return 'OK'\n }\n\n throw new Error('Not found')\n },\n }))\n\n expect(await fetchUrls().get('http://example.com/specification/openapi.yaml')).toBe('OK')\n })\n\n it('rewrites the URL', async () => {\n // @ts-expect-error\n fetch.mockImplementation(async (url: string) => ({\n text: async () => {\n if (url === 'http://foobar.com/specification/openapi.yaml') {\n return 'OK'\n }\n throw new Error('Not found')\n },\n }))\n\n expect(\n await fetchUrls({\n fetch: (url) => fetch(url.replace('example', 'foobar')),\n }).get('http://foobar.com/specification/openapi.yaml'),\n ).toBe('OK')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,UAAU,QAAQ,IAAI,UAAU;AAErD,SAAS,iBAAiB;AAE1B,OAAO,QAAQ,GAAG,GAAG;AAErB,SAAS,aAAa,YAAY;AAChC,aAAW,MAAM;AAEf,WAAO,MAAM,UAAU;AAAA,EACzB,CAAC;AAED,KAAG,2BAA2B,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,+CAA+C,CAAC,EAAE,KAAK,IAAI;AAAA,EACtF,CAAC;AAED,KAAG,gCAAgC,YAAY;AAC7C,WAAO,UAAU,EAAE,MAAM,cAAc,CAAC,EAAE,KAAK,KAAK;AAAA,EACtD,CAAC;AAED,KAAG,4BAA4B,YAAY;AACzC,WAAO,UAAU,EAAE,MAAM,4BAA4B,CAAC,EAAE,KAAK,KAAK;AAAA,EACpE,CAAC;AAED,KAAG,+BAA+B,YAAY;AAC5C,WAAO,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EAC1C,CAAC;AAED,KAAG,gCAAgC,YAAY;AAC7C,WAAO,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,KAAK;AAAA,EACxC,CAAC;AAED,KAAG,mBAAmB,YAAY;AAEhC,UAAM,mBAAmB,OAAO,SAAiB;AAAA,MAC/C,MAAM,YAAY;AAChB,YAAI,QAAQ,iDAAiD;AAC3D,iBAAO;AAAA,QACT;AAEA,cAAM,IAAI,MAAM,WAAW;AAAA,MAC7B;AAAA,IACF,EAAE;AAEF,WAAO,MAAM,UAAU,EAAE,IAAI,+CAA+C,CAAC,EAAE,KAAK,IAAI;AAAA,EAC1F,CAAC;AAED,KAAG,oBAAoB,YAAY;AAEjC,UAAM,mBAAmB,OAAO,SAAiB;AAAA,MAC/C,MAAM,YAAY;AAChB,YAAI,QAAQ,gDAAgD;AAC1D,iBAAO;AAAA,QACT;AACA,cAAM,IAAI,MAAM,WAAW;AAAA,MAC7B;AAAA,IACF,EAAE;AAEF;AAAA,MACE,MAAM,UAAU;AAAA,QACd,OAAO,CAAC,QAAQ,MAAM,IAAI,QAAQ,WAAW,QAAQ,CAAC;AAAA,MACxD,CAAC,EAAE,IAAI,8CAA8C;AAAA,IACvD,EAAE,KAAK,IAAI;AAAA,EACb,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { readFiles } from "./read-files.js";
|
|
3
|
-
describe("readFiles", async () => {
|
|
4
|
-
it("returns true for a filename", async () => {
|
|
5
|
-
expect(readFiles().check("openapi.yaml")).toBe(true);
|
|
6
|
-
});
|
|
7
|
-
it("returns true for a path", async () => {
|
|
8
|
-
expect(readFiles().check("../specification/openapi.yaml")).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
it("returns false for an object", async () => {
|
|
11
|
-
expect(readFiles().check({})).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
it("returns false for undefinded", async () => {
|
|
14
|
-
expect(readFiles().check()).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
it("returns false for an url", async () => {
|
|
17
|
-
expect(readFiles().check("http://example.com/specification/openapi.yaml")).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
//# sourceMappingURL=read-files.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/read-files/read-files.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { readFiles } from './read-files'\n\ndescribe('readFiles', async () => {\n it('returns true for a filename', async () => {\n expect(readFiles().check('openapi.yaml')).toBe(true)\n })\n\n it('returns true for a path', async () => {\n expect(readFiles().check('../specification/openapi.yaml')).toBe(true)\n })\n\n it('returns false for an object', async () => {\n expect(readFiles().check({})).toBe(false)\n })\n\n it('returns false for undefinded', async () => {\n expect(readFiles().check()).toBe(false)\n })\n\n it('returns false for an url', async () => {\n expect(readFiles().check('http://example.com/specification/openapi.yaml')).toBe(false)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,aAAa,YAAY;AAChC,KAAG,+BAA+B,YAAY;AAC5C,WAAO,UAAU,EAAE,MAAM,cAAc,CAAC,EAAE,KAAK,IAAI;AAAA,EACrD,CAAC;AAED,KAAG,2BAA2B,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,+BAA+B,CAAC,EAAE,KAAK,IAAI;AAAA,EACtE,CAAC;AAED,KAAG,+BAA+B,YAAY;AAC5C,WAAO,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EAC1C,CAAC;AAED,KAAG,gCAAgC,YAAY;AAC7C,WAAO,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,KAAK;AAAA,EACxC,CAAC;AAED,KAAG,4BAA4B,YAAY;AACzC,WAAO,UAAU,EAAE,MAAM,+CAA+C,CAAC,EAAE,KAAK,KAAK;AAAA,EACvF,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|