@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.
Files changed (103) hide show
  1. package/CHANGELOG.md +19 -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/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/types/index.d.ts +3 -13
  8. package/dist/types/index.d.ts.map +1 -1
  9. package/dist/utils/details.d.ts.map +1 -1
  10. package/dist/utils/details.js +8 -1
  11. package/dist/utils/filter.d.ts +2 -1
  12. package/dist/utils/filter.d.ts.map +1 -1
  13. package/dist/utils/get-list-of-references.d.ts +1 -1
  14. package/dist/utils/get-list-of-references.d.ts.map +1 -1
  15. package/dist/utils/join/join.d.ts +1 -1
  16. package/dist/utils/join/join.d.ts.map +1 -1
  17. package/dist/utils/join/merge-objects.d.ts.map +1 -1
  18. package/dist/utils/join/merge-objects.js +7 -0
  19. package/dist/utils/make-filesystem.d.ts +2 -1
  20. package/dist/utils/make-filesystem.d.ts.map +1 -1
  21. package/dist/utils/openapi/openapi.d.ts +352 -352
  22. package/dist/utils/resolve-references.d.ts +2 -1
  23. package/dist/utils/resolve-references.d.ts.map +1 -1
  24. package/dist/utils/to-json.d.ts +1 -1
  25. package/dist/utils/to-json.d.ts.map +1 -1
  26. package/dist/utils/to-yaml.d.ts +1 -1
  27. package/dist/utils/to-yaml.d.ts.map +1 -1
  28. package/dist/utils/transform/sanitize.d.ts +1 -1
  29. package/dist/utils/transform/sanitize.d.ts.map +1 -1
  30. package/dist/utils/transform/utils/addInfoObject.d.ts +1 -1
  31. package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
  32. package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts +1 -1
  33. package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
  34. package/dist/utils/transform/utils/addMissingTags.d.ts +1 -1
  35. package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
  36. package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts +1 -1
  37. package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
  38. package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts +1 -1
  39. package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
  40. package/dist/utils/traverse.d.ts.map +1 -1
  41. package/dist/utils/upgrade.d.ts +2 -1
  42. package/dist/utils/upgrade.d.ts.map +1 -1
  43. package/dist/utils/validate.d.ts +8 -2
  44. package/dist/utils/validate.d.ts.map +1 -1
  45. package/dist/utils/validate.js +75 -29
  46. package/package.json +7 -11
  47. package/dist/lib/Validator/Validator.d.ts +0 -22
  48. package/dist/lib/Validator/Validator.d.ts.map +0 -1
  49. package/dist/lib/Validator/Validator.js +0 -146
  50. package/dist/schemas/v2.0/schema.d.ts +0 -1407
  51. package/dist/schemas/v2.0/schema.d.ts.map +0 -1
  52. package/dist/schemas/v2.0/schema.js +0 -1466
  53. package/dist/schemas/v3.0/schema.d.ts +0 -1269
  54. package/dist/schemas/v3.0/schema.d.ts.map +0 -1
  55. package/dist/schemas/v3.0/schema.js +0 -1499
  56. package/dist/schemas/v3.1/schema.d.ts +0 -1225
  57. package/dist/schemas/v3.1/schema.d.ts.map +0 -1
  58. package/dist/schemas/v3.1/schema.js +0 -1292
  59. package/dist/schemas/v3.2/schema.d.ts +0 -1409
  60. package/dist/schemas/v3.2/schema.d.ts.map +0 -1
  61. package/dist/schemas/v3.2/schema.js +0 -1509
  62. package/dist/utils/betterAjvErrors/helpers.d.ts +0 -3
  63. package/dist/utils/betterAjvErrors/helpers.d.ts.map +0 -1
  64. package/dist/utils/betterAjvErrors/helpers.js +0 -159
  65. package/dist/utils/betterAjvErrors/index.d.ts +0 -17
  66. package/dist/utils/betterAjvErrors/index.d.ts.map +0 -1
  67. package/dist/utils/betterAjvErrors/index.js +0 -12
  68. package/dist/utils/betterAjvErrors/utils.d.ts +0 -13
  69. package/dist/utils/betterAjvErrors/utils.d.ts.map +0 -1
  70. package/dist/utils/betterAjvErrors/utils.js +0 -21
  71. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +0 -10
  72. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +0 -1
  73. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +0 -15
  74. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +0 -23
  75. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +0 -1
  76. package/dist/utils/betterAjvErrors/validation-errors/base.js +0 -21
  77. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +0 -10
  78. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +0 -1
  79. package/dist/utils/betterAjvErrors/validation-errors/default.js +0 -15
  80. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +0 -11
  81. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +0 -1
  82. package/dist/utils/betterAjvErrors/validation-errors/enum.js +0 -36
  83. package/dist/utils/betterAjvErrors/validation-errors/format.d.ts +0 -27
  84. package/dist/utils/betterAjvErrors/validation-errors/format.d.ts.map +0 -1
  85. package/dist/utils/betterAjvErrors/validation-errors/format.js +0 -73
  86. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +0 -8
  87. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +0 -1
  88. package/dist/utils/betterAjvErrors/validation-errors/index.js +0 -7
  89. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +0 -10
  90. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +0 -1
  91. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +0 -15
  92. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +0 -10
  93. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +0 -1
  94. package/dist/utils/betterAjvErrors/validation-errors/required.js +0 -14
  95. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +0 -10
  96. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +0 -1
  97. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +0 -15
  98. package/dist/utils/transform-errors.d.ts +0 -6
  99. package/dist/utils/transform-errors.d.ts.map +0 -1
  100. package/dist/utils/transform-errors.js +0 -65
  101. package/dist/utils/validate-path-parameters.d.ts +0 -6
  102. package/dist/utils/validate-path-parameters.d.ts.map +0 -1
  103. 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
- }