@scalar/openapi-parser 0.28.16 → 0.29.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/configuration/index.d.ts +6 -5307
  3. package/dist/configuration/index.d.ts.map +1 -1
  4. package/dist/configuration/index.js +2 -15
  5. package/dist/types/index.d.ts +3 -13
  6. package/dist/types/index.d.ts.map +1 -1
  7. package/dist/utils/details.d.ts.map +1 -1
  8. package/dist/utils/details.js +8 -1
  9. package/dist/utils/openapi/openapi.d.ts +172 -172
  10. package/dist/utils/validate.d.ts +6 -1
  11. package/dist/utils/validate.d.ts.map +1 -1
  12. package/dist/utils/validate.js +75 -29
  13. package/package.json +7 -11
  14. package/dist/lib/Validator/Validator.d.ts +0 -22
  15. package/dist/lib/Validator/Validator.d.ts.map +0 -1
  16. package/dist/lib/Validator/Validator.js +0 -146
  17. package/dist/schemas/v2.0/schema.d.ts +0 -1407
  18. package/dist/schemas/v2.0/schema.d.ts.map +0 -1
  19. package/dist/schemas/v2.0/schema.js +0 -1466
  20. package/dist/schemas/v3.0/schema.d.ts +0 -1269
  21. package/dist/schemas/v3.0/schema.d.ts.map +0 -1
  22. package/dist/schemas/v3.0/schema.js +0 -1499
  23. package/dist/schemas/v3.1/schema.d.ts +0 -1225
  24. package/dist/schemas/v3.1/schema.d.ts.map +0 -1
  25. package/dist/schemas/v3.1/schema.js +0 -1292
  26. package/dist/schemas/v3.2/schema.d.ts +0 -1409
  27. package/dist/schemas/v3.2/schema.d.ts.map +0 -1
  28. package/dist/schemas/v3.2/schema.js +0 -1509
  29. package/dist/utils/betterAjvErrors/helpers.d.ts +0 -3
  30. package/dist/utils/betterAjvErrors/helpers.d.ts.map +0 -1
  31. package/dist/utils/betterAjvErrors/helpers.js +0 -159
  32. package/dist/utils/betterAjvErrors/index.d.ts +0 -17
  33. package/dist/utils/betterAjvErrors/index.d.ts.map +0 -1
  34. package/dist/utils/betterAjvErrors/index.js +0 -12
  35. package/dist/utils/betterAjvErrors/utils.d.ts +0 -13
  36. package/dist/utils/betterAjvErrors/utils.d.ts.map +0 -1
  37. package/dist/utils/betterAjvErrors/utils.js +0 -21
  38. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +0 -10
  39. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +0 -1
  40. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +0 -15
  41. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +0 -23
  42. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +0 -1
  43. package/dist/utils/betterAjvErrors/validation-errors/base.js +0 -21
  44. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +0 -10
  45. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +0 -1
  46. package/dist/utils/betterAjvErrors/validation-errors/default.js +0 -15
  47. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +0 -11
  48. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +0 -1
  49. package/dist/utils/betterAjvErrors/validation-errors/enum.js +0 -36
  50. package/dist/utils/betterAjvErrors/validation-errors/format.d.ts +0 -27
  51. package/dist/utils/betterAjvErrors/validation-errors/format.d.ts.map +0 -1
  52. package/dist/utils/betterAjvErrors/validation-errors/format.js +0 -73
  53. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +0 -8
  54. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +0 -1
  55. package/dist/utils/betterAjvErrors/validation-errors/index.js +0 -7
  56. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +0 -10
  57. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +0 -1
  58. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +0 -15
  59. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +0 -10
  60. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +0 -1
  61. package/dist/utils/betterAjvErrors/validation-errors/required.js +0 -14
  62. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +0 -10
  63. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +0 -1
  64. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +0 -15
  65. package/dist/utils/transform-errors.d.ts +0 -6
  66. package/dist/utils/transform-errors.d.ts.map +0 -1
  67. package/dist/utils/transform-errors.js +0 -65
  68. package/dist/utils/validate-path-parameters.d.ts +0 -6
  69. package/dist/utils/validate-path-parameters.d.ts.map +0 -1
  70. 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
- }