@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,3 +0,0 @@
1
- import { EnumValidationError } from './validation-errors/index.js';
2
- export default function prettify(ajvErrors: any, options: any): EnumValidationError[];
3
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/betterAjvErrors/helpers.ts"],"names":[],"mappings":"AAcA,OAAO,EAGL,mBAAmB,EAKpB,MAAM,qBAAqB,CAAA;AAwK5B,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA,yBAKlD"}
@@ -1,159 +0,0 @@
1
- import { concatAll, getChildren, getErrors, getSiblings, isAdditionalPropertiesError, isAnyOfError, isEnumError, isIfError, isOneOfError, isRequiredError, isUnevaluatedPropertiesError, notUndefined, } from './utils.js';
2
- import { AdditionalPropValidationError, DefaultValidationError, EnumValidationError, FormatValidationError, PatternValidationError, RequiredValidationError, UnevaluatedPropValidationError, } from './validation-errors/index.js';
3
- const JSON_POINTERS_REGEX = /\/[\w$_-]+(\/\d+)?/g;
4
- // Make a tree of errors from ajv errors array
5
- function makeTree(ajvErrors = []) {
6
- const root = { children: {} };
7
- ajvErrors.forEach((ajvError) => {
8
- const instancePath = typeof ajvError.instancePath !== 'undefined' ? ajvError.instancePath : ajvError.dataPath;
9
- // `dataPath === ''` is root
10
- const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);
11
- if (paths) {
12
- paths.reduce((obj, path, i) => {
13
- obj.children[path] = obj.children[path] || { children: {}, errors: [] };
14
- if (i === paths.length - 1) {
15
- obj.children[path].errors.push(ajvError);
16
- }
17
- return obj.children[path];
18
- }, root);
19
- }
20
- });
21
- return root;
22
- }
23
- function filterRedundantErrors(root, parent, key) {
24
- const errors = getErrors(root);
25
- const hasOneOfError = errors.some(isOneOfError);
26
- const hasAnyOfError = errors.some(isAnyOfError);
27
- const hasRequiredError = errors.some(isRequiredError);
28
- const hasIfError = errors.some(isIfError);
29
- const hasAdditionalPropertiesError = errors.some(isAdditionalPropertiesError);
30
- const hasUnevaluatedPropertiesError = errors.some(isUnevaluatedPropertiesError);
31
- const hasChildren = Object.keys(root.children || {}).length > 0;
32
- /**
33
- * If there is an `if` error with `additionalProperties` or `unevaluatedProperties` error,
34
- * filter out the `if` error as it's just noise from the if/then/else conditional.
35
- */
36
- if (hasIfError && (hasAdditionalPropertiesError || hasUnevaluatedPropertiesError)) {
37
- root.errors = errors.filter((error) => !isIfError(error));
38
- }
39
- /**
40
- * If there is a `oneOf` error with a `required` error:
41
- * 1. If there are other errors at this level (like additionalProperties), keep those
42
- * 2. If there are child errors, don't clear them - they're more meaningful
43
- * The `required` error is likely from a failed oneOf branch (e.g., Reference requiring $ref).
44
- */
45
- if (hasOneOfError && hasRequiredError) {
46
- if (hasAdditionalPropertiesError || hasUnevaluatedPropertiesError) {
47
- // Filter out the required and oneOf errors, keep the meaningful ones at this level
48
- root.errors = errors.filter((error) => !isRequiredError(error) && !isOneOfError(error));
49
- }
50
- else if (hasChildren) {
51
- // Clear parent errors, keep children as they're more meaningful
52
- delete root.errors;
53
- }
54
- else {
55
- // Both `oneOf` branches produced a `required` error: one from the schema
56
- // the user most likely intended (e.g. a Response needs `description`) and
57
- // one from the `Reference` branch (needs `$ref`). Surface the intended
58
- // schema's error and drop the `$ref` noise so the message is actionable.
59
- // Only fall back to the generic `oneOf` error when the sole requirement
60
- // left is `$ref` (i.e. the value looks like a broken reference).
61
- const meaningfulRequiredErrors = errors.filter((error) => isRequiredError(error) && error.params?.missingProperty !== '$ref');
62
- root.errors = meaningfulRequiredErrors.length > 0 ? meaningfulRequiredErrors : errors.filter(isOneOfError);
63
- }
64
- }
65
- else if (hasOneOfError && !hasRequiredError && hasChildren) {
66
- /**
67
- * If there is only a `oneOf` error (without required complications):
68
- * If there are child errors, clear the oneOf error to surface the children.
69
- * Children will have more specific information about why each branch failed.
70
- */
71
- // Clear the generic oneOf errors, let children surface
72
- delete root.errors;
73
- }
74
- else if (hasOneOfError && !hasRequiredError && !hasChildren) {
75
- /**
76
- * If we have multiple oneOf errors (duplicates from different branches),
77
- * keep only one to avoid noise.
78
- */
79
- const oneOfErrors = errors.filter(isOneOfError);
80
- if (oneOfErrors.length > 1) {
81
- // Keep only the first oneOf error
82
- root.errors = [oneOfErrors[0]];
83
- }
84
- }
85
- else if (hasRequiredError && !hasOneOfError) {
86
- /**
87
- * If there is a `required` error (without oneOf complications),
88
- * then we can just skip everything else.
89
- * And, also `required` should have more priority than `anyOf`. @see #8
90
- */
91
- root.errors = errors.filter(isRequiredError);
92
- root.children = {};
93
- }
94
- /**
95
- * If there is an `anyOf` error that means we have more meaningful errors
96
- * inside children. So we will just remove all errors from this level.
97
- *
98
- * If there are no children, then we don't delete the errors since we should
99
- * have at least one error to report.
100
- */
101
- if (hasAnyOfError) {
102
- if (Object.keys(root.children).length > 0) {
103
- delete root.errors;
104
- }
105
- }
106
- /**
107
- * If all errors are `enum` and siblings have any error then we can safely
108
- * ignore the node.
109
- *
110
- * **CAUTION**
111
- * Need explicit `root.errors` check because `[].every(fn) === true`
112
- * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics
113
- */
114
- if (root.errors?.length && getErrors(root).every(isEnumError)) {
115
- if (getSiblings(parent)(root)
116
- // Remove any reference which becomes `undefined` later
117
- .filter(notUndefined)
118
- .some(getErrors)) {
119
- delete parent.children[key];
120
- }
121
- }
122
- Object.entries(root.children).forEach(([k, child]) => filterRedundantErrors(child, root, k));
123
- }
124
- function createErrorInstances(root, options) {
125
- const errors = getErrors(root);
126
- if (errors.length && errors.every(isEnumError)) {
127
- const uniqueValues = new Set(concatAll([])(errors.map((e) => e.params.allowedValues)));
128
- const allowedValues = [...uniqueValues];
129
- const error = errors[0];
130
- return [
131
- new EnumValidationError({
132
- ...error,
133
- params: { allowedValues },
134
- }, options),
135
- ];
136
- }
137
- return concatAll(errors.reduce((ret, error) => {
138
- switch (error.keyword) {
139
- case 'additionalProperties':
140
- return ret.concat(new AdditionalPropValidationError(error, options));
141
- case 'pattern':
142
- return ret.concat(new PatternValidationError(error, options));
143
- case 'format':
144
- return ret.concat(new FormatValidationError(error, options));
145
- case 'required':
146
- return ret.concat(new RequiredValidationError(error, options));
147
- case 'unevaluatedProperties':
148
- return ret.concat(new UnevaluatedPropValidationError(error, options));
149
- default:
150
- return ret.concat(new DefaultValidationError(error, options));
151
- }
152
- }, []))(getChildren(root).map((child) => createErrorInstances(child, options)));
153
- }
154
- export default function prettify(ajvErrors, options) {
155
- const tree = makeTree(ajvErrors || []);
156
- // @ts-expect-error TODO
157
- filterRedundantErrors(tree);
158
- return createErrorInstances(tree, options);
159
- }
@@ -1,17 +0,0 @@
1
- type BetterAjvErrorsOptions = {
2
- indent?: number;
3
- json?: string;
4
- };
5
- type AjvError = {
6
- keyword: string;
7
- dataPath: string;
8
- schemaPath: string;
9
- params: any;
10
- message: string;
11
- schema: any;
12
- parentSchema: any;
13
- data: any;
14
- };
15
- export declare function betterAjvErrors(schema: any, data: any, errors: AjvError[], options?: BetterAjvErrorsOptions): any[];
16
- export {};
17
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/betterAjvErrors/index.ts"],"names":[],"mappings":"AAEA,KAAK,sBAAsB,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAGD,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,GAAG,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,GAAG,CAAA;IACX,YAAY,EAAE,GAAG,CAAA;IACjB,IAAI,EAAE,GAAG,CAAA;CACV,CAAA;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAE,sBAA2B,SAa/G"}
@@ -1,12 +0,0 @@
1
- import prettify from './helpers.js';
2
- export function betterAjvErrors(schema, data, errors, options = {}) {
3
- const { indent = null, json = null } = options;
4
- const jsonRaw = json || JSON.stringify(data, null, indent);
5
- const customErrorToStructure = (error) => error.getError();
6
- const customErrors = prettify(errors, {
7
- data,
8
- schema,
9
- jsonRaw,
10
- });
11
- return customErrors.map(customErrorToStructure);
12
- }
@@ -1,13 +0,0 @@
1
- export declare const notUndefined: (x: any) => boolean;
2
- export declare const isRequiredError: (error: any) => boolean;
3
- export declare const isAnyOfError: (error: any) => boolean;
4
- export declare const isOneOfError: (error: any) => boolean;
5
- export declare const isIfError: (error: any) => boolean;
6
- export declare const isEnumError: (error: any) => boolean;
7
- export declare const isAdditionalPropertiesError: (error: any) => boolean;
8
- export declare const isUnevaluatedPropertiesError: (error: any) => boolean;
9
- export declare const getErrors: (node: any) => any;
10
- export declare const getChildren: (node: any) => unknown[];
11
- export declare const getSiblings: (parent: any) => (node: any) => unknown[];
12
- export declare const concatAll: (xs: any) => (ys: any) => any;
13
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/betterAjvErrors/utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,GAAI,MAAC,YAAoB,CAAA;AAIlD,eAAO,MAAM,eAAe,yBAAuB,CAAA;AACnD,eAAO,MAAM,YAAY,yBAAoB,CAAA;AAC7C,eAAO,MAAM,YAAY,yBAAoB,CAAA;AAC7C,eAAO,MAAM,SAAS,yBAAiB,CAAA;AACvC,eAAO,MAAM,WAAW,yBAAmB,CAAA;AAC3C,eAAO,MAAM,2BAA2B,yBAAmC,CAAA;AAC3E,eAAO,MAAM,4BAA4B,yBAAoC,CAAA;AAC7E,eAAO,MAAM,SAAS,GAAI,SAAI,QAAuB,CAAA;AAGrD,eAAO,MAAM,WAAW,GAAI,SAAI,cAA6C,CAAA;AAE7E,eAAO,MAAM,WAAW,GAAI,WAAM,MAAkB,SAAI,cACb,CAAA;AAE3C,eAAO,MAAM,SAAS,GAGnB,OAAE,MAA+B,OAAE,QACI,CAAA"}
@@ -1,21 +0,0 @@
1
- // Basic
2
- const eq = (x) => (y) => x === y;
3
- const not = (fn) => (x) => !fn(x);
4
- const getValues = (o) => Object.values(o);
5
- export const notUndefined = (x) => x !== undefined;
6
- // Error
7
- const isXError = (x) => (error) => error.keyword === x;
8
- export const isRequiredError = isXError('required');
9
- export const isAnyOfError = isXError('anyOf');
10
- export const isOneOfError = isXError('oneOf');
11
- export const isIfError = isXError('if');
12
- export const isEnumError = isXError('enum');
13
- export const isAdditionalPropertiesError = isXError('additionalProperties');
14
- export const isUnevaluatedPropertiesError = isXError('unevaluatedProperties');
15
- export const getErrors = (node) => node?.errors || [];
16
- // Node
17
- export const getChildren = (node) => (node && getValues(node.children)) || [];
18
- export const getSiblings = (parent /*: Node */) => (node /*: Node */) => getChildren(parent).filter(not(eq(node)));
19
- export const concatAll =
20
- /* ::<T> */
21
- (xs /*: $ReadOnlyArray<T> */) => (ys /* : $ReadOnlyArray<T> */) => ys.reduce((zs, z) => zs.concat(z), xs);
@@ -1,10 +0,0 @@
1
- export default class AdditionalPropValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- }
9
- import BaseValidationError from './base.js';
10
- //# sourceMappingURL=additional-prop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"additional-prop.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/additional-prop.js"],"names":[],"mappings":"AAEA;IACE,4BAIC;IAFC,aAA2C;IAI7C;;;MAOC;CACF;gCAjB+B,QAAQ"}
@@ -1,15 +0,0 @@
1
- import BaseValidationError from './base.js';
2
- export default class AdditionalPropValidationError extends BaseValidationError {
3
- constructor(...args) {
4
- super(...args);
5
- this.name = 'AdditionalPropValidationError';
6
- this.options.isIdentifierLocation = true;
7
- }
8
- getError() {
9
- const { params } = this.options;
10
- return {
11
- message: `Property ${params.additionalProperty} is not expected to be here`,
12
- path: this.instancePath,
13
- };
14
- }
15
- }
@@ -1,23 +0,0 @@
1
- export default class BaseValidationError {
2
- constructor(options: {
3
- isIdentifierLocation: boolean;
4
- }, { data, schema, jsonAst, jsonRaw }: {
5
- data: any;
6
- schema: any;
7
- jsonAst: any;
8
- jsonRaw: any;
9
- });
10
- options: {
11
- isIdentifierLocation: boolean;
12
- };
13
- data: any;
14
- schema: any;
15
- jsonAst: any;
16
- jsonRaw: any;
17
- /**
18
- * @return {string}
19
- */
20
- get instancePath(): string;
21
- getError(): void;
22
- }
23
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/base.js"],"names":[],"mappings":"AAIA;IACE;;;;;;;OAMC;IALC;;MAAsB;IACtB,UAAgB;IAChB,YAAoB;IACpB,aAAsB;IACtB,aAAsB;IAGxB;;OAEG;IACH,oBAFY,MAAM,CAIjB;IAED,iBAEC;CACF"}
@@ -1,21 +0,0 @@
1
- // import { codeFrameColumns } from '@babel/code-frame';
2
- // import chalk from 'chalk';
3
- // import { getMetaFromPath } from '@/json/index'
4
- export default class BaseValidationError {
5
- constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {
6
- this.options = options;
7
- this.data = data;
8
- this.schema = schema;
9
- this.jsonAst = jsonAst;
10
- this.jsonRaw = jsonRaw;
11
- }
12
- /**
13
- * @return {string}
14
- */
15
- get instancePath() {
16
- return typeof this.options.instancePath !== 'undefined' ? this.options.instancePath : this.options.dataPath;
17
- }
18
- getError() {
19
- throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);
20
- }
21
- }
@@ -1,10 +0,0 @@
1
- export default class DefaultValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- }
9
- import BaseValidationError from './base.js';
10
- //# sourceMappingURL=default.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/default.js"],"names":[],"mappings":"AAEA;IACE,4BAIC;IAFC,aAAoC;IAItC;;;MAOC;CACF;gCAjB+B,QAAQ"}
@@ -1,15 +0,0 @@
1
- import BaseValidationError from './base.js';
2
- export default class DefaultValidationError extends BaseValidationError {
3
- constructor(...args) {
4
- super(...args);
5
- this.name = 'DefaultValidationError';
6
- this.options.isSkipEndLocation = true;
7
- }
8
- getError() {
9
- const { keyword, message } = this.options;
10
- return {
11
- message: `${keyword} ${message}`,
12
- path: this.instancePath,
13
- };
14
- }
15
- }
@@ -1,11 +0,0 @@
1
- export default class EnumValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- findBestMatch(): any;
9
- }
10
- import BaseValidationError from './base.js';
11
- //# sourceMappingURL=enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/enum.js"],"names":[],"mappings":"AAKA;IACE,4BAGC;IADC,aAAiC;IAGnC;;;MAeC;IAED,qBAmBC;CACF;gCA7C+B,QAAQ"}
@@ -1,36 +0,0 @@
1
- import pointer from 'jsonpointer';
2
- import leven from 'leven';
3
- import BaseValidationError from './base.js';
4
- export default class EnumValidationError extends BaseValidationError {
5
- constructor(...args) {
6
- super(...args);
7
- this.name = 'EnumValidationError';
8
- }
9
- getError() {
10
- const { message, params } = this.options;
11
- const bestMatch = this.findBestMatch();
12
- const allowedValues = params.allowedValues.join(', ');
13
- const output = {
14
- message: `${message}: ${allowedValues}`,
15
- path: this.instancePath,
16
- };
17
- if (bestMatch !== null) {
18
- output.suggestion = `Did you mean ${bestMatch}?`;
19
- }
20
- return output;
21
- }
22
- findBestMatch() {
23
- const { params: { allowedValues }, } = this.options;
24
- const currentValue = this.instancePath === '' ? this.data : pointer.get(this.data, this.instancePath);
25
- if (!currentValue) {
26
- return null;
27
- }
28
- const bestMatch = allowedValues
29
- .map((value) => ({
30
- value,
31
- weight: leven(value, currentValue.toString()),
32
- }))
33
- .sort((x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0))[0];
34
- return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
35
- }
36
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Enhanced error messages for `format` keyword validation failures.
3
- *
4
- * Currently provides context for:
5
- * - `uri-reference` format on `$ref` paths (non-ASCII characters, etc.)
6
- *
7
- * To add a new format enhancer, add a case to the switch in `getError()`.
8
- */
9
- export default class FormatValidationError extends BaseValidationError {
10
- constructor(...args: any[]);
11
- name: string;
12
- getError(): {
13
- message: string;
14
- path: string;
15
- };
16
- /**
17
- * Builds a contextual error message for uri-reference format failures on $ref values.
18
- */
19
- _getUriReferenceMessage(): string;
20
- /**
21
- * Attempts to extract the actual $ref value from the specification
22
- * by walking the instancePath through the spec object.
23
- */
24
- _extractRefValue(): string;
25
- }
26
- import BaseValidationError from './base.js';
27
- //# sourceMappingURL=format.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/format.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH;IACE,4BAIC;IAFC,aAAmC;IAIrC;;;MAkBC;IAED;;OAEG;IACH,kCAYC;IAED;;;OAGG;IACH,2BA0BC;CACF;gCArF+B,QAAQ"}
@@ -1,73 +0,0 @@
1
- import BaseValidationError from './base.js';
2
- /**
3
- * Enhanced error messages for `format` keyword validation failures.
4
- *
5
- * Currently provides context for:
6
- * - `uri-reference` format on `$ref` paths (non-ASCII characters, etc.)
7
- *
8
- * To add a new format enhancer, add a case to the switch in `getError()`.
9
- */
10
- export default class FormatValidationError extends BaseValidationError {
11
- constructor(...args) {
12
- super(...args);
13
- this.name = 'FormatValidationError';
14
- this.options.isSkipEndLocation = true;
15
- }
16
- getError() {
17
- const { keyword, message, params, instancePath: errorPath } = this.options;
18
- const path = this.instancePath;
19
- const format = params?.format;
20
- // uri-reference format on $ref paths
21
- if (format === 'uri-reference' && path?.endsWith('/$ref')) {
22
- return {
23
- message: this._getUriReferenceMessage(),
24
- path,
25
- };
26
- }
27
- // Default: fall back to the same format as DefaultValidationError
28
- return {
29
- message: `${keyword} ${message}`,
30
- path,
31
- };
32
- }
33
- /**
34
- * Builds a contextual error message for uri-reference format failures on $ref values.
35
- */
36
- _getUriReferenceMessage() {
37
- const refValue = this._extractRefValue();
38
- if (refValue && /[^\x00-\x7F]/.test(refValue)) {
39
- return `$ref "${refValue}" contains non-ASCII characters`;
40
- }
41
- if (refValue) {
42
- return `$ref "${refValue}" is not a valid URI reference`;
43
- }
44
- return '$ref is not a valid URI reference';
45
- }
46
- /**
47
- * Attempts to extract the actual $ref value from the specification
48
- * by walking the instancePath through the spec object.
49
- */
50
- _extractRefValue() {
51
- const spec = this.schema;
52
- if (!spec || typeof spec !== 'object') {
53
- return null;
54
- }
55
- const path = this.instancePath;
56
- if (!path) {
57
- return null;
58
- }
59
- // Parse JSON Pointer segments, decoding ~1 (/) and ~0 (~)
60
- const segments = path
61
- .split('/')
62
- .filter(Boolean)
63
- .map((s) => s.replace(/~1/g, '/').replace(/~0/g, '~'));
64
- let current = spec;
65
- for (const segment of segments) {
66
- if (current === null || current === undefined || typeof current !== 'object') {
67
- return null;
68
- }
69
- current = current[segment];
70
- }
71
- return typeof current === 'string' ? current : null;
72
- }
73
- }
@@ -1,8 +0,0 @@
1
- export { default as AdditionalPropValidationError } from "./additional-prop.js";
2
- export { default as DefaultValidationError } from "./default.js";
3
- export { default as EnumValidationError } from "./enum.js";
4
- export { default as FormatValidationError } from "./format.js";
5
- export { default as PatternValidationError } from "./pattern.js";
6
- export { default as RequiredValidationError } from "./required.js";
7
- export { default as UnevaluatedPropValidationError } from "./unevaluated-prop.js";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/index.js"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- export { default as AdditionalPropValidationError } from './additional-prop.js';
2
- export { default as DefaultValidationError } from './default.js';
3
- export { default as EnumValidationError } from './enum.js';
4
- export { default as FormatValidationError } from './format.js';
5
- export { default as PatternValidationError } from './pattern.js';
6
- export { default as RequiredValidationError } from './required.js';
7
- export { default as UnevaluatedPropValidationError } from './unevaluated-prop.js';
@@ -1,10 +0,0 @@
1
- export default class PatternValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- }
9
- import BaseValidationError from './base.js';
10
- //# sourceMappingURL=pattern.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/pattern.js"],"names":[],"mappings":"AAEA;IACE,4BAIC;IAFC,aAAoC;IAItC;;;MAOC;CACF;gCAjB+B,QAAQ"}
@@ -1,15 +0,0 @@
1
- import BaseValidationError from './base.js';
2
- export default class PatternValidationError extends BaseValidationError {
3
- constructor(...args) {
4
- super(...args);
5
- this.name = 'PatternValidationError';
6
- this.options.isIdentifierLocation = true;
7
- }
8
- getError() {
9
- const { params, propertyName } = this.options;
10
- return {
11
- message: `Property "${propertyName}" must match pattern ${params.pattern}`,
12
- path: this.instancePath,
13
- };
14
- }
15
- }
@@ -1,10 +0,0 @@
1
- export default class RequiredValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- }
9
- import BaseValidationError from './base.js';
10
- //# sourceMappingURL=required.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"required.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/required.js"],"names":[],"mappings":"AAEA;IACE,4BAGC;IADC,aAAqC;IAGvC;;;MAOC;CACF;gCAhB+B,QAAQ"}
@@ -1,14 +0,0 @@
1
- import BaseValidationError from './base.js';
2
- export default class RequiredValidationError extends BaseValidationError {
3
- constructor(...args) {
4
- super(...args);
5
- this.name = 'RequiredValidationError';
6
- }
7
- getError() {
8
- const { message } = this.options;
9
- return {
10
- message: `${message}`,
11
- path: this.instancePath,
12
- };
13
- }
14
- }
@@ -1,10 +0,0 @@
1
- export default class UnevaluatedPropValidationError extends BaseValidationError {
2
- constructor(...args: any[]);
3
- name: string;
4
- getError(): {
5
- message: string;
6
- path: string;
7
- };
8
- }
9
- import BaseValidationError from './base.js';
10
- //# sourceMappingURL=unevaluated-prop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unevaluated-prop.d.ts","sourceRoot":"","sources":["../../../../src/utils/betterAjvErrors/validation-errors/unevaluated-prop.js"],"names":[],"mappings":"AAEA;IACE,4BAIC;IAFC,aAA4C;IAI9C;;;MAOC;CACF;gCAjB+B,QAAQ"}
@@ -1,15 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import type { AnyObject } from '../types/index.js';
2
- /**
3
- * Transforms ajv errors, finds the positions in the schema and returns an enriched format.
4
- */
5
- export declare function transformErrors(specification: AnyObject, errors: any): any;
6
- //# sourceMappingURL=transform-errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-errors.d.ts","sourceRoot":"","sources":["../../src/utils/transform-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAI9C;;GAEG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAkEpE"}