@scalar/openapi-parser 0.25.4 → 0.25.6

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 (140) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/configuration/index.js +24 -24
  3. package/dist/index.js +24 -45
  4. package/dist/lib/Validator/Validator.js +125 -108
  5. package/dist/plugins/fetch-urls/fetch-urls.js +39 -38
  6. package/dist/plugins/fetch-urls/index.js +1 -6
  7. package/dist/plugins/read-files/index.js +1 -5
  8. package/dist/plugins/read-files/read-files.js +53 -51
  9. package/dist/schemas/v2.0/schema.js +1373 -1377
  10. package/dist/schemas/v3.0/schema.js +1411 -1415
  11. package/dist/schemas/v3.1/schema.js +1196 -1200
  12. package/dist/schemas/v3.2/schema.js +1417 -1421
  13. package/dist/types/index.js +1 -1
  14. package/dist/utils/betterAjvErrors/helpers.js +138 -112
  15. package/dist/utils/betterAjvErrors/index.js +11 -15
  16. package/dist/utils/betterAjvErrors/utils.js +17 -30
  17. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +14 -18
  18. package/dist/utils/betterAjvErrors/validation-errors/base.js +20 -21
  19. package/dist/utils/betterAjvErrors/validation-errors/default.js +14 -18
  20. package/dist/utils/betterAjvErrors/validation-errors/enum.js +33 -37
  21. package/dist/utils/betterAjvErrors/validation-errors/index.js +6 -15
  22. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +14 -18
  23. package/dist/utils/betterAjvErrors/validation-errors/required.js +13 -17
  24. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +14 -18
  25. package/dist/utils/dereference.js +22 -18
  26. package/dist/utils/details.js +28 -29
  27. package/dist/utils/filter.js +13 -14
  28. package/dist/utils/get-entrypoint.js +5 -6
  29. package/dist/utils/get-list-of-references.js +20 -16
  30. package/dist/utils/get-segments-from-path.js +13 -9
  31. package/dist/utils/is-filesystem.js +8 -6
  32. package/dist/utils/is-json.js +8 -11
  33. package/dist/utils/is-yaml.js +15 -17
  34. package/dist/utils/join/index.js +1 -5
  35. package/dist/utils/join/join.js +267 -153
  36. package/dist/utils/join/merge-objects.js +35 -18
  37. package/dist/utils/load/index.js +1 -5
  38. package/dist/utils/load/load.js +114 -90
  39. package/dist/utils/make-filesystem.js +20 -21
  40. package/dist/utils/normalize.js +32 -29
  41. package/dist/utils/openapi/actions/details.js +9 -10
  42. package/dist/utils/openapi/actions/files.js +7 -8
  43. package/dist/utils/openapi/actions/get.js +9 -10
  44. package/dist/utils/openapi/actions/toJson.js +9 -10
  45. package/dist/utils/openapi/actions/toYaml.js +9 -10
  46. package/dist/utils/openapi/commands/dereferenceCommand.js +25 -26
  47. package/dist/utils/openapi/commands/filterCommand.js +24 -25
  48. package/dist/utils/openapi/commands/loadCommand.js +40 -41
  49. package/dist/utils/openapi/commands/upgradeCommand.js +27 -28
  50. package/dist/utils/openapi/commands/validateCommand.js +31 -32
  51. package/dist/utils/openapi/openapi.js +16 -14
  52. package/dist/utils/openapi/openapi.test-d.js +13 -13
  53. package/dist/utils/openapi/utils/queueTask.js +8 -9
  54. package/dist/utils/openapi/utils/workThroughQueue.js +64 -50
  55. package/dist/utils/resolve-references.js +168 -110
  56. package/dist/utils/to-json.js +1 -5
  57. package/dist/utils/to-yaml.js +2 -6
  58. package/dist/utils/transform/sanitize.js +22 -22
  59. package/dist/utils/transform/utils/addInfoObject.js +9 -14
  60. package/dist/utils/transform/utils/addLatestOpenApiVersion.js +4 -9
  61. package/dist/utils/transform/utils/addMissingTags.js +26 -27
  62. package/dist/utils/transform/utils/normalizeSecuritySchemes.js +39 -37
  63. package/dist/utils/transform/utils/rejectSwaggerDocuments.js +5 -9
  64. package/dist/utils/transform-errors.js +62 -55
  65. package/dist/utils/traverse.js +21 -22
  66. package/dist/utils/unescape-json-pointer.js +8 -6
  67. package/dist/utils/upgrade.js +19 -22
  68. package/dist/utils/validate-path-parameters.js +79 -80
  69. package/dist/utils/validate.js +23 -19
  70. package/package.json +9 -14
  71. package/dist/configuration/index.js.map +0 -7
  72. package/dist/declarations.d.js +0 -1
  73. package/dist/declarations.d.js.map +0 -7
  74. package/dist/index.js.map +0 -7
  75. package/dist/lib/Validator/Validator.js.map +0 -7
  76. package/dist/plugins/fetch-urls/fetch-urls.js.map +0 -7
  77. package/dist/plugins/fetch-urls/index.js.map +0 -7
  78. package/dist/plugins/read-files/index.js.map +0 -7
  79. package/dist/plugins/read-files/read-files.js.map +0 -7
  80. package/dist/schemas/v2.0/schema.js.map +0 -7
  81. package/dist/schemas/v3.0/schema.js.map +0 -7
  82. package/dist/schemas/v3.1/schema.js.map +0 -7
  83. package/dist/schemas/v3.2/schema.js.map +0 -7
  84. package/dist/types/index.js.map +0 -7
  85. package/dist/utils/betterAjvErrors/helpers.js.map +0 -7
  86. package/dist/utils/betterAjvErrors/index.js.map +0 -7
  87. package/dist/utils/betterAjvErrors/utils.js.map +0 -7
  88. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +0 -7
  89. package/dist/utils/betterAjvErrors/validation-errors/base.js.map +0 -7
  90. package/dist/utils/betterAjvErrors/validation-errors/default.js.map +0 -7
  91. package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +0 -7
  92. package/dist/utils/betterAjvErrors/validation-errors/index.js.map +0 -7
  93. package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +0 -7
  94. package/dist/utils/betterAjvErrors/validation-errors/required.js.map +0 -7
  95. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +0 -7
  96. package/dist/utils/dereference.js.map +0 -7
  97. package/dist/utils/details.js.map +0 -7
  98. package/dist/utils/filter.js.map +0 -7
  99. package/dist/utils/get-entrypoint.js.map +0 -7
  100. package/dist/utils/get-list-of-references.js.map +0 -7
  101. package/dist/utils/get-segments-from-path.js.map +0 -7
  102. package/dist/utils/is-filesystem.js.map +0 -7
  103. package/dist/utils/is-json.js.map +0 -7
  104. package/dist/utils/is-yaml.js.map +0 -7
  105. package/dist/utils/join/index.js.map +0 -7
  106. package/dist/utils/join/join.js.map +0 -7
  107. package/dist/utils/join/merge-objects.js.map +0 -7
  108. package/dist/utils/load/index.js.map +0 -7
  109. package/dist/utils/load/load.js.map +0 -7
  110. package/dist/utils/make-filesystem.js.map +0 -7
  111. package/dist/utils/normalize.js.map +0 -7
  112. package/dist/utils/openapi/actions/details.js.map +0 -7
  113. package/dist/utils/openapi/actions/files.js.map +0 -7
  114. package/dist/utils/openapi/actions/get.js.map +0 -7
  115. package/dist/utils/openapi/actions/toJson.js.map +0 -7
  116. package/dist/utils/openapi/actions/toYaml.js.map +0 -7
  117. package/dist/utils/openapi/commands/dereferenceCommand.js.map +0 -7
  118. package/dist/utils/openapi/commands/filterCommand.js.map +0 -7
  119. package/dist/utils/openapi/commands/loadCommand.js.map +0 -7
  120. package/dist/utils/openapi/commands/upgradeCommand.js.map +0 -7
  121. package/dist/utils/openapi/commands/validateCommand.js.map +0 -7
  122. package/dist/utils/openapi/openapi.js.map +0 -7
  123. package/dist/utils/openapi/openapi.test-d.js.map +0 -7
  124. package/dist/utils/openapi/utils/queueTask.js.map +0 -7
  125. package/dist/utils/openapi/utils/workThroughQueue.js.map +0 -7
  126. package/dist/utils/resolve-references.js.map +0 -7
  127. package/dist/utils/to-json.js.map +0 -7
  128. package/dist/utils/to-yaml.js.map +0 -7
  129. package/dist/utils/transform/sanitize.js.map +0 -7
  130. package/dist/utils/transform/utils/addInfoObject.js.map +0 -7
  131. package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +0 -7
  132. package/dist/utils/transform/utils/addMissingTags.js.map +0 -7
  133. package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +0 -7
  134. package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +0 -7
  135. package/dist/utils/transform-errors.js.map +0 -7
  136. package/dist/utils/traverse.js.map +0 -7
  137. package/dist/utils/unescape-json-pointer.js.map +0 -7
  138. package/dist/utils/upgrade.js.map +0 -7
  139. package/dist/utils/validate-path-parameters.js.map +0 -7
  140. package/dist/utils/validate.js.map +0 -7
