@scalar/openapi-parser 0.7.1 → 0.7.2
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 +6 -0
- package/dist/{configuration.d.ts → configuration/index.d.ts} +8 -7
- package/dist/configuration/index.d.ts.map +1 -0
- package/dist/configuration/index.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/Validator/Validator.d.ts +6 -8
- package/dist/lib/Validator/Validator.d.ts.map +1 -0
- package/dist/lib/Validator/Validator.js +1 -0
- package/dist/lib/Validator/index.d.ts +3 -0
- package/dist/lib/Validator/index.d.ts.map +1 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/polyfills/index.d.ts +2 -0
- package/dist/polyfills/index.d.ts.map +1 -0
- package/dist/polyfills/path.d.ts +24 -0
- package/dist/polyfills/path.d.ts.map +1 -0
- package/dist/polyfills/path.js +1 -0
- package/dist/schemas/v2.0/schema.json.js +1 -1623
- package/dist/schemas/v3.0/schema.json.js +1 -1673
- package/dist/schemas/v3.1/schema.json.js +1 -1452
- package/dist/types/index.d.ts +23 -17
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/openapi-types.d.ts +7 -8
- package/dist/types/openapi-types.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/helpers.d.ts +7 -0
- package/dist/utils/betterAjvErrors/helpers.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/helpers.js +1 -0
- package/dist/utils/betterAjvErrors/index.d.ts +17 -0
- package/dist/utils/betterAjvErrors/index.d.ts.map +1 -0
- package/dist/utils/betterAjvErrors/index.js +1 -0
- package/dist/utils/betterAjvErrors/utils.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/base.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/default.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/enum.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/pattern.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/required.js +1 -0
- package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +1 -0
- package/dist/utils/dereference.d.ts +3 -5
- package/dist/utils/dereference.d.ts.map +1 -0
- package/dist/utils/dereference.js +1 -0
- package/dist/utils/details.d.ts +3 -5
- package/dist/utils/details.d.ts.map +1 -0
- package/dist/utils/details.js +1 -0
- package/dist/utils/escapeJsonPointer.d.ts +2 -3
- package/dist/utils/escapeJsonPointer.d.ts.map +1 -0
- package/dist/utils/escapeJsonPointer.js +1 -0
- package/dist/utils/filter.d.ts +3 -5
- package/dist/utils/filter.d.ts.map +1 -0
- package/dist/utils/filter.js +1 -0
- package/dist/utils/getEntrypoint.d.ts +3 -5
- package/dist/utils/getEntrypoint.d.ts.map +1 -0
- package/dist/utils/getEntrypoint.js +1 -0
- package/dist/utils/getListOfReferences.d.ts +3 -5
- package/dist/utils/getListOfReferences.d.ts.map +1 -0
- package/dist/utils/getListOfReferences.js +1 -0
- package/dist/utils/getSegmentsFromPath.d.ts +2 -3
- package/dist/utils/getSegmentsFromPath.d.ts.map +1 -0
- package/dist/utils/getSegmentsFromPath.js +1 -0
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/isFilesystem.d.ts +2 -3
- package/dist/utils/isFilesystem.d.ts.map +1 -0
- package/dist/utils/isFilesystem.js +1 -0
- package/dist/utils/isJson.d.ts +2 -3
- package/dist/utils/isJson.d.ts.map +1 -0
- package/dist/utils/isJson.js +1 -0
- package/dist/utils/isObject.d.ts +2 -3
- package/dist/utils/isObject.d.ts.map +1 -0
- package/dist/utils/isObject.js +1 -0
- package/dist/utils/isYaml.d.ts +2 -3
- package/dist/utils/isYaml.d.ts.map +1 -0
- package/dist/utils/isYaml.js +1 -0
- package/dist/utils/load/index.d.ts +2 -0
- package/dist/utils/load/index.d.ts.map +1 -0
- package/dist/utils/load/load.d.ts +4 -6
- package/dist/utils/load/load.d.ts.map +1 -0
- package/dist/utils/load/load.js +1 -0
- package/dist/{src/utils → utils}/load/plugins/fetchUrls.d.ts +4 -6
- package/dist/utils/load/plugins/fetchUrls.d.ts.map +1 -0
- package/dist/utils/load/plugins/fetchUrls.js +1 -0
- package/dist/utils/load/plugins/readFiles.d.ts +3 -0
- package/dist/utils/load/plugins/readFiles.d.ts.map +1 -0
- package/dist/utils/load/plugins/readFiles.js +1 -0
- package/dist/utils/makeFilesystem.d.ts +3 -0
- package/dist/utils/makeFilesystem.d.ts.map +1 -0
- package/dist/utils/makeFilesystem.js +1 -0
- package/dist/utils/normalize.d.ts +3 -5
- package/dist/utils/normalize.d.ts.map +1 -0
- package/dist/utils/normalize.js +1 -0
- package/dist/utils/openapi.d.ts +183 -0
- package/dist/utils/openapi.d.ts.map +1 -0
- package/dist/utils/openapi.js +1 -0
- package/dist/utils/resolveReferences.d.ts +5 -7
- package/dist/utils/resolveReferences.d.ts.map +1 -0
- package/dist/utils/resolveReferences.js +1 -0
- package/dist/utils/toJson.d.ts +3 -5
- package/dist/utils/toJson.d.ts.map +1 -0
- package/dist/utils/toJson.js +1 -0
- package/dist/utils/toYaml.d.ts +3 -5
- package/dist/utils/toYaml.d.ts.map +1 -0
- package/dist/utils/toYaml.js +1 -0
- package/dist/utils/transformErrors.d.ts +3 -5
- package/dist/utils/transformErrors.d.ts.map +1 -0
- package/dist/utils/transformErrors.js +1 -0
- package/dist/utils/traverse.d.ts +3 -5
- package/dist/utils/traverse.d.ts.map +1 -0
- package/dist/utils/traverse.js +1 -0
- package/dist/utils/unescapeJsonPointer.d.ts +2 -3
- package/dist/utils/unescapeJsonPointer.d.ts.map +1 -0
- package/dist/utils/unescapeJsonPointer.js +1 -0
- package/dist/utils/upgrade.d.ts +3 -5
- package/dist/utils/upgrade.d.ts.map +1 -0
- package/dist/utils/upgrade.js +1 -0
- package/dist/utils/upgradeFromThreeToThreeOne.d.ts +3 -5
- package/dist/utils/upgradeFromThreeToThreeOne.d.ts.map +1 -0
- package/dist/utils/upgradeFromThreeToThreeOne.js +1 -0
- package/dist/utils/upgradeFromTwoToThree.d.ts +3 -5
- package/dist/utils/upgradeFromTwoToThree.d.ts.map +1 -0
- package/dist/utils/upgradeFromTwoToThree.js +1 -0
- package/dist/utils/validate.d.ts +3 -5
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +1 -0
- package/dist/utils/workThroughQueue.d.ts +11 -0
- package/dist/utils/workThroughQueue.d.ts.map +1 -0
- package/dist/utils/workThroughQueue.js +1 -0
- package/package.json +19 -15
- package/dist/pipeline.d.ts +0 -388
- package/dist/src/configuration.js +0 -22
- package/dist/src/index.d.ts +0 -27
- package/dist/src/index.js +0 -25
- package/dist/src/lib/Validator/Validator.js +0 -94
- package/dist/src/pipeline.js +0 -121
- package/dist/src/polyfills/path.js +0 -80
- package/dist/src/utils/betterAjvErrors/helpers.js +0 -89
- package/dist/src/utils/betterAjvErrors/index.js +0 -15
- package/dist/src/utils/betterAjvErrors/utils.js +0 -17
- package/dist/src/utils/betterAjvErrors/validation-errors/additional-prop.js +0 -18
- package/dist/src/utils/betterAjvErrors/validation-errors/base.js +0 -23
- package/dist/src/utils/betterAjvErrors/validation-errors/default.js +0 -18
- package/dist/src/utils/betterAjvErrors/validation-errors/enum.js +0 -41
- package/dist/src/utils/betterAjvErrors/validation-errors/pattern.js +0 -18
- package/dist/src/utils/betterAjvErrors/validation-errors/required.js +0 -17
- package/dist/src/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +0 -18
- package/dist/src/utils/dereference.js +0 -18
- package/dist/src/utils/details.js +0 -22
- package/dist/src/utils/escapeJsonPointer.js +0 -5
- package/dist/src/utils/filter.js +0 -17
- package/dist/src/utils/getEntrypoint.js +0 -5
- package/dist/src/utils/getListOfReferences.js +0 -17
- package/dist/src/utils/getSegmentsFromPath.js +0 -10
- package/dist/src/utils/isFilesystem.js +0 -5
- package/dist/src/utils/isJson.js +0 -10
- package/dist/src/utils/isObject.js +0 -3
- package/dist/src/utils/isYaml.js +0 -17
- package/dist/src/utils/load/load.js +0 -59
- package/dist/src/utils/load/plugins/fetchUrls.js +0 -38
- package/dist/src/utils/load/plugins/readFiles.d.ts +0 -5
- package/dist/src/utils/load/plugins/readFiles.js +0 -50
- package/dist/src/utils/makeFilesystem.js +0 -22
- package/dist/src/utils/normalize.js +0 -20
- package/dist/src/utils/resolveReferences.js +0 -106
- package/dist/src/utils/toJson.js +0 -3
- package/dist/src/utils/toYaml.js +0 -5
- package/dist/src/utils/transformErrors.js +0 -19
- package/dist/src/utils/traverse.js +0 -20
- package/dist/src/utils/unescapeJsonPointer.js +0 -5
- package/dist/src/utils/upgrade.js +0 -19
- package/dist/src/utils/upgradeFromThreeToThreeOne.js +0 -70
- package/dist/src/utils/upgradeFromTwoToThree.js +0 -5
- package/dist/src/utils/validate.js +0 -15
- package/dist/src/utils/workThroughQueue.js +0 -24
- package/dist/webpack-stats.json +0 -1
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
function normalizeArray(parts, allowAboveRoot) {
|
|
2
|
-
var up = 0;
|
|
3
|
-
for (var i = parts.length - 1; i >= 0; i--) {
|
|
4
|
-
var last = parts[i];
|
|
5
|
-
if (last === ".") {
|
|
6
|
-
parts.splice(i, 1);
|
|
7
|
-
} else if (last === "..") {
|
|
8
|
-
parts.splice(i, 1);
|
|
9
|
-
up++;
|
|
10
|
-
} else if (up) {
|
|
11
|
-
parts.splice(i, 1);
|
|
12
|
-
up--;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (allowAboveRoot) {
|
|
16
|
-
for (; up--; up) {
|
|
17
|
-
parts.unshift("..");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return parts;
|
|
21
|
-
}
|
|
22
|
-
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
|
23
|
-
var splitPath = function(filename) {
|
|
24
|
-
return splitPathRe.exec(filename).slice(1);
|
|
25
|
-
};
|
|
26
|
-
function normalize(path) {
|
|
27
|
-
var isPathAbsolute = isAbsolute(path), trailingSlash = substr(path, -1) === "/";
|
|
28
|
-
path = normalizeArray(
|
|
29
|
-
filter(path.split("/"), function(p) {
|
|
30
|
-
return !!p;
|
|
31
|
-
}),
|
|
32
|
-
!isPathAbsolute
|
|
33
|
-
).join("/");
|
|
34
|
-
if (!path && !isPathAbsolute) {
|
|
35
|
-
path = ".";
|
|
36
|
-
}
|
|
37
|
-
if (path && trailingSlash) {
|
|
38
|
-
path += "/";
|
|
39
|
-
}
|
|
40
|
-
return (isPathAbsolute ? "/" : "") + path;
|
|
41
|
-
}
|
|
42
|
-
function isAbsolute(path) {
|
|
43
|
-
return path.charAt(0) === "/";
|
|
44
|
-
}
|
|
45
|
-
function join(...paths) {
|
|
46
|
-
return normalize(
|
|
47
|
-
filter(paths, function(p, index) {
|
|
48
|
-
if (typeof p !== "string") {
|
|
49
|
-
throw new TypeError("Arguments to path.join must be strings");
|
|
50
|
-
}
|
|
51
|
-
return p;
|
|
52
|
-
}).join("/")
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
function dirname(path) {
|
|
56
|
-
var result = splitPath(path), root = result[0], dir = result[1];
|
|
57
|
-
if (!root && !dir) {
|
|
58
|
-
return ".";
|
|
59
|
-
}
|
|
60
|
-
if (dir) {
|
|
61
|
-
dir = dir.substr(0, dir.length - 1);
|
|
62
|
-
}
|
|
63
|
-
return root + dir;
|
|
64
|
-
}
|
|
65
|
-
function filter(xs, f) {
|
|
66
|
-
if (xs.filter) return xs.filter(f);
|
|
67
|
-
var res = [];
|
|
68
|
-
for (var i = 0; i < xs.length; i++) {
|
|
69
|
-
if (f(xs[i], i, xs)) res.push(xs[i]);
|
|
70
|
-
}
|
|
71
|
-
return res;
|
|
72
|
-
}
|
|
73
|
-
var substr = "ab".substr(-1) === "b" ? function(str, start, len) {
|
|
74
|
-
return str.substr(start, len);
|
|
75
|
-
} : function(str, start, len) {
|
|
76
|
-
if (start < 0) start = str.length + start;
|
|
77
|
-
return str.substr(start, len);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export { dirname, isAbsolute, join, normalize };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { getErrors, isRequiredError, isAnyOfError, isEnumError, getSiblings, notUndefined, concatAll, getChildren } from './utils.js';
|
|
2
|
-
import EnumValidationError from './validation-errors/enum.js';
|
|
3
|
-
import DefaultValidationError from './validation-errors/default.js';
|
|
4
|
-
import UnevaluatedPropValidationError from './validation-errors/unevaluated-prop.js';
|
|
5
|
-
import RequiredValidationError from './validation-errors/required.js';
|
|
6
|
-
import PatternValidationError from './validation-errors/pattern.js';
|
|
7
|
-
import AdditionalPropValidationError from './validation-errors/additional-prop.js';
|
|
8
|
-
|
|
9
|
-
const JSON_POINTERS_REGEX = /\/[\w_-]+(\/\d+)?/g;
|
|
10
|
-
function makeTree(ajvErrors = []) {
|
|
11
|
-
const root = { children: {} };
|
|
12
|
-
ajvErrors.forEach((ajvError) => {
|
|
13
|
-
const instancePath = typeof ajvError.instancePath !== "undefined" ? ajvError.instancePath : ajvError.dataPath;
|
|
14
|
-
const paths = instancePath === "" ? [""] : instancePath.match(JSON_POINTERS_REGEX);
|
|
15
|
-
if (paths) {
|
|
16
|
-
paths.reduce((obj, path, i) => {
|
|
17
|
-
obj.children[path] = obj.children[path] || { children: {}, errors: [] };
|
|
18
|
-
if (i === paths.length - 1) {
|
|
19
|
-
obj.children[path].errors.push(ajvError);
|
|
20
|
-
}
|
|
21
|
-
return obj.children[path];
|
|
22
|
-
}, root);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return root;
|
|
26
|
-
}
|
|
27
|
-
function filterRedundantErrors(root, parent, key) {
|
|
28
|
-
getErrors(root).forEach((error) => {
|
|
29
|
-
if (isRequiredError(error)) {
|
|
30
|
-
root.errors = [error];
|
|
31
|
-
root.children = {};
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
if (getErrors(root).some(isAnyOfError)) {
|
|
35
|
-
if (Object.keys(root.children).length > 0) {
|
|
36
|
-
delete root.errors;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (root.errors && root.errors.length && getErrors(root).every(isEnumError)) {
|
|
40
|
-
if (getSiblings(parent)(root).filter(notUndefined).some(getErrors)) {
|
|
41
|
-
delete parent.children[key];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
Object.entries(root.children).forEach(
|
|
45
|
-
([k, child]) => filterRedundantErrors(child, root, k)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
function createErrorInstances(root, options) {
|
|
49
|
-
const errors = getErrors(root);
|
|
50
|
-
if (errors.length && errors.every(isEnumError)) {
|
|
51
|
-
const uniqueValues = new Set(
|
|
52
|
-
concatAll([])(errors.map((e) => e.params.allowedValues))
|
|
53
|
-
);
|
|
54
|
-
const allowedValues = [...uniqueValues];
|
|
55
|
-
const error = errors[0];
|
|
56
|
-
return [
|
|
57
|
-
new EnumValidationError(
|
|
58
|
-
{
|
|
59
|
-
...error,
|
|
60
|
-
params: { allowedValues }
|
|
61
|
-
},
|
|
62
|
-
options
|
|
63
|
-
)
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
return concatAll(
|
|
67
|
-
errors.reduce((ret, error) => {
|
|
68
|
-
switch (error.keyword) {
|
|
69
|
-
case "additionalProperties":
|
|
70
|
-
return ret.concat(new AdditionalPropValidationError(error, options));
|
|
71
|
-
case "pattern":
|
|
72
|
-
return ret.concat(new PatternValidationError(error, options));
|
|
73
|
-
case "required":
|
|
74
|
-
return ret.concat(new RequiredValidationError(error, options));
|
|
75
|
-
case "unevaluatedProperties":
|
|
76
|
-
return ret.concat(new UnevaluatedPropValidationError(error, options));
|
|
77
|
-
default:
|
|
78
|
-
return ret.concat(new DefaultValidationError(error, options));
|
|
79
|
-
}
|
|
80
|
-
}, [])
|
|
81
|
-
)(getChildren(root).map((child) => createErrorInstances(child, options)));
|
|
82
|
-
}
|
|
83
|
-
function prettify(ajvErrors, options) {
|
|
84
|
-
const tree = makeTree(ajvErrors || []);
|
|
85
|
-
filterRedundantErrors(tree);
|
|
86
|
-
return createErrorInstances(tree, options);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { createErrorInstances, prettify as default, filterRedundantErrors, makeTree };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import prettify from './helpers.js';
|
|
2
|
-
|
|
3
|
-
function betterAjvErrors(schema, data, errors, options = {}) {
|
|
4
|
-
const { indent = null, json = null } = options;
|
|
5
|
-
const jsonRaw = json || JSON.stringify(data, null, indent);
|
|
6
|
-
const customErrorToStructure = (error) => error.getError();
|
|
7
|
-
const customErrors = prettify(errors, {
|
|
8
|
-
data,
|
|
9
|
-
schema,
|
|
10
|
-
jsonRaw
|
|
11
|
-
});
|
|
12
|
-
return customErrors.map(customErrorToStructure);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { betterAjvErrors };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const eq = (x) => (y) => x === y;
|
|
2
|
-
const not = (fn) => (x) => !fn(x);
|
|
3
|
-
const getValues = (o) => Object.values(o);
|
|
4
|
-
const notUndefined = (x) => x !== void 0;
|
|
5
|
-
const isXError = (x) => (error) => error.keyword === x;
|
|
6
|
-
const isRequiredError = isXError("required");
|
|
7
|
-
const isAnyOfError = isXError("anyOf");
|
|
8
|
-
const isEnumError = isXError("enum");
|
|
9
|
-
const getErrors = (node) => node && node.errors || [];
|
|
10
|
-
const getChildren = (node) => node && getValues(node.children) || [];
|
|
11
|
-
const getSiblings = (parent) => (node) => getChildren(parent).filter(not(eq(node)));
|
|
12
|
-
const concatAll = (
|
|
13
|
-
/* ::<T> */
|
|
14
|
-
(xs) => (ys) => ys.reduce((zs, z) => zs.concat(z), xs)
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export { concatAll, getChildren, getErrors, getSiblings, isAnyOfError, isEnumError, isRequiredError, notUndefined };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import BaseValidationError from './base.js';
|
|
2
|
-
|
|
3
|
-
class AdditionalPropValidationError extends BaseValidationError {
|
|
4
|
-
constructor(...args) {
|
|
5
|
-
super(...args);
|
|
6
|
-
this.name = "AdditionalPropValidationError";
|
|
7
|
-
this.options.isIdentifierLocation = true;
|
|
8
|
-
}
|
|
9
|
-
getError() {
|
|
10
|
-
const { params } = this.options;
|
|
11
|
-
return {
|
|
12
|
-
message: `Property ${params.additionalProperty} is not expected to be here`,
|
|
13
|
-
path: this.instancePath
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { AdditionalPropValidationError as default };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
class BaseValidationError {
|
|
2
|
-
// eslint-disable-next-line default-param-last
|
|
3
|
-
constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {
|
|
4
|
-
this.options = options;
|
|
5
|
-
this.data = data;
|
|
6
|
-
this.schema = schema;
|
|
7
|
-
this.jsonAst = jsonAst;
|
|
8
|
-
this.jsonRaw = jsonRaw;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @return {string}
|
|
12
|
-
*/
|
|
13
|
-
get instancePath() {
|
|
14
|
-
return typeof this.options.instancePath !== "undefined" ? this.options.instancePath : this.options.dataPath;
|
|
15
|
-
}
|
|
16
|
-
getError() {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Implement the 'getError' method inside ${this.constructor.name}!`
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { BaseValidationError as default };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import BaseValidationError from './base.js';
|
|
2
|
-
|
|
3
|
-
class DefaultValidationError extends BaseValidationError {
|
|
4
|
-
constructor(...args) {
|
|
5
|
-
super(...args);
|
|
6
|
-
this.name = "DefaultValidationError";
|
|
7
|
-
this.options.isSkipEndLocation = true;
|
|
8
|
-
}
|
|
9
|
-
getError() {
|
|
10
|
-
const { keyword, message } = this.options;
|
|
11
|
-
return {
|
|
12
|
-
message: `${keyword} ${message}`,
|
|
13
|
-
path: this.instancePath
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { DefaultValidationError as default };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import pointer from 'jsonpointer';
|
|
2
|
-
import leven from 'leven';
|
|
3
|
-
import BaseValidationError from './base.js';
|
|
4
|
-
|
|
5
|
-
class EnumValidationError extends BaseValidationError {
|
|
6
|
-
constructor(...args) {
|
|
7
|
-
super(...args);
|
|
8
|
-
this.name = "EnumValidationError";
|
|
9
|
-
}
|
|
10
|
-
getError() {
|
|
11
|
-
const { message, params } = this.options;
|
|
12
|
-
const bestMatch = this.findBestMatch();
|
|
13
|
-
const allowedValues = params.allowedValues.join(", ");
|
|
14
|
-
const output = {
|
|
15
|
-
message: `${message}: ${allowedValues}`,
|
|
16
|
-
path: this.instancePath
|
|
17
|
-
};
|
|
18
|
-
if (bestMatch !== null) {
|
|
19
|
-
output.suggestion = `Did you mean ${bestMatch}?`;
|
|
20
|
-
}
|
|
21
|
-
return output;
|
|
22
|
-
}
|
|
23
|
-
findBestMatch() {
|
|
24
|
-
const {
|
|
25
|
-
params: { allowedValues }
|
|
26
|
-
} = this.options;
|
|
27
|
-
const currentValue = this.instancePath === "" ? this.data : pointer.get(this.data, this.instancePath);
|
|
28
|
-
if (!currentValue) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const bestMatch = allowedValues.map((value) => ({
|
|
32
|
-
value,
|
|
33
|
-
weight: leven(value, currentValue.toString())
|
|
34
|
-
})).sort(
|
|
35
|
-
(x, y) => x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0
|
|
36
|
-
)[0];
|
|
37
|
-
return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { EnumValidationError as default };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import BaseValidationError from './base.js';
|
|
2
|
-
|
|
3
|
-
class PatternValidationError extends BaseValidationError {
|
|
4
|
-
constructor(...args) {
|
|
5
|
-
super(...args);
|
|
6
|
-
this.name = "PatternValidationError";
|
|
7
|
-
this.options.isIdentifierLocation = true;
|
|
8
|
-
}
|
|
9
|
-
getError() {
|
|
10
|
-
const { params, propertyName } = this.options;
|
|
11
|
-
return {
|
|
12
|
-
message: `Property "${propertyName}" must match pattern ${params.pattern}`,
|
|
13
|
-
path: this.instancePath
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { PatternValidationError as default };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import BaseValidationError from './base.js';
|
|
2
|
-
|
|
3
|
-
class RequiredValidationError extends BaseValidationError {
|
|
4
|
-
constructor(...args) {
|
|
5
|
-
super(...args);
|
|
6
|
-
this.name = "RequiredValidationError";
|
|
7
|
-
}
|
|
8
|
-
getError() {
|
|
9
|
-
const { message } = this.options;
|
|
10
|
-
return {
|
|
11
|
-
message: `${message}`,
|
|
12
|
-
path: this.instancePath
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { RequiredValidationError as default };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import BaseValidationError from './base.js';
|
|
2
|
-
|
|
3
|
-
class UnevaluatedPropValidationError extends BaseValidationError {
|
|
4
|
-
constructor(...args) {
|
|
5
|
-
super(...args);
|
|
6
|
-
this.name = "UnevaluatedPropValidationError";
|
|
7
|
-
this.options.isIdentifierLocation = true;
|
|
8
|
-
}
|
|
9
|
-
getError() {
|
|
10
|
-
const { params } = this.options;
|
|
11
|
-
return {
|
|
12
|
-
message: `Property ${params.unevaluatedProperty} is not expected to be here`,
|
|
13
|
-
path: this.instancePath
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { UnevaluatedPropValidationError as default };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { details } from './details.js';
|
|
2
|
-
import { getEntrypoint } from './getEntrypoint.js';
|
|
3
|
-
import { makeFilesystem } from './makeFilesystem.js';
|
|
4
|
-
import { resolveReferences } from './resolveReferences.js';
|
|
5
|
-
|
|
6
|
-
async function dereference(value) {
|
|
7
|
-
const filesystem = makeFilesystem(value);
|
|
8
|
-
const entrypoint = getEntrypoint(filesystem);
|
|
9
|
-
const result = resolveReferences(filesystem);
|
|
10
|
-
return {
|
|
11
|
-
specification: entrypoint.specification,
|
|
12
|
-
errors: result.errors,
|
|
13
|
-
schema: result.schema,
|
|
14
|
-
...details(entrypoint.specification)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { dereference };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { OpenApiVersions } from '../configuration.js';
|
|
2
|
-
|
|
3
|
-
function details(specification) {
|
|
4
|
-
for (const version of new Set(OpenApiVersions)) {
|
|
5
|
-
const specificationType = version === "2.0" ? "swagger" : "openapi";
|
|
6
|
-
const value = specification[specificationType];
|
|
7
|
-
if (typeof value === "string" && value.startsWith(version)) {
|
|
8
|
-
return {
|
|
9
|
-
version,
|
|
10
|
-
specificationType,
|
|
11
|
-
specificationVersion: value
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
version: void 0,
|
|
17
|
-
specificationType: void 0,
|
|
18
|
-
specificationVersion: void 0
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { details };
|
package/dist/src/utils/filter.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getEntrypoint } from './getEntrypoint.js';
|
|
2
|
-
import { makeFilesystem } from './makeFilesystem.js';
|
|
3
|
-
import { traverse } from './traverse.js';
|
|
4
|
-
|
|
5
|
-
function filter(specification, callback) {
|
|
6
|
-
const filesystem = makeFilesystem(specification);
|
|
7
|
-
return {
|
|
8
|
-
specification: traverse(
|
|
9
|
-
getEntrypoint(filesystem).specification,
|
|
10
|
-
(schema) => {
|
|
11
|
-
return callback(schema) ? schema : void 0;
|
|
12
|
-
}
|
|
13
|
-
)
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { filter };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { traverse } from './traverse.js';
|
|
2
|
-
|
|
3
|
-
function getListOfReferences(specification) {
|
|
4
|
-
const references = [];
|
|
5
|
-
if (!specification || typeof specification !== "object") {
|
|
6
|
-
return references;
|
|
7
|
-
}
|
|
8
|
-
traverse(specification, (value) => {
|
|
9
|
-
if (value.$ref && typeof value.$ref === "string" && !value.$ref.startsWith("#")) {
|
|
10
|
-
references.push(value.$ref.split("#")[0]);
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
});
|
|
14
|
-
return [...new Set(references)];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { getListOfReferences };
|
package/dist/src/utils/isJson.js
DELETED
package/dist/src/utils/isYaml.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { parse } from 'yaml';
|
|
2
|
-
|
|
3
|
-
function isYaml(value) {
|
|
4
|
-
if (!value.includes("\n")) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
try {
|
|
8
|
-
parse(value, {
|
|
9
|
-
maxAliasCount: 1e4
|
|
10
|
-
});
|
|
11
|
-
return true;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { isYaml };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { getEntrypoint } from '../getEntrypoint.js';
|
|
2
|
-
import { getListOfReferences } from '../getListOfReferences.js';
|
|
3
|
-
import { makeFilesystem } from '../makeFilesystem.js';
|
|
4
|
-
import { normalize } from '../normalize.js';
|
|
5
|
-
|
|
6
|
-
async function load(value, options) {
|
|
7
|
-
if (options?.filesystem && options?.filesystem.find((entry) => entry.filename === value)) {
|
|
8
|
-
return {
|
|
9
|
-
filesystem: options.filesystem
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
const plugin = options?.plugins?.find((plugin2) => plugin2.check(value));
|
|
13
|
-
const content = normalize(plugin ? await plugin.get(value) : value);
|
|
14
|
-
if (content === void 0) {
|
|
15
|
-
return {
|
|
16
|
-
filesystem: []
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
let filesystem = makeFilesystem(content, {
|
|
20
|
-
filename: options?.filename ?? null
|
|
21
|
-
});
|
|
22
|
-
const newEntry = options?.filename ? filesystem.find((entry) => entry.filename === options?.filename) : getEntrypoint(filesystem);
|
|
23
|
-
const listOfReferences = newEntry.references ?? getListOfReferences(content);
|
|
24
|
-
if (listOfReferences.length === 0) {
|
|
25
|
-
return {
|
|
26
|
-
filesystem
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
for (const reference of listOfReferences) {
|
|
30
|
-
const plugin2 = options?.plugins?.find((plugin3) => plugin3.check(reference));
|
|
31
|
-
if (!plugin2) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const target = plugin2.check(reference) && plugin2.resolvePath ? plugin2.resolvePath(value, reference) : reference;
|
|
35
|
-
if (filesystem.find((entry) => entry.filename === reference)) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const { filesystem: referencedFiles } = await load(target, {
|
|
39
|
-
...options,
|
|
40
|
-
// Make the filename the exact same value as the $ref
|
|
41
|
-
// TODO: This leads to problems, if there are multiple references with the same file name but in different folders
|
|
42
|
-
filename: reference
|
|
43
|
-
});
|
|
44
|
-
filesystem = [
|
|
45
|
-
...filesystem,
|
|
46
|
-
...referencedFiles.map((file) => {
|
|
47
|
-
return {
|
|
48
|
-
...file,
|
|
49
|
-
isEntrypoint: false
|
|
50
|
-
};
|
|
51
|
-
})
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
filesystem
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { load };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const fetchUrlsDefaultConfiguration = {
|
|
2
|
-
limit: 20
|
|
3
|
-
};
|
|
4
|
-
const fetchUrls = (customConfiguration) => {
|
|
5
|
-
let numberOfRequests = 0;
|
|
6
|
-
const configuration = {
|
|
7
|
-
...fetchUrlsDefaultConfiguration,
|
|
8
|
-
...customConfiguration
|
|
9
|
-
};
|
|
10
|
-
return {
|
|
11
|
-
check(value) {
|
|
12
|
-
if (typeof value !== "string") {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (!value.startsWith("http://") && !value.startsWith("https://")) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
},
|
|
20
|
-
async get(value) {
|
|
21
|
-
if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {
|
|
22
|
-
console.warn(
|
|
23
|
-
`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`
|
|
24
|
-
);
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
numberOfRequests++;
|
|
29
|
-
const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value));
|
|
30
|
-
return await response.text();
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error("[fetchUrls]", error.message, `(${value})`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export { fetchUrls, fetchUrlsDefaultConfiguration };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { ERRORS } from '../../../configuration.js';
|
|
3
|
-
import { dirname, join } from '../../../polyfills/path.js';
|
|
4
|
-
import { isJson } from '../../isJson.js';
|
|
5
|
-
import { isYaml } from '../../isYaml.js';
|
|
6
|
-
|
|
7
|
-
const readFiles = () => {
|
|
8
|
-
return {
|
|
9
|
-
check(value) {
|
|
10
|
-
if (typeof value !== "string") {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (value.includes("\n")) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (isJson(value)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (isYaml(value)) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
},
|
|
27
|
-
async get(value) {
|
|
28
|
-
if (!fs.existsSync(value)) {
|
|
29
|
-
throw new Error(ERRORS.FILE_DOES_NOT_EXIST.replace("%s", value));
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
return fs.readFileSync(value, "utf-8");
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error("[readFiles]", error);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
resolvePath(value, reference) {
|
|
38
|
-
const dir = dirname(value);
|
|
39
|
-
return join(dir, reference);
|
|
40
|
-
},
|
|
41
|
-
getDir(value) {
|
|
42
|
-
return dirname(value);
|
|
43
|
-
},
|
|
44
|
-
getFilename(value) {
|
|
45
|
-
return value.split("/").pop();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { readFiles };
|