@scalar/openapi-parser 0.28.16 → 0.29.1
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 +19 -0
- package/dist/configuration/index.d.ts +6 -5307
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +2 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +8 -1
- package/dist/utils/filter.d.ts +2 -1
- package/dist/utils/filter.d.ts.map +1 -1
- package/dist/utils/get-list-of-references.d.ts +1 -1
- package/dist/utils/get-list-of-references.d.ts.map +1 -1
- package/dist/utils/join/join.d.ts +1 -1
- package/dist/utils/join/join.d.ts.map +1 -1
- package/dist/utils/join/merge-objects.d.ts.map +1 -1
- package/dist/utils/join/merge-objects.js +7 -0
- package/dist/utils/make-filesystem.d.ts +2 -1
- package/dist/utils/make-filesystem.d.ts.map +1 -1
- package/dist/utils/openapi/openapi.d.ts +352 -352
- package/dist/utils/resolve-references.d.ts +2 -1
- package/dist/utils/resolve-references.d.ts.map +1 -1
- package/dist/utils/to-json.d.ts +1 -1
- package/dist/utils/to-json.d.ts.map +1 -1
- package/dist/utils/to-yaml.d.ts +1 -1
- package/dist/utils/to-yaml.d.ts.map +1 -1
- package/dist/utils/transform/sanitize.d.ts +1 -1
- package/dist/utils/transform/sanitize.d.ts.map +1 -1
- package/dist/utils/transform/utils/addInfoObject.d.ts +1 -1
- package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts +1 -1
- package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
- package/dist/utils/transform/utils/addMissingTags.d.ts +1 -1
- package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts +1 -1
- package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts +1 -1
- package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
- package/dist/utils/traverse.d.ts.map +1 -1
- package/dist/utils/upgrade.d.ts +2 -1
- package/dist/utils/upgrade.d.ts.map +1 -1
- package/dist/utils/validate.d.ts +8 -2
- package/dist/utils/validate.d.ts.map +1 -1
- package/dist/utils/validate.js +75 -29
- package/package.json +7 -11
- package/dist/lib/Validator/Validator.d.ts +0 -22
- package/dist/lib/Validator/Validator.d.ts.map +0 -1
- package/dist/lib/Validator/Validator.js +0 -146
- package/dist/schemas/v2.0/schema.d.ts +0 -1407
- package/dist/schemas/v2.0/schema.d.ts.map +0 -1
- package/dist/schemas/v2.0/schema.js +0 -1466
- package/dist/schemas/v3.0/schema.d.ts +0 -1269
- package/dist/schemas/v3.0/schema.d.ts.map +0 -1
- package/dist/schemas/v3.0/schema.js +0 -1499
- package/dist/schemas/v3.1/schema.d.ts +0 -1225
- package/dist/schemas/v3.1/schema.d.ts.map +0 -1
- package/dist/schemas/v3.1/schema.js +0 -1292
- package/dist/schemas/v3.2/schema.d.ts +0 -1409
- package/dist/schemas/v3.2/schema.d.ts.map +0 -1
- package/dist/schemas/v3.2/schema.js +0 -1509
- package/dist/utils/betterAjvErrors/helpers.d.ts +0 -3
- package/dist/utils/betterAjvErrors/helpers.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/helpers.js +0 -159
- package/dist/utils/betterAjvErrors/index.d.ts +0 -17
- package/dist/utils/betterAjvErrors/index.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/index.js +0 -12
- package/dist/utils/betterAjvErrors/utils.d.ts +0 -13
- package/dist/utils/betterAjvErrors/utils.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/utils.js +0 -21
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +0 -10
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +0 -15
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +0 -23
- package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/base.js +0 -21
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +0 -10
- package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/default.js +0 -15
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +0 -11
- package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +0 -36
- package/dist/utils/betterAjvErrors/validation-errors/format.d.ts +0 -27
- package/dist/utils/betterAjvErrors/validation-errors/format.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/format.js +0 -73
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +0 -8
- package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/index.js +0 -7
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +0 -10
- package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +0 -15
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +0 -10
- package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/required.js +0 -14
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +0 -10
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +0 -1
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +0 -15
- package/dist/utils/transform-errors.d.ts +0 -6
- package/dist/utils/transform-errors.d.ts.map +0 -1
- package/dist/utils/transform-errors.js +0 -65
- package/dist/utils/validate-path-parameters.d.ts +0 -6
- package/dist/utils/validate-path-parameters.d.ts.map +0 -1
- package/dist/utils/validate-path-parameters.js +0 -94
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { betterAjvErrors } from './betterAjvErrors/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Transforms ajv errors, finds the positions in the schema and returns an enriched format.
|
|
4
|
-
*/
|
|
5
|
-
export function transformErrors(specification, errors) {
|
|
6
|
-
// TODO: This should work with multiple files
|
|
7
|
-
if (typeof errors === 'string') {
|
|
8
|
-
return [
|
|
9
|
-
{
|
|
10
|
-
message: errors,
|
|
11
|
-
},
|
|
12
|
-
];
|
|
13
|
-
}
|
|
14
|
-
// If specification is null or invalid, betterAjvErrors cannot process it
|
|
15
|
-
// This can happen when reference resolution fails
|
|
16
|
-
if (!specification || typeof specification !== 'object') {
|
|
17
|
-
return [
|
|
18
|
-
{
|
|
19
|
-
message: 'Invalid specification',
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
// Wrap betterAjvErrors in a try-catch since it can fail with malformed schemas
|
|
24
|
-
let processedErrors;
|
|
25
|
-
try {
|
|
26
|
-
processedErrors = betterAjvErrors(specification, null, errors, {
|
|
27
|
-
indent: 2,
|
|
28
|
-
}).map((error) => {
|
|
29
|
-
error.message = error.message.trim();
|
|
30
|
-
return error;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
console.error(error);
|
|
35
|
-
// If betterAjvErrors fails, fall back to raw AJV errors
|
|
36
|
-
if (Array.isArray(errors)) {
|
|
37
|
-
return errors.map((err) => {
|
|
38
|
-
let message = err.message || 'Validation error';
|
|
39
|
-
// For additionalProperties errors, include the property name
|
|
40
|
-
if (err.keyword === 'additionalProperties' && err.params?.additionalProperty) {
|
|
41
|
-
message = `Property ${err.params.additionalProperty} is not expected to be here`;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
message,
|
|
45
|
-
path: err.dataPath || err.instancePath,
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return [
|
|
50
|
-
{
|
|
51
|
-
message: 'Validation failed',
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
// Deduplicate errors with the same message and path
|
|
56
|
-
const seen = new Set();
|
|
57
|
-
return processedErrors.filter((error) => {
|
|
58
|
-
const key = `${error.message}||${error.path}`;
|
|
59
|
-
if (seen.has(key)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
seen.add(key);
|
|
63
|
-
return true;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AnyObject, ErrorObject } from '../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Validates path-template semantics that are not enforced by the JSON schema.
|
|
4
|
-
*/
|
|
5
|
-
export declare function validatePathParameters(specification: AnyObject): ErrorObject[];
|
|
6
|
-
//# sourceMappingURL=validate-path-parameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-path-parameters.d.ts","sourceRoot":"","sources":["../../src/utils/validate-path-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAU3D;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,EAAE,CAoE9E"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const OPERATION_KEYS = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
|
|
2
|
-
const PATH_PARAMETER_PATTERN = /{([^}]+)}/g;
|
|
3
|
-
/**
|
|
4
|
-
* Validates path-template semantics that are not enforced by the JSON schema.
|
|
5
|
-
*/
|
|
6
|
-
export function validatePathParameters(specification) {
|
|
7
|
-
const paths = specification?.paths;
|
|
8
|
-
if (!paths || typeof paths !== 'object') {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
const errors = [];
|
|
12
|
-
for (const [pathName, pathItem] of Object.entries(paths)) {
|
|
13
|
-
if (!isRecord(pathItem)) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
const operations = Object.entries(pathItem).filter(([key, value]) => OPERATION_KEYS.has(key) && isRecord(value));
|
|
17
|
-
// Preserve the repo's current behaviour for empty path items.
|
|
18
|
-
if (operations.length === 0) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const templateParameters = new Set(getTemplateParameterNames(pathName));
|
|
22
|
-
const pathLevelParameters = getPathParameters(pathItem.parameters, ['paths', pathName, 'parameters']);
|
|
23
|
-
for (const parameter of pathLevelParameters) {
|
|
24
|
-
if (!templateParameters.has(parameter.name)) {
|
|
25
|
-
errors.push({
|
|
26
|
-
path: parameter.path,
|
|
27
|
-
message: `Path parameter "${parameter.name}" must have the corresponding {${parameter.name}} segment in the "${pathName}" path`,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
for (const [operationKey, operation] of operations) {
|
|
32
|
-
const operationParameters = getPathParameters(operation.parameters, [
|
|
33
|
-
'paths',
|
|
34
|
-
pathName,
|
|
35
|
-
operationKey,
|
|
36
|
-
'parameters',
|
|
37
|
-
]);
|
|
38
|
-
for (const parameter of operationParameters) {
|
|
39
|
-
if (!templateParameters.has(parameter.name)) {
|
|
40
|
-
errors.push({
|
|
41
|
-
path: parameter.path,
|
|
42
|
-
message: `Path parameter "${parameter.name}" must have the corresponding {${parameter.name}} segment in the "${pathName}" path`,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const effectiveParameters = new Set([...pathLevelParameters, ...operationParameters].map((parameter) => parameter.name));
|
|
47
|
-
for (const templateParameter of templateParameters) {
|
|
48
|
-
if (!effectiveParameters.has(templateParameter)) {
|
|
49
|
-
errors.push({
|
|
50
|
-
path: ['paths', pathName, operationKey],
|
|
51
|
-
message: `Declared path parameter "${templateParameter}" needs to be defined as a path parameter at either the path or operation level`,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return deduplicateErrors(errors);
|
|
58
|
-
}
|
|
59
|
-
function getTemplateParameterNames(pathName) {
|
|
60
|
-
return [...pathName.matchAll(PATH_PARAMETER_PATTERN)].map((match) => normalizeTemplateParameterName(match[1]));
|
|
61
|
-
}
|
|
62
|
-
function normalizeTemplateParameterName(name) {
|
|
63
|
-
return name.endsWith('+') ? name.slice(0, -1) : name;
|
|
64
|
-
}
|
|
65
|
-
function getPathParameters(parameters, pathPrefix) {
|
|
66
|
-
if (!Array.isArray(parameters)) {
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
return parameters.flatMap((parameter, index) => {
|
|
70
|
-
if (!isRecord(parameter) || parameter.in !== 'path' || typeof parameter.name !== 'string') {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
return [
|
|
74
|
-
{
|
|
75
|
-
name: parameter.name,
|
|
76
|
-
path: [...pathPrefix, String(index), 'name'],
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function deduplicateErrors(errors) {
|
|
82
|
-
const seen = new Set();
|
|
83
|
-
return errors.filter((error) => {
|
|
84
|
-
const key = `${error.message}||${error.path?.join('.') ?? ''}`;
|
|
85
|
-
if (seen.has(key)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
seen.add(key);
|
|
89
|
-
return true;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function isRecord(value) {
|
|
93
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
94
|
-
}
|