@scalar/openapi-parser 0.23.12 → 0.24.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 +29 -0
- package/dist/configuration/index.d.ts +23 -8
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.d.ts +1 -1
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +11 -5
- package/dist/lib/Validator/Validator.js.map +2 -2
- package/dist/schemas/v2.0/schema.d.ts +3 -1
- package/dist/schemas/v2.0/schema.d.ts.map +1 -1
- package/dist/schemas/v2.0/schema.js +8 -1
- package/dist/schemas/v2.0/schema.js.map +2 -2
- package/dist/schemas/v3.0/schema.d.ts +8 -3
- package/dist/schemas/v3.0/schema.d.ts.map +1 -1
- package/dist/schemas/v3.0/schema.js +15 -5
- package/dist/schemas/v3.0/schema.js.map +2 -2
- package/dist/schemas/v3.1/schema.js +1 -1
- package/dist/schemas/v3.1/schema.js.map +1 -1
- package/dist/schemas/v3.2/schema.d.ts +12 -4
- package/dist/schemas/v3.2/schema.d.ts.map +1 -1
- package/dist/schemas/v3.2/schema.js +15 -7
- package/dist/schemas/v3.2/schema.js.map +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/betterAjvErrors/helpers.d.ts.map +1 -1
- package/dist/utils/betterAjvErrors/helpers.js +34 -6
- package/dist/utils/betterAjvErrors/helpers.js.map +2 -2
- package/dist/utils/betterAjvErrors/utils.d.ts +4 -0
- package/dist/utils/betterAjvErrors/utils.d.ts.map +1 -1
- package/dist/utils/betterAjvErrors/utils.js +8 -0
- package/dist/utils/betterAjvErrors/utils.js.map +2 -2
- package/dist/utils/transform-errors.d.ts +1 -1
- package/dist/utils/transform-errors.d.ts.map +1 -1
- package/dist/utils/transform-errors.js +43 -5
- package/dist/utils/transform-errors.js.map +2 -2
- package/package.json +6 -6
|
@@ -7,11 +7,49 @@ function transformErrors(specification, errors) {
|
|
|
7
7
|
}
|
|
8
8
|
];
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (!specification || typeof specification !== "object") {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
message: "Invalid specification"
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
let processedErrors;
|
|
18
|
+
try {
|
|
19
|
+
processedErrors = betterAjvErrors(specification, null, errors, {
|
|
20
|
+
indent: 2
|
|
21
|
+
}).map((error) => {
|
|
22
|
+
error.message = error.message.trim();
|
|
23
|
+
return error;
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(error);
|
|
27
|
+
if (Array.isArray(errors)) {
|
|
28
|
+
return errors.map((err) => {
|
|
29
|
+
let message = err.message || "Validation error";
|
|
30
|
+
if (err.keyword === "additionalProperties" && err.params?.additionalProperty) {
|
|
31
|
+
message = `Property ${err.params.additionalProperty} is not expected to be here`;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
message,
|
|
35
|
+
path: err.dataPath || err.instancePath
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
message: "Validation failed"
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
const seen = /* @__PURE__ */ new Set();
|
|
46
|
+
return processedErrors.filter((error) => {
|
|
47
|
+
const key = `${error.message}||${error.path}`;
|
|
48
|
+
if (seen.has(key)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
seen.add(key);
|
|
52
|
+
return true;
|
|
15
53
|
});
|
|
16
54
|
}
|
|
17
55
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\n\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 // If specification is null or invalid, betterAjvErrors cannot process it\n // This can happen when reference resolution fails\n if (!specification || typeof specification !== 'object') {\n return [\n {\n message: 'Invalid specification',\n },\n ]\n }\n\n // Wrap betterAjvErrors in a try-catch since it can fail with malformed schemas\n let processedErrors\n try {\n processedErrors = betterAjvErrors(specification, null, errors, {\n indent: 2,\n }).map((error) => {\n error.message = error.message.trim()\n\n return error\n })\n } catch (error) {\n console.error(error)\n // If betterAjvErrors fails, fall back to raw AJV errors\n if (Array.isArray(errors)) {\n return errors.map((err) => {\n let message = err.message || 'Validation error'\n\n // For additionalProperties errors, include the property name\n if (err.keyword === 'additionalProperties' && err.params?.additionalProperty) {\n message = `Property ${err.params.additionalProperty} is not expected to be here`\n }\n\n return {\n message,\n path: err.dataPath || err.instancePath,\n }\n })\n }\n return [\n {\n message: 'Validation failed',\n },\n ]\n }\n\n // Deduplicate errors with the same message and path\n const seen = new Set<string>()\n return processedErrors.filter((error) => {\n const key = `${error.message}||${error.path}`\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,uBAAuB;AAKzB,SAAS,gBAAgB,eAA0B,Q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-
"version": "0.
|
|
20
|
+
"version": "0.24.1",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
"jsonpointer": "^5.0.1",
|
|
55
55
|
"leven": "^4.0.0",
|
|
56
56
|
"yaml": "^2.8.0",
|
|
57
|
-
"@scalar/json-magic": "0.
|
|
57
|
+
"@scalar/json-magic": "0.9.1",
|
|
58
58
|
"@scalar/openapi-types": "0.5.3",
|
|
59
|
-
"@scalar/openapi-upgrader": "0.1.
|
|
59
|
+
"@scalar/openapi-upgrader": "0.1.7"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@apidevtools/swagger-parser": "10.1.0",
|
|
63
|
-
"@types/node": "^22.
|
|
63
|
+
"@types/node": "^22.19.3",
|
|
64
64
|
"just-diff": "^6.0.2",
|
|
65
|
-
"vite": "7.1
|
|
65
|
+
"vite": "^7.3.1",
|
|
66
66
|
"@scalar/build-tooling": "0.4.1",
|
|
67
|
-
"@scalar/types": "0.5.
|
|
67
|
+
"@scalar/types": "0.5.8"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "scalar-build-esbuild",
|