@@ -1 +1 @@
1
- //# sourceMappingURL=index.js.map
1
+ export {};
@@ -1,125 +1,151 @@
1
- import {
2
- concatAll,
3
- getChildren,
4
- getErrors,
5
- getSiblings,
6
- isAdditionalPropertiesError,
7
- isAnyOfError,
8
- isEnumError,
9
- isIfError,
10
- isOneOfError,
11
- isRequiredError,
12
- isUnevaluatedPropertiesError,
13
- notUndefined
14
- } from "./utils.js";
15
- import {
16
- AdditionalPropValidationError,
17
- DefaultValidationError,
18
- EnumValidationError,
19
- PatternValidationError,
20
- RequiredValidationError,
21
- UnevaluatedPropValidationError
22
- } from "./validation-errors/index.js";
1
+ import { concatAll, getChildren, getErrors, getSiblings, isAdditionalPropertiesError, isAnyOfError, isEnumError, isIfError, isOneOfError, isRequiredError, isUnevaluatedPropertiesError, notUndefined, } from './utils.js';
2
+ import { AdditionalPropValidationError, DefaultValidationError, EnumValidationError, PatternValidationError, RequiredValidationError, UnevaluatedPropValidationError, } from './validation-errors/index.js';
23
3
  const JSON_POINTERS_REGEX = /\/[\w_-]+(\/\d+)?/g;
