@scalar/openapi-parser 0.25.3 → 0.25.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/configuration/index.js +24 -24
- package/dist/index.js +24 -45
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +125 -105
- package/dist/plugins/fetch-urls/fetch-urls.js +39 -38
- package/dist/plugins/fetch-urls/index.js +1 -6
- package/dist/plugins/read-files/index.js +1 -5
- package/dist/plugins/read-files/read-files.js +53 -51
- package/dist/schemas/v2.0/schema.js +1373 -1377
- package/dist/schemas/v3.0/schema.js +1411 -1415
- package/dist/schemas/v3.1/schema.js +1196 -1200
- package/dist/schemas/v3.2/schema.js +1417 -1421
- package/dist/types/index.js +1 -1
- package/dist/utils/betterAjvErrors/helpers.js +138 -112
- package/dist/utils/betterAjvErrors/index.js +11 -15
- package/dist/utils/betterAjvErrors/utils.js +17 -30
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/base.js +20 -21
- package/dist/utils/betterAjvErrors/validation-errors/default.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +33 -37
- package/dist/utils/betterAjvErrors/validation-errors/index.js +6 -15
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +14 -18
- package/dist/utils/betterAjvErrors/validation-errors/required.js +13 -17
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +14 -18
- package/dist/utils/dereference.js +22 -18
- package/dist/utils/details.js +28 -29
- package/dist/utils/filter.js +13 -14
- package/dist/utils/get-entrypoint.js +5 -6
- package/dist/utils/get-list-of-references.js +20 -16
- package/dist/utils/get-segments-from-path.js +13 -9
- package/dist/utils/is-filesystem.js +8 -6
- package/dist/utils/is-json.js +8 -11
- package/dist/utils/is-yaml.js +15 -17
- package/dist/utils/join/index.js +1 -5
- package/dist/utils/join/join.js +267 -153
- package/dist/utils/join/merge-objects.js +35 -18
- package/dist/utils/load/index.js +1 -5
- package/dist/utils/load/load.js +114 -90
- package/dist/utils/make-filesystem.js +20 -21
- package/dist/utils/normalize.js +32 -29
- package/dist/utils/openapi/actions/details.js +9 -10
- package/dist/utils/openapi/actions/files.js +7 -8
- package/dist/utils/openapi/actions/get.js +9 -10
- package/dist/utils/openapi/actions/toJson.js +9 -10
- package/dist/utils/openapi/actions/toYaml.js +9 -10
- package/dist/utils/openapi/commands/dereferenceCommand.js +25 -26
- package/dist/utils/openapi/commands/filterCommand.js +24 -25
- package/dist/utils/openapi/commands/loadCommand.js +40 -41
- package/dist/utils/openapi/commands/upgradeCommand.js +27 -28
- package/dist/utils/openapi/commands/validateCommand.js +31 -32
- package/dist/utils/openapi/openapi.js +16 -14
- package/dist/utils/openapi/openapi.test-d.js +13 -13
- package/dist/utils/openapi/utils/queueTask.js +8 -9
- package/dist/utils/openapi/utils/workThroughQueue.js +64 -50
- package/dist/utils/resolve-references.js +168 -110
- package/dist/utils/to-json.js +1 -5
- package/dist/utils/to-yaml.js +2 -6
- package/dist/utils/transform/sanitize.js +22 -22
- package/dist/utils/transform/utils/addInfoObject.js +9 -14
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js +4 -9
- package/dist/utils/transform/utils/addMissingTags.js +26 -27
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js +39 -37
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js +5 -9
- package/dist/utils/transform-errors.js +62 -55
- package/dist/utils/traverse.js +21 -22
- package/dist/utils/unescape-json-pointer.js +8 -6
- package/dist/utils/upgrade.js +19 -22
- package/dist/utils/validate-path-parameters.d.ts +6 -0
- package/dist/utils/validate-path-parameters.d.ts.map +1 -0
- package/dist/utils/validate-path-parameters.js +91 -0
- package/dist/utils/validate.js +23 -19
- package/package.json +9 -14
- package/dist/configuration/index.js.map +0 -7
- package/dist/declarations.d.js +0 -1
- package/dist/declarations.d.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/lib/Validator/Validator.js.map +0 -7
- package/dist/plugins/fetch-urls/fetch-urls.js.map +0 -7
- package/dist/plugins/fetch-urls/index.js.map +0 -7
- package/dist/plugins/read-files/index.js.map +0 -7
- package/dist/plugins/read-files/read-files.js.map +0 -7
- package/dist/schemas/v2.0/schema.js.map +0 -7
- package/dist/schemas/v3.0/schema.js.map +0 -7
- package/dist/schemas/v3.1/schema.js.map +0 -7
- package/dist/schemas/v3.2/schema.js.map +0 -7
- package/dist/types/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/helpers.js.map +0 -7
- package/dist/utils/betterAjvErrors/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/utils.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/base.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/default.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/index.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/required.js.map +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +0 -7
- package/dist/utils/dereference.js.map +0 -7
- package/dist/utils/details.js.map +0 -7
- package/dist/utils/filter.js.map +0 -7
- package/dist/utils/get-entrypoint.js.map +0 -7
- package/dist/utils/get-list-of-references.js.map +0 -7
- package/dist/utils/get-segments-from-path.js.map +0 -7
- package/dist/utils/is-filesystem.js.map +0 -7
- package/dist/utils/is-json.js.map +0 -7
- package/dist/utils/is-yaml.js.map +0 -7
- package/dist/utils/join/index.js.map +0 -7
- package/dist/utils/join/join.js.map +0 -7
- package/dist/utils/join/merge-objects.js.map +0 -7
- package/dist/utils/load/index.js.map +0 -7
- package/dist/utils/load/load.js.map +0 -7
- package/dist/utils/make-filesystem.js.map +0 -7
- package/dist/utils/normalize.js.map +0 -7
- package/dist/utils/openapi/actions/details.js.map +0 -7
- package/dist/utils/openapi/actions/files.js.map +0 -7
- package/dist/utils/openapi/actions/get.js.map +0 -7
- package/dist/utils/openapi/actions/toJson.js.map +0 -7
- package/dist/utils/openapi/actions/toYaml.js.map +0 -7
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +0 -7
- package/dist/utils/openapi/commands/filterCommand.js.map +0 -7
- package/dist/utils/openapi/commands/loadCommand.js.map +0 -7
- package/dist/utils/openapi/commands/upgradeCommand.js.map +0 -7
- package/dist/utils/openapi/commands/validateCommand.js.map +0 -7
- package/dist/utils/openapi/openapi.js.map +0 -7
- package/dist/utils/openapi/openapi.test-d.js.map +0 -7
- package/dist/utils/openapi/utils/queueTask.js.map +0 -7
- package/dist/utils/openapi/utils/workThroughQueue.js.map +0 -7
- package/dist/utils/resolve-references.js.map +0 -7
- package/dist/utils/to-json.js.map +0 -7
- package/dist/utils/to-yaml.js.map +0 -7
- package/dist/utils/transform/sanitize.js.map +0 -7
- package/dist/utils/transform/utils/addInfoObject.js.map +0 -7
- package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +0 -7
- package/dist/utils/transform/utils/addMissingTags.js.map +0 -7
- package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +0 -7
- package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +0 -7
- package/dist/utils/transform-errors.js.map +0 -7
- package/dist/utils/traverse.js.map +0 -7
- package/dist/utils/unescape-json-pointer.js.map +0 -7
- package/dist/utils/upgrade.js.map +0 -7
- package/dist/utils/validate.js.map +0 -7
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import BaseValidationError from
|
|
2
|
-
class UnevaluatedPropValidationError extends BaseValidationError {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import BaseValidationError from './base.js';
|
|
2
|
+
export default class UnevaluatedPropValidationError extends BaseValidationError {
|
|
3
|
+
constructor(...args) {
|
|
4
|
+
super(...args);
|
|
5
|
+
this.name = 'UnevaluatedPropValidationError';
|
|
6
|
+
this.options.isIdentifierLocation = true;
|
|
7
|
+
}
|
|
8
|
+
getError() {
|
|
9
|
+
const { params } = this.options;
|
|
10
|
+
return {
|
|
11
|
+
message: `Property ${params.unevaluatedProperty} is not expected to be here`,
|
|
12
|
+
path: this.instancePath,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
export {
|
|
17
|
-
UnevaluatedPropValidationError as default
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=unevaluated-prop.js.map
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { details } from
|
|
2
|
-
import { getEntrypoint } from
|
|
3
|
-
import { makeFilesystem } from
|
|
4
|
-
import { resolveReferences } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { details } from './details.js';
|
|
2
|
+
import { getEntrypoint } from './get-entrypoint.js';
|
|
3
|
+
import { makeFilesystem } from './make-filesystem.js';
|
|
4
|
+
import { resolveReferences } from './resolve-references.js';
|
|
5
|
+
/**
|
|
6
|
+
* Dereferences an API definition or filesystem by resolving all references within the specification.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The API definition or filesystem to dereference.\
|
|
9
|
+
* Can be any supported API definition format or a filesystem object.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Optional options for the dereferencing process.
|
|
12
|
+
*/
|
|
13
|
+
export function dereference(value, options) {
|
|
14
|
+
const filesystem = makeFilesystem(value);
|
|
15
|
+
const entrypoint = getEntrypoint(filesystem);
|
|
16
|
+
const result = resolveReferences(filesystem, options);
|
|
17
|
+
return {
|
|
18
|
+
specification: entrypoint.specification,
|
|
19
|
+
errors: result.errors,
|
|
20
|
+
schema: result.schema,
|
|
21
|
+
...details(entrypoint.specification),
|
|
22
|
+
};
|
|
15
23
|
}
|
|
16
|
-
export {
|
|
17
|
-
dereference
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=dereference.js.map
|
package/dist/utils/details.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import { isObject } from
|
|
2
|
-
import { OpenApiVersions } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
specificationVersion: void 0
|
|
9
|
-
};
|
|
10
|
-
}
|
|
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)) {
|
|
1
|
+
import { isObject } from '@scalar/helpers/object/is-object';
|
|
2
|
+
import { OpenApiVersions } from '../configuration/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get versions of the OpenAPI document.
|
|
5
|
+
*/
|
|
6
|
+
export function details(specification) {
|
|
7
|
+
if (specification === null) {
|
|
16
8
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
version: undefined,
|
|
10
|
+
specificationType: undefined,
|
|
11
|
+
specificationVersion: undefined,
|
|
20
12
|
};
|
|
21
|
-
}
|
|
22
13
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
if (isObject(specification)) {
|
|
15
|
+
for (const version of new Set(OpenApiVersions)) {
|
|
16
|
+
const specificationType = version === '2.0' ? 'swagger' : 'openapi';
|
|
17
|
+
const value = specification[specificationType];
|
|
18
|
+
if (typeof value === 'string' && value.startsWith(version)) {
|
|
19
|
+
return {
|
|
20
|
+
version: version,
|
|
21
|
+
specificationType,
|
|
22
|
+
specificationVersion: value,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
version: undefined,
|
|
29
|
+
specificationType: undefined,
|
|
30
|
+
specificationVersion: undefined,
|
|
31
|
+
};
|
|
29
32
|
}
|
|
30
|
-
export {
|
|
31
|
-
details
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=details.js.map
|
package/dist/utils/filter.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { getEntrypoint } from
|
|
2
|
-
import { makeFilesystem } from
|
|
3
|
-
import { traverse } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { getEntrypoint } from './get-entrypoint.js';
|
|
2
|
+
import { makeFilesystem } from './make-filesystem.js';
|
|
3
|
+
import { traverse } from './traverse.js';
|
|
4
|
+
/**
|
|
5
|
+
* Filter the specification based on the callback
|
|
6
|
+
*/
|
|
7
|
+
export function filter(specification, callback) {
|
|
8
|
+
const filesystem = makeFilesystem(specification);
|
|
9
|
+
return {
|
|
10
|
+
specification: traverse(getEntrypoint(filesystem).specification, (schema) => {
|
|
11
|
+
return callback(schema) ? schema : undefined;
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
11
14
|
}
|
|
12
|
-
export {
|
|
13
|
-
filter
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=filter.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Return just the entrypoint of the filesystem.
|
|
3
|
+
*/
|
|
4
|
+
export function getEntrypoint(filesystem) {
|
|
5
|
+
return filesystem?.find((file) => file.isEntrypoint);
|
|
3
6
|
}
|
|
4
|
-
export {
|
|
5
|
-
getEntrypoint
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=get-entrypoint.js.map
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { traverse } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { traverse } from './traverse.js';
|
|
2
|
+
/**
|
|
3
|
+
* Walks through the specification and returns all references as an array.
|
|
4
|
+
*
|
|
5
|
+
* Warning: Doesn't return internal references.
|
|
6
|
+
*/
|
|
7
|
+
export function getListOfReferences(specification) {
|
|
8
|
+
const references = [];
|
|
9
|
+
// Make sure we're dealing with an object
|
|
10
|
+
if (!specification || typeof specification !== 'object') {
|
|
11
|
+
return references;
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
// Traverse the specification and collect all references
|
|
14
|
+
traverse(specification, (value) => {
|
|
15
|
+
if (value.$ref && typeof value.$ref === 'string' && !value.$ref.startsWith('#')) {
|
|
16
|
+
references.push(value.$ref.split('#')[0]);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
});
|
|
20
|
+
// Remove duplicates
|
|
21
|
+
return [...new Set(references)];
|
|
14
22
|
}
|
|
15
|
-
export {
|
|
16
|
-
getListOfReferences
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=get-list-of-references.js.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { unescapeJsonPointer } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { unescapeJsonPointer } from './unescape-json-pointer.js';
|
|
2
|
+
/**
|
|
3
|
+
* Translate `/paths/~1test` to `['paths', '/test']`
|
|
4
|
+
*/
|
|
5
|
+
export function getSegmentsFromPath(path) {
|
|
6
|
+
return (
|
|
4
7
|
// /paths/~1test
|
|
5
|
-
path
|
|
6
|
-
|
|
8
|
+
path
|
|
9
|
+
// ['', 'paths', '~1test']
|
|
10
|
+
.split('/')
|
|
11
|
+
// ['paths', '~test']
|
|
12
|
+
.slice(1)
|
|
13
|
+
// ['paths', '/test']
|
|
14
|
+
.map(unescapeJsonPointer));
|
|
7
15
|
}
|
|
8
|
-
export {
|
|
9
|
-
getSegmentsFromPath
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=get-segments-from-path.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check if the value is a filesystem
|
|
3
|
+
*/
|
|
4
|
+
export function isFilesystem(value) {
|
|
5
|
+
return (typeof value !== 'undefined' &&
|
|
6
|
+
Array.isArray(value) &&
|
|
7
|
+
value.length > 0 &&
|
|
8
|
+
value.some((file) => file.isEntrypoint === true));
|
|
3
9
|
}
|
|
4
|
-
export {
|
|
5
|
-
isFilesystem
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=is-filesystem.js.map
|
package/dist/utils/is-json.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
function isJson(value) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export function isJson(value) {
|
|
2
|
+
try {
|
|
3
|
+
JSON.parse(value);
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
8
9
|
}
|
|
9
|
-
export {
|
|
10
|
-
isJson
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=is-json.js.map
|
package/dist/utils/is-yaml.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { parse } from
|
|
2
|
-
function isYaml(value) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
export function isYaml(value) {
|
|
3
|
+
// Line breaks
|
|
4
|
+
if (!value.includes('\n')) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
parse(value, {
|
|
9
|
+
maxAliasCount: 10000,
|
|
10
|
+
});
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch (_error) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
|
-
export {
|
|
16
|
-
isYaml
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=is-yaml.js.map
|
package/dist/utils/join/index.js
CHANGED