4
+ // Make a tree of errors from ajv errors array
24
5
  function makeTree(ajvErrors = []) {
25
- const root = { children: {} };
26
- ajvErrors.forEach((ajvError) => {
27
- const instancePath = typeof ajvError.instancePath !== "undefined" ? ajvError.instancePath : ajvError.dataPath;
28
- const paths = instancePath === "" ? [""] : instancePath.match(JSON_POINTERS_REGEX);
29
- if (paths) {
30
- paths.reduce((obj, path, i) => {
31
- obj.children[path] = obj.children[path] || { children: {}, errors: [] };
32
- if (i === paths.length - 1) {
33
- obj.children[path].errors.push(ajvError);
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);
34
19
  }
35
- return obj.children[path];
36
- }, root);
37
- }
38
- });
39
- return root;
20
+ });
21
+ return root;
40
22
  }
41
23
  function filterRedundantErrors(root, parent, key) {
42
- const errors = getErrors(root);
43
- const hasOneOfError = errors.some(isOneOfError);
44
- const hasAnyOfError = errors.some(isAnyOfError);
45
- const hasRequiredError = errors.some(isRequiredError);
46
- const hasIfError = errors.some(isIfError);
47
- const hasAdditionalPropertiesError = errors.some(isAdditionalPropertiesError);
48
- const hasUnevaluatedPropertiesError = errors.some(isUnevaluatedPropertiesError);
49
- const hasChildren = Object.keys(root.children || {}).length > 0;
50
- if (hasIfError && (hasAdditionalPropertiesError || hasUnevaluatedPropertiesError)) {
51
- root.errors = errors.filter((error) => !isIfError(error));
52
- }
53
- if (hasOneOfError && hasRequiredError) {
54
- if (hasAdditionalPropertiesError || hasUnevaluatedPropertiesError) {
55
- root.errors = errors.filter((error) => !isRequiredError(error) && !isOneOfError(error));
56
- } else if (hasChildren) {
57
- delete root.errors;
58
- } else {
59
- root.errors = errors.filter((error) => isOneOfError(error));
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
+ // No other errors, keep oneOf as it's all we have
56
+ root.errors = errors.filter((error) => isOneOfError(error));
57
+ }
58
+ }
59
+ else if (hasOneOfError && !hasRequiredError && hasChildren) {
60
+ /**
61
+ * If there is only a `oneOf` error (without required complications):
62
+ * If there are child errors, clear the oneOf error to surface the children.
63
+ * Children will have more specific information about why each branch failed.
64
+ */
65
+ // Clear the generic oneOf errors, let children surface
66
+ delete root.errors;
60
67
  }
61
- } else if (hasOneOfError && !hasRequiredError && hasChildren) {
62
- delete root.errors;
63
- } else if (hasOneOfError && !hasRequiredError && !hasChildren) {
64
- const oneOfErrors = errors.filter(isOneOfError);
65
- if (oneOfErrors.length > 1) {
66
- root.errors = [oneOfErrors[0]];
68
+ else if (hasOneOfError && !hasRequiredError && !hasChildren) {
69
+ /**
70
+ * If we have multiple oneOf errors (duplicates from different branches),
71
+ * keep only one to avoid noise.
72
+ */
73
+ const oneOfErrors = errors.filter(isOneOfError);
74
+ if (oneOfErrors.length > 1) {
75
+ // Keep only the first oneOf error
76
+ root.errors = [oneOfErrors[0]];
77
+ }
78
+ }
79
+ else if (hasRequiredError && !hasOneOfError) {
80
+ /**
81
+ * If there is a `required` error (without oneOf complications),
82
+ * then we can just skip everything else.
83
+ * And, also `required` should have more priority than `anyOf`. @see #8
84
+ */
85
+ root.errors = errors.filter(isRequiredError);
86
+ root.children = {};
67
87
  }
68
- } else if (hasRequiredError && !hasOneOfError) {
69
- root.errors = errors.filter(isRequiredError);
70
- root.children = {};
71
- }
72
- if (hasAnyOfError) {
73
- if (Object.keys(root.children).length > 0) {
74
- delete root.errors;
88
+ /**
89
+ * If there is an `anyOf` error that means we have more meaningful errors
90
+ * inside children. So we will just remove all errors from this level.
91
+ *
92
+ * If there are no children, then we don't delete the errors since we should
93
+ * have at least one error to report.
94
+ */
95
+ if (hasAnyOfError) {
96
+ if (Object.keys(root.children).length > 0) {
97
+ delete root.errors;
98
+ }
75
99
  }
76
- }
77
- if (root.errors?.length && getErrors(root).every(isEnumError)) {
78
- if (getSiblings(parent)(root).filter(notUndefined).some(getErrors)) {
79
- delete parent.children[key];
100
+ /**
101
+ * If all errors are `enum` and siblings have any error then we can safely
102
+ * ignore the node.
103
+ *
104
+ * **CAUTION**
105
+ * Need explicit `root.errors` check because `[].every(fn) === true`
106
+ * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics
107
+ */
108
+ if (root.errors?.length && getErrors(root).every(isEnumError)) {
109
+ if (getSiblings(parent)(root)
110
+ // Remove any reference which becomes `undefined` later
111
+ .filter(notUndefined)
112
+ .some(getErrors)) {
113
+ delete parent.children[key];
114
+ }
80
115
  }
81
- }
82
- Object.entries(root.children).forEach(([k, child]) => filterRedundantErrors(child, root, k));
116
+ Object.entries(root.children).forEach(([k, child]) => filterRedundantErrors(child, root, k));
83
117
  }
84
118
  function createErrorInstances(root, options) {
85
- const errors = getErrors(root);
86
- if (errors.length && errors.every(isEnumError)) {
87
- const uniqueValues = new Set(concatAll([])(errors.map((e) => e.params.allowedValues)));
88
- const allowedValues = [...uniqueValues];
89
- const error = errors[0];
90
- return [
91
- new EnumValidationError(
92
- {
93
- ...error,
94
- params: { allowedValues }
95
- },
96
- options
97
- )
98
- ];
99
- }
100
- return concatAll(
101
- errors.reduce((ret, error) => {
102
- switch (error.keyword) {
103
- case "additionalProperties":
104
- return ret.concat(new AdditionalPropValidationError(error, options));
105
- case "pattern":
106
- return ret.concat(new PatternValidationError(error, options));
107
- case "required":
108
- return ret.concat(new RequiredValidationError(error, options));
109
- case "unevaluatedProperties":
110
- return ret.concat(new UnevaluatedPropValidationError(error, options));
111
- default:
112
- return ret.concat(new DefaultValidationError(error, options));
113
- }
114
- }, [])
115
- )(getChildren(root).map((child) => createErrorInstances(child, options)));
119
+ const errors = getErrors(root);
120
+ if (errors.length && errors.every(isEnumError)) {
121
+ const uniqueValues = new Set(concatAll([])(errors.map((e) => e.params.allowedValues)));
122
+ const allowedValues = [...uniqueValues];
123
+ const error = errors[0];
124
+ return [
125
+ new EnumValidationError({
126
+ ...error,
127
+ params: { allowedValues },
128
+ }, options),
129
+ ];
130
+ }
131
+ return concatAll(errors.reduce((ret, error) => {
132
+ switch (error.keyword) {
133
+ case 'additionalProperties':
134
+ return ret.concat(new AdditionalPropValidationError(error, options));
135
+ case 'pattern':
136
+ return ret.concat(new PatternValidationError(error, options));
137
+ case 'required':
138
+ return ret.concat(new RequiredValidationError(error, options));
139
+ case 'unevaluatedProperties':
140
+ return ret.concat(new UnevaluatedPropValidationError(error, options));
141
+ default:
142
+ return ret.concat(new DefaultValidationError(error, options));
143
+ }
144
+ }, []))(getChildren(root).map((child) => createErrorInstances(child, options)));
116
145
  }
117
- function prettify(ajvErrors, options) {
118
- const tree = makeTree(ajvErrors || []);
119
- filterRedundantErrors(tree);
120
- return createErrorInstances(tree, options);
146
+ export default function prettify(ajvErrors, options) {
147
+ const tree = makeTree(ajvErrors || []);
148
+ // @ts-expect-error TODO
149
+ filterRedundantErrors(tree);
150
+ return createErrorInstances(tree, options);
121
151
  }
122
- export {
123
- prettify as default
124
- };
125
- //# sourceMappingURL=helpers.js.map
@@ -1,16 +1,12 @@
1
- import prettify from "./helpers.js";
2
- 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);
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
12
  }
13
- export {
14
- betterAjvErrors
15
- };
16
- //# sourceMappingURL=index.js.map
@@ -1,34 +1,21 @@
1
+ // Basic
1
2
  const eq = (x) => (y) => x === y;
2
3
  const not = (fn) => (x) => !fn(x);
3
4
  const getValues = (o) => Object.values(o);
4
- const notUndefined = (x) => x !== void 0;
5
+ export const notUndefined = (x) => x !== undefined;
6
+ // Error
5
7
  const isXError = (x) => (error) => error.keyword === x;
6
- const isRequiredError = isXError("required");
7
- const isAnyOfError = isXError("anyOf");
8
- const isOneOfError = isXError("oneOf");
9
- const isIfError = isXError("if");
10
- const isEnumError = isXError("enum");
11
- const isAdditionalPropertiesError = isXError("additionalProperties");
12
- const isUnevaluatedPropertiesError = isXError("unevaluatedProperties");
13
- const getErrors = (node) => node?.errors || [];
14
- const getChildren = (node) => node && getValues(node.children) || [];
15
- const getSiblings = (parent) => (node) => getChildren(parent).filter(not(eq(node)));
16
- const concatAll = (
17
- /* ::<T> */
18
- (xs) => (ys) => ys.reduce((zs, z) => zs.concat(z), xs)
19
- );
20
- export {
21
- concatAll,
22
- getChildren,
23
- getErrors,
24
- getSiblings,
25
- isAdditionalPropertiesError,
26
- isAnyOfError,
27
- isEnumError,
28
- isIfError,
29
- isOneOfError,
30
- isRequiredError,
31
- isUnevaluatedPropertiesError,
32
- notUndefined
33
- };
34
- //# sourceMappingURL=utils.js.map
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,19 +1,15 @@
1
- import BaseValidationError from "./base.js";
2
- 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
- }
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
15
  }
16
- export {
17
- AdditionalPropValidationError as default
18
- };
19
- //# sourceMappingURL=additional-prop.js.map
@@ -1,22 +1,21 @@
1
- class BaseValidationError {
2
- constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {
3
- this.options = options;
4
- this.data = data;
5
- this.schema = schema;
6
- this.jsonAst = jsonAst;
7
- this.jsonRaw = jsonRaw;
8
- }
9
- /**
10
- * @return {string}
11
- */
12
- get instancePath() {
13
- return typeof this.options.instancePath !== "undefined" ? this.options.instancePath : this.options.dataPath;
14
- }
15
- getError() {
16
- throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);
17
- }
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
+ }
18
21
  }
19
- export {
20
- BaseValidationError as default
21
- };
22
- //# sourceMappingURL=base.js.map
@@ -1,19 +1,15 @@
1
- import BaseValidationError from "./base.js";
2
- 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
- }
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
15
  }
16
- export {
17
- DefaultValidationError as default
18
- };
19
- //# sourceMappingURL=default.js.map
@@ -1,40 +1,36 @@
1
- import pointer from "jsonpointer";
2
- import leven from "leven";
3
- import BaseValidationError from "./base.js";
4
- 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}?`;
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';
19
8
  }
20
- return output;
21
- }
22
- findBestMatch() {
23
- const {
24
- params: { allowedValues }
25
- } = this.options;
26
- const currentValue = this.instancePath === "" ? this.data : pointer.get(this.data, this.instancePath);
27
- if (!currentValue) {
28
- return null;
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;
29
35
  }
30
- const bestMatch = allowedValues.map((value) => ({
31
- value,
32
- weight: leven(value, currentValue.toString())
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
36
  }
37
- export {
38
- EnumValidationError as default
39
- };
40
- //# sourceMappingURL=enum.js.map
@@ -1,15 +1,6 @@
1
- import { default as default2 } from "./additional-prop.js";
2
- import { default as default3 } from "./default.js";
3
- import { default as default4 } from "./enum.js";
4
- import { default as default5 } from "./pattern.js";
5
- import { default as default6 } from "./required.js";
6
- import { default as default7 } from "./unevaluated-prop.js";
7
- export {
8
- default2 as AdditionalPropValidationError,
9
- default3 as DefaultValidationError,
10
- default4 as EnumValidationError,
11
- default5 as PatternValidationError,
12
- default6 as RequiredValidationError,
13
- default7 as UnevaluatedPropValidationError
14
- };
15
- //# sourceMappingURL=index.js.map
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 PatternValidationError } from './pattern.js';
5
+ export { default as RequiredValidationError } from './required.js';
6
+ export { default as UnevaluatedPropValidationError } from './unevaluated-prop.js';
@@ -1,19 +1,15 @@
1
- import BaseValidationError from "./base.js";
2
- 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
- }
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
15
  }
16
- export {
17
- PatternValidationError as default
18
- };
19
- //# sourceMappingURL=pattern.js.map
@@ -1,18 +1,14 @@
1
- import BaseValidationError from "./base.js";
2
- 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
- }
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
14
  }
15
- export {
16
- RequiredValidationError as default
17
- };
18
- //# sourceMappingURL=required.js.map