@stoplight/spectral-core 1.12.4 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ruleset/alias.d.ts +3 -0
- package/dist/ruleset/alias.js +61 -0
- package/dist/ruleset/alias.js.map +1 -0
- package/dist/ruleset/function.d.ts +4 -3
- package/dist/ruleset/function.js +43 -39
- package/dist/ruleset/function.js.map +1 -1
- package/dist/ruleset/mergers/rules.js +1 -1
- package/dist/ruleset/mergers/rules.js.map +1 -1
- package/dist/ruleset/meta/js-extensions.json +2 -2
- package/dist/ruleset/meta/rule.schema.json +63 -57
- package/dist/ruleset/meta/shared.json +20 -3
- package/dist/ruleset/rule.js +9 -55
- package/dist/ruleset/rule.js.map +1 -1
- package/dist/ruleset/utils/guards.d.ts +4 -2
- package/dist/ruleset/utils/guards.js +16 -2
- package/dist/ruleset/utils/guards.js.map +1 -1
- package/dist/ruleset/validation/ajv.js +30 -8
- package/dist/ruleset/validation/ajv.js.map +1 -1
- package/dist/ruleset/validation/assertions.d.ts +1 -2
- package/dist/ruleset/validation/assertions.js +10 -9
- package/dist/ruleset/validation/assertions.js.map +1 -1
- package/dist/ruleset/validation/errors.d.ts +8 -9
- package/dist/ruleset/validation/errors.js +47 -42
- package/dist/ruleset/validation/errors.js.map +1 -1
- package/dist/ruleset/validation/validators/alias.d.ts +4 -0
- package/dist/ruleset/validation/validators/alias.js +37 -0
- package/dist/ruleset/validation/validators/alias.js.map +1 -0
- package/dist/ruleset/validation/validators/common/error.d.ts +1 -0
- package/dist/ruleset/validation/validators/common/error.js +24 -0
- package/dist/ruleset/validation/validators/common/error.js.map +1 -0
- package/dist/ruleset/validation/validators/function.d.ts +2 -0
- package/dist/ruleset/validation/validators/function.js +23 -0
- package/dist/ruleset/validation/validators/function.js.map +1 -0
- package/dist/types/function.d.ts +2 -2
- package/dist/utils/replacer.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RulesetScopedAliasDefinition } from './types';
|
|
2
|
+
export declare function resolveAliasForFormats({ targets }: RulesetScopedAliasDefinition, formats: Set<unknown> | null): string[] | null;
|
|
3
|
+
export declare function resolveAlias(aliases: Record<string, unknown> | null, expression: string, formats: Set<unknown> | null): string[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAlias = exports.resolveAliasForFormats = void 0;
|
|
4
|
+
const guards_1 = require("./utils/guards");
|
|
5
|
+
const ALIAS = /^#([A-Za-z0-9_-]+)/;
|
|
6
|
+
function resolveAliasForFormats({ targets }, formats) {
|
|
7
|
+
if (formats === null || formats.size === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
for (let i = targets.length - 1; i >= 0; i--) {
|
|
11
|
+
const target = targets[i];
|
|
12
|
+
for (const format of target.formats) {
|
|
13
|
+
if (formats.has(format)) {
|
|
14
|
+
return target.given;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
exports.resolveAliasForFormats = resolveAliasForFormats;
|
|
21
|
+
function resolveAlias(aliases, expression, formats) {
|
|
22
|
+
return _resolveAlias(aliases, expression, formats, new Set());
|
|
23
|
+
}
|
|
24
|
+
exports.resolveAlias = resolveAlias;
|
|
25
|
+
function _resolveAlias(aliases, expression, formats, stack) {
|
|
26
|
+
var _a;
|
|
27
|
+
const resolvedExpressions = [];
|
|
28
|
+
if (expression.startsWith('#')) {
|
|
29
|
+
const alias = (_a = ALIAS.exec(expression)) === null || _a === void 0 ? void 0 : _a[1];
|
|
30
|
+
if (alias === void 0 || alias === null) {
|
|
31
|
+
throw new ReferenceError(`Alias must match /^#([A-Za-z0-9_-]+)/`);
|
|
32
|
+
}
|
|
33
|
+
if (stack.has(alias)) {
|
|
34
|
+
const _stack = [...stack, alias];
|
|
35
|
+
throw new ReferenceError(`Alias "${_stack[0]}" is circular. Resolution stack: ${_stack.join(' -> ')}`);
|
|
36
|
+
}
|
|
37
|
+
stack.add(alias);
|
|
38
|
+
if (aliases === null || !(alias in aliases)) {
|
|
39
|
+
throw new ReferenceError(`Alias "${alias}" does not exist`);
|
|
40
|
+
}
|
|
41
|
+
const aliasValue = aliases[alias];
|
|
42
|
+
let actualAliasValue;
|
|
43
|
+
if ((0, guards_1.isSimpleAliasDefinition)(aliasValue)) {
|
|
44
|
+
actualAliasValue = aliasValue;
|
|
45
|
+
}
|
|
46
|
+
else if ((0, guards_1.isScopedAliasDefinition)(aliasValue)) {
|
|
47
|
+
actualAliasValue = resolveAliasForFormats(aliasValue, formats);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
actualAliasValue = null;
|
|
51
|
+
}
|
|
52
|
+
if (actualAliasValue !== null) {
|
|
53
|
+
resolvedExpressions.push(...actualAliasValue.flatMap(item => _resolveAlias(aliases, item + expression.slice(alias.length + 1), formats, new Set([...stack]))));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resolvedExpressions.push(expression);
|
|
58
|
+
}
|
|
59
|
+
return resolvedExpressions;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=alias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias.js","sourceRoot":"","sources":["../../src/ruleset/alias.ts"],"names":[],"mappings":";;;AAAA,2CAAkF;AAGlF,MAAM,KAAK,GAAG,oBAAoB,CAAC;AAEnC,SAAgB,sBAAsB,CACpC,EAAE,OAAO,EAAgC,EACzC,OAA4B;IAE5B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE;QAC1C,OAAO,IAAI,CAAC;KACb;IAGD,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE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AAU,KAAK,kBAAkB,CAAC,CAAC;SAC7D;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,gBAAiC,CAAC;QACtC,IAAI,IAAA,gCAAuB,EAAC,UAAU,CAAC,EAAE;YACvC,gBAAgB,GAAG,UAAU,CAAC;SAC/B;aAAM,IAAI,IAAA,gCAAuB,EAAC,UAAU,CAAC,EAAE;YAC9C,gBAAgB,GAAG,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SAChE;aAAM;YACL,gBAAgB,GAAG,IAAI,CAAC;SACzB;QAED,IAAI,gBAAgB,KAAK,IAAI,EAAE;YAC7B,mBAAmB,CAAC,IAAI,CACtB,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACjC,aAAa,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAChG,CACF,CAAC;SACH;KACF;SAAM;QACL,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACtC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ErrorObject } from 'ajv';
|
|
2
|
-
import { RulesetValidationError } from './validation';
|
|
2
|
+
import { RulesetValidationError } from './validation/index';
|
|
3
3
|
import { JSONSchema, RulesetFunction, RulesetFunctionWithValidator } from '../types';
|
|
4
4
|
export declare class RulesetFunctionValidationError extends RulesetValidationError {
|
|
5
|
-
constructor(fn: string,
|
|
5
|
+
constructor(fn: string, error: ErrorObject);
|
|
6
|
+
private static printMessage;
|
|
6
7
|
}
|
|
7
8
|
declare type SchemaKeyedFragmentKeyword = 'properties' | 'patternProperties' | 'definitions';
|
|
8
9
|
declare type SchemaFragmentKeyword = 'additionalItems' | 'propertyNames' | 'if' | 'then' | 'else' | 'not';
|
|
@@ -27,7 +28,7 @@ declare type Schema = ((Omit<JSONSchema, SchemaKeyedFragmentKeyword | SchemaFrag
|
|
|
27
28
|
dependencies?: SchemaDefinition | string[];
|
|
28
29
|
};
|
|
29
30
|
export declare type SchemaDefinition = Schema | boolean;
|
|
30
|
-
export declare function createRulesetFunction<I
|
|
31
|
+
export declare function createRulesetFunction<I, O>({ input, errorOnInvalidInput, options, }: {
|
|
31
32
|
input: Schema | null;
|
|
32
33
|
errorOnInvalidInput?: boolean;
|
|
33
34
|
options: Schema | null;
|
package/dist/ruleset/function.js
CHANGED
|
@@ -6,43 +6,46 @@ const ajv_1 = (0, tslib_1.__importDefault)(require("ajv"));
|
|
|
6
6
|
const ajv_formats_1 = (0, tslib_1.__importDefault)(require("ajv-formats"));
|
|
7
7
|
const ajv_errors_1 = (0, tslib_1.__importDefault)(require("ajv-errors"));
|
|
8
8
|
const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
9
|
-
const
|
|
9
|
+
const index_1 = require("./validation/index");
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const AggregateError = require("es-aggregate-error");
|
|
10
12
|
const ajv = new ajv_1.default({ allErrors: true, allowUnionTypes: true, strict: true, keywords: ['x-internal'] });
|
|
11
13
|
(0, ajv_errors_1.default)(ajv);
|
|
12
14
|
(0, ajv_formats_1.default)(ajv);
|
|
13
|
-
class RulesetFunctionValidationError extends
|
|
14
|
-
constructor(fn,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const values = error.params.allowedValues.map(spectral_runtime_1.printValue).join(', ');
|
|
39
|
-
return `"${fn}" function and its "${path}" option accepts only the following values: ${values}`;
|
|
40
|
-
}
|
|
41
|
-
default:
|
|
42
|
-
return error.message;
|
|
15
|
+
class RulesetFunctionValidationError extends index_1.RulesetValidationError {
|
|
16
|
+
constructor(fn, error) {
|
|
17
|
+
super(RulesetFunctionValidationError.printMessage(fn, error), error.instancePath.slice(1).split('/'));
|
|
18
|
+
}
|
|
19
|
+
static printMessage(fn, error) {
|
|
20
|
+
var _a;
|
|
21
|
+
switch (error.keyword) {
|
|
22
|
+
case 'type': {
|
|
23
|
+
const path = (0, spectral_runtime_1.printPath)(error.instancePath.slice(1).split('/'), spectral_runtime_1.PrintStyle.Dot);
|
|
24
|
+
const values = Array.isArray(error.params.type) ? error.params.type.join(', ') : String(error.params.type);
|
|
25
|
+
return `"${fn}" function and its "${path}" option accepts only the following types: ${values}`;
|
|
26
|
+
}
|
|
27
|
+
case 'required': {
|
|
28
|
+
const missingProperty = error.params.missingProperty;
|
|
29
|
+
const missingPropertyPath = error.instancePath === ''
|
|
30
|
+
? missingProperty
|
|
31
|
+
: (0, spectral_runtime_1.printPath)([...error.instancePath.slice(1).split('/'), missingProperty], spectral_runtime_1.PrintStyle.Dot);
|
|
32
|
+
return `"${fn}" function is missing "${missingPropertyPath}" option`;
|
|
33
|
+
}
|
|
34
|
+
case 'additionalProperties': {
|
|
35
|
+
const additionalProperty = error.params.additionalProperty;
|
|
36
|
+
const additionalPropertyPath = error.instancePath === ''
|
|
37
|
+
? additionalProperty
|
|
38
|
+
: (0, spectral_runtime_1.printPath)([...error.instancePath.slice(1).split('/'), additionalProperty], spectral_runtime_1.PrintStyle.Dot);
|
|
39
|
+
return `"${fn}" function does not support "${additionalPropertyPath}" option`;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
case 'enum': {
|
|
42
|
+
const path = (0, spectral_runtime_1.printPath)(error.instancePath.slice(1).split('/'), spectral_runtime_1.PrintStyle.Dot);
|
|
43
|
+
const values = error.params.allowedValues.map(spectral_runtime_1.printValue).join(', ');
|
|
44
|
+
return `"${fn}" function and its "${path}" option accepts only the following values: ${values}`;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
return (_a = error.message) !== null && _a !== void 0 ? _a : 'unknown error';
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
exports.RulesetFunctionValidationError = RulesetFunctionValidationError;
|
|
@@ -66,24 +69,25 @@ function createRulesetFunction({ input, errorOnInvalidInput = false, options, },
|
|
|
66
69
|
return fn(input, options, ...args);
|
|
67
70
|
};
|
|
68
71
|
Reflect.defineProperty(wrappedFn, 'name', { value: fn.name });
|
|
69
|
-
const validOpts = new
|
|
72
|
+
const validOpts = new WeakSet();
|
|
70
73
|
wrappedFn.validator = function (o) {
|
|
71
|
-
if (validOpts.has(o))
|
|
74
|
+
if ((0, lodash_1.isObject)(o) && validOpts.has(o))
|
|
72
75
|
return;
|
|
73
76
|
if (validateOptions(o)) {
|
|
74
|
-
|
|
77
|
+
if ((0, lodash_1.isObject)(o))
|
|
78
|
+
validOpts.add(o);
|
|
75
79
|
return;
|
|
76
80
|
}
|
|
77
81
|
if (options === null) {
|
|
78
|
-
throw new
|
|
82
|
+
throw new index_1.RulesetValidationError(`"${fn.name || '<unknown>'}" function does not accept any options`, []);
|
|
79
83
|
}
|
|
80
84
|
else if ('errors' in validateOptions &&
|
|
81
85
|
Array.isArray(validateOptions.errors) &&
|
|
82
86
|
validateOptions.errors.length > 0) {
|
|
83
|
-
throw new RulesetFunctionValidationError(fn.name || '<unknown>',
|
|
87
|
+
throw new AggregateError(validateOptions.errors.map(error => new RulesetFunctionValidationError(fn.name || '<unknown>', error)));
|
|
84
88
|
}
|
|
85
89
|
else {
|
|
86
|
-
throw new
|
|
90
|
+
throw new index_1.RulesetValidationError(`"functionOptions" of "${fn.name || '<unknown>'}" function must be valid`, []);
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
Reflect.defineProperty(wrappedFn, 'schemas', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/ruleset/function.ts"],"names":[],"mappings":";;;;AAAA,2DAAuC;AACvC,2EAAqC;AACrC,yEAAmC;AAMnC,kEAAgF;AAEhF,
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/ruleset/function.ts"],"names":[],"mappings":";;;;AAAA,2DAAuC;AACvC,2EAAqC;AACrC,yEAAmC;AAMnC,kEAAgF;AAEhF,8CAA4D;AAE5D,mCAAkC;AAClC,qDAAsD;AAEtD,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AACxG,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;AACf,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAC;AAEhB,MAAa,8BAA+B,SAAQ,8BAAsB;IACxE,YAAY,EAAU,EAAE,KAAkB;QACxC,KAAK,CAAC,8BAA8B,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACxG,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,EAAU,EAAE,KAAkB;;QACxD,QAAQ,KAAK,CAAC,OAAO,EAAE;YACrB,KAAK,MAAM,CAAC,CAAC;gBACX,MAAM,IAAI,GAAG,IAAA,4BAAS,EAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,6BAAU,CAAC,GAAG,CAAC,CAAC;gBAC/E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,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AC,CAAC;KACpC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAtCD,8BAsCC"}
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"Format": {
|
|
42
42
|
"$anchor": "format",
|
|
43
|
-
"spectral-runtime": "format",
|
|
43
|
+
"x-spectral-runtime": "format",
|
|
44
44
|
"errorMessage": "must be a valid format"
|
|
45
45
|
},
|
|
46
46
|
"Function": {
|
|
47
47
|
"$anchor": "function",
|
|
48
|
-
"spectral-runtime": "function",
|
|
48
|
+
"x-spectral-runtime": "ruleset-function",
|
|
49
49
|
"type": "object",
|
|
50
50
|
"properties": {
|
|
51
51
|
"function": true
|
|
@@ -21,72 +21,78 @@
|
|
|
21
21
|
"$ref": "shared#severity"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
"if": {
|
|
25
|
+
"type": "object"
|
|
26
|
+
},
|
|
27
|
+
"then": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"properties": {
|
|
30
|
+
"description": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"documentationUrl": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"format": "url",
|
|
36
|
+
"errorMessage": "must be a valid URL"
|
|
37
|
+
},
|
|
38
|
+
"recommended": {
|
|
39
|
+
"type": "boolean"
|
|
40
|
+
},
|
|
41
|
+
"given": {
|
|
42
|
+
"$ref": "shared#given"
|
|
43
|
+
},
|
|
44
|
+
"resolved": {
|
|
45
|
+
"type": "boolean"
|
|
46
|
+
},
|
|
47
|
+
"severity": {
|
|
48
|
+
"$ref": "#/$defs/Severity"
|
|
49
|
+
},
|
|
50
|
+
"message": {
|
|
51
|
+
"type": "string"
|
|
52
|
+
},
|
|
53
|
+
"tags": {
|
|
54
|
+
"items": {
|
|
48
55
|
"type": "string"
|
|
49
56
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
"type": "array"
|
|
58
|
+
},
|
|
59
|
+
"formats": {
|
|
60
|
+
"$ref": "shared#formats"
|
|
61
|
+
},
|
|
62
|
+
"then": {
|
|
63
|
+
"if": {
|
|
54
64
|
"type": "array"
|
|
55
65
|
},
|
|
56
|
-
"formats": {
|
|
57
|
-
"$ref": "shared#formats"
|
|
58
|
-
},
|
|
59
66
|
"then": {
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
"items": {
|
|
66
|
-
"$ref": "#/$defs/Then"
|
|
67
|
-
},
|
|
68
|
-
"type": "array"
|
|
69
|
-
}
|
|
70
|
-
]
|
|
67
|
+
"type": "array",
|
|
68
|
+
"items": {
|
|
69
|
+
"$ref": "#/$defs/Then"
|
|
70
|
+
}
|
|
71
71
|
},
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"type": "string",
|
|
75
|
-
"errorMessage": "allowed types are \"style\" and \"validation\""
|
|
72
|
+
"else": {
|
|
73
|
+
"$ref": "#/$defs/Then"
|
|
76
74
|
}
|
|
77
75
|
},
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"required": "the rule must have at least \"given\" and \"then\" properties"
|
|
76
|
+
"type": {
|
|
77
|
+
"enum": ["style", "validation"],
|
|
78
|
+
"type": "string",
|
|
79
|
+
"errorMessage": "allowed types are \"style\" and \"validation\""
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"type": "boolean"
|
|
82
|
+
"required": ["given", "then"],
|
|
83
|
+
"additionalProperties": false,
|
|
84
|
+
"errorMessage": {
|
|
85
|
+
"required": "the rule must have at least \"given\" and \"then\" properties"
|
|
90
86
|
}
|
|
91
|
-
|
|
87
|
+
},
|
|
88
|
+
"else": {
|
|
89
|
+
"oneOf": [
|
|
90
|
+
{
|
|
91
|
+
"$ref": "shared#/$defs/HumanReadableSeverity"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"type": "boolean"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
92
98
|
}
|
|
@@ -50,9 +50,26 @@
|
|
|
50
50
|
},
|
|
51
51
|
"PathExpression": {
|
|
52
52
|
"$id": "path-expression",
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
"if": {
|
|
54
|
+
"type": "string"
|
|
55
|
+
},
|
|
56
|
+
"then": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"if": {
|
|
59
|
+
"pattern": "^#"
|
|
60
|
+
},
|
|
61
|
+
"then": {
|
|
62
|
+
"x-spectral-runtime": "alias"
|
|
63
|
+
},
|
|
64
|
+
"else": {
|
|
65
|
+
"pattern": "^\\$",
|
|
66
|
+
"errorMessage": "must be a valid JSON Path expression or a reference to the existing Alias optionally paired with a JSON Path expression subset"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"else": {
|
|
70
|
+
"not": {},
|
|
71
|
+
"errorMessage": "must be a valid JSON Path expression or a reference to the existing Alias optionally paired with a JSON Path expression subset"
|
|
72
|
+
}
|
|
56
73
|
}
|
|
57
74
|
}
|
|
58
75
|
}
|
package/dist/ruleset/rule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var _Rule_severity, _Rule_enabled, _Rule_then, _Rule_given;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Rule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
@@ -10,11 +10,10 @@ const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
|
10
10
|
const severity_1 = require("./utils/severity");
|
|
11
11
|
const minimatch_1 = require("./utils/minimatch");
|
|
12
12
|
const formats_1 = require("./formats");
|
|
13
|
-
const
|
|
14
|
-
const ALIAS = /^#([A-Za-z0-9_-]+)/;
|
|
13
|
+
const alias_1 = require("./alias");
|
|
15
14
|
class Rule {
|
|
16
15
|
constructor(name, definition, owner) {
|
|
17
|
-
var _b, _c
|
|
16
|
+
var _a, _b, _c;
|
|
18
17
|
this.name = name;
|
|
19
18
|
this.definition = definition;
|
|
20
19
|
this.owner = owner;
|
|
@@ -24,9 +23,9 @@ class Rule {
|
|
|
24
23
|
_Rule_given.set(this, void 0);
|
|
25
24
|
this.recommended = definition.recommended !== false;
|
|
26
25
|
(0, tslib_1.__classPrivateFieldSet)(this, _Rule_enabled, this.recommended, "f");
|
|
27
|
-
this.description = (
|
|
28
|
-
this.message = (
|
|
29
|
-
this.documentationUrl = (
|
|
26
|
+
this.description = (_a = definition.description) !== null && _a !== void 0 ? _a : null;
|
|
27
|
+
this.message = (_b = definition.message) !== null && _b !== void 0 ? _b : null;
|
|
28
|
+
this.documentationUrl = (_c = definition.documentationUrl) !== null && _c !== void 0 ? _c : null;
|
|
30
29
|
this.severity = definition.severity;
|
|
31
30
|
this.resolved = definition.resolved !== false;
|
|
32
31
|
this.formats = 'formats' in definition ? new formats_1.Formats(definition.formats) : null;
|
|
@@ -90,11 +89,11 @@ class Rule {
|
|
|
90
89
|
const actualGiven = Array.isArray(given) ? given : [given];
|
|
91
90
|
(0, tslib_1.__classPrivateFieldSet)(this, _Rule_given, this.owner.hasComplexAliases
|
|
92
91
|
? actualGiven
|
|
93
|
-
: actualGiven.flatMap(expr => (0,
|
|
92
|
+
: actualGiven.flatMap(expr => (0, alias_1.resolveAlias)(this.owner.aliases, expr, null)).filter(lodash_1.isString), "f");
|
|
94
93
|
}
|
|
95
94
|
getGivenForFormats(formats) {
|
|
96
95
|
return this.owner.hasComplexAliases
|
|
97
|
-
? (0, tslib_1.__classPrivateFieldGet)(this, _Rule_given, "f").flatMap(expr => (0,
|
|
96
|
+
? (0, tslib_1.__classPrivateFieldGet)(this, _Rule_given, "f").flatMap(expr => (0, alias_1.resolveAlias)(this.owner.aliases, expr, formats))
|
|
98
97
|
: (0, tslib_1.__classPrivateFieldGet)(this, _Rule_given, "f");
|
|
99
98
|
}
|
|
100
99
|
matchesFormat(formats) {
|
|
@@ -136,50 +135,5 @@ class Rule {
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
exports.Rule = Rule;
|
|
139
|
-
|
|
140
|
-
var _b;
|
|
141
|
-
const resolvedExpressions = [];
|
|
142
|
-
if (expr.startsWith('#')) {
|
|
143
|
-
const alias = (_b = ALIAS.exec(expr)) === null || _b === void 0 ? void 0 : _b[1];
|
|
144
|
-
if (alias === void 0 || alias === null) {
|
|
145
|
-
throw new ReferenceError(`"${this.name}" rule references an invalid alias`);
|
|
146
|
-
}
|
|
147
|
-
if (stack.has(alias)) {
|
|
148
|
-
const _stack = [...stack, alias];
|
|
149
|
-
throw new ReferenceError(`Alias "${_stack[0]}" is circular. Resolution stack: ${_stack.join(' -> ')}`);
|
|
150
|
-
}
|
|
151
|
-
stack.add(alias);
|
|
152
|
-
if (aliases === null || !(alias in aliases)) {
|
|
153
|
-
throw new ReferenceError(`Alias "${alias}" does not exist`);
|
|
154
|
-
}
|
|
155
|
-
const aliasValue = aliases[alias];
|
|
156
|
-
let actualAliasValue;
|
|
157
|
-
if ((0, guards_1.isSimpleAliasDefinition)(aliasValue)) {
|
|
158
|
-
actualAliasValue = aliasValue;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
actualAliasValue = (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAliasForFormats).call(Rule, aliasValue, formats);
|
|
162
|
-
}
|
|
163
|
-
if (actualAliasValue !== null) {
|
|
164
|
-
resolvedExpressions.push(...actualAliasValue.flatMap(item => (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAlias).call(Rule, aliases, item + expr.slice(alias.length + 1), formats, new Set([...stack]))));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
resolvedExpressions.push(expr);
|
|
169
|
-
}
|
|
170
|
-
return resolvedExpressions;
|
|
171
|
-
}, _Rule_resolveAliasForFormats = function _Rule_resolveAliasForFormats({ targets }, formats) {
|
|
172
|
-
if (formats === null || formats.size === 0) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
for (let i = targets.length - 1; i >= 0; i--) {
|
|
176
|
-
const target = targets[i];
|
|
177
|
-
for (const format of target.formats) {
|
|
178
|
-
if (formats.has(format)) {
|
|
179
|
-
return target.given;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return null;
|
|
184
|
-
};
|
|
138
|
+
_Rule_severity = new WeakMap(), _Rule_enabled = new WeakMap(), _Rule_then = new WeakMap(), _Rule_given = new WeakMap();
|
|
185
139
|
//# sourceMappingURL=rule.js.map
|
package/dist/ruleset/rule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/ruleset/rule.ts"],"names":[],"mappings":";;;;;AAAA,mCAAkC;AAElC,0CAAoD;AACpD,0CAAgD;AAChD,kEAAyD;AAEzD,+CAAiF;
|
|
1
|
+
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/ruleset/rule.ts"],"names":[],"mappings":";;;;;AAAA,mCAAkC;AAElC,0CAAoD;AACpD,0CAAgD;AAChD,kEAAyD;AAEzD,+CAAiF;AAIjF,iDAA8C;AAC9C,uCAAoC;AACpC,mCAAuC;AAsBvC,MAAa,IAAI;IAYf,YACkB,IAAY,EACZ,UAA0B,EAC1B,KAAc;;QAFd,SAA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AAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;YAC7F,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;SACrB,CAAC;IACJ,CAAC;CACF;AAxJD,oBAwJC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { RulesetScopedAliasDefinition } from '../types';
|
|
2
|
-
export declare function isSimpleAliasDefinition(alias:
|
|
1
|
+
import type { RulesetScopedAliasDefinition } from '../types';
|
|
2
|
+
export declare function isSimpleAliasDefinition(alias: unknown): alias is string[];
|
|
3
|
+
export declare function isValidAliasTarget(target: Record<string, unknown>): target is RulesetScopedAliasDefinition['targets'][number];
|
|
4
|
+
export declare function isScopedAliasDefinition(alias: unknown): alias is RulesetScopedAliasDefinition;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSimpleAliasDefinition = void 0;
|
|
3
|
+
exports.isScopedAliasDefinition = exports.isValidAliasTarget = exports.isSimpleAliasDefinition = void 0;
|
|
4
|
+
const json_1 = require("@stoplight/json");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
4
6
|
function isSimpleAliasDefinition(alias) {
|
|
5
|
-
return
|
|
7
|
+
return Array.isArray(alias);
|
|
6
8
|
}
|
|
7
9
|
exports.isSimpleAliasDefinition = isSimpleAliasDefinition;
|
|
10
|
+
function isValidAliasTarget(target) {
|
|
11
|
+
const formats = target.formats;
|
|
12
|
+
if (!Array.isArray(formats) && !(formats instanceof Set)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return Array.isArray(target.given) && target.given.every(lodash_1.isString);
|
|
16
|
+
}
|
|
17
|
+
exports.isValidAliasTarget = isValidAliasTarget;
|
|
18
|
+
function isScopedAliasDefinition(alias) {
|
|
19
|
+
return (0, json_1.isPlainObject)(alias) && Array.isArray(alias.targets) && alias.targets.every(isValidAliasTarget);
|
|
20
|
+
}
|
|
21
|
+
exports.isScopedAliasDefinition = isScopedAliasDefinition;
|
|
8
22
|
//# sourceMappingURL=guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/ruleset/utils/guards.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/ruleset/utils/guards.ts"],"names":[],"mappings":";;;AAAA,0CAAgD;AAChD,mCAAkC;AAGlC,SAAgB,uBAAuB,CAAC,KAAc;IACpD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAFD,0DAEC;AAED,SAAgB,kBAAkB,CAChC,MAA+B;IAE/B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,YAAY,GAAG,CAAC,EAAE;QACxD,OAAO,KAAK,CAAC;KACd;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAQ,CAAC,CAAC;AACrE,CAAC;AATD,gDASC;AAED,SAAgB,uBAAuB,CAAC,KAAc;IACpD,OAAO,IAAA,oBAAa,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACzG,CAAC;AAFD,0DAEC"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createValidator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ajv_1 = (0, tslib_1.__importStar)(require("ajv"));
|
|
6
|
+
const names_1 = (0, tslib_1.__importDefault)(require("ajv/dist/compile/names"));
|
|
6
7
|
const ajv_formats_1 = (0, tslib_1.__importDefault)(require("ajv-formats"));
|
|
7
8
|
const ajv_errors_1 = (0, tslib_1.__importDefault)(require("ajv-errors"));
|
|
8
9
|
const ruleSchema = (0, tslib_1.__importStar)(require("../meta/rule.schema.json"));
|
|
@@ -10,7 +11,8 @@ const shared = (0, tslib_1.__importStar)(require("../meta/shared.json"));
|
|
|
10
11
|
const rulesetSchema = (0, tslib_1.__importStar)(require("../meta/ruleset.schema.json"));
|
|
11
12
|
const jsExtensions = (0, tslib_1.__importStar)(require("../meta/js-extensions.json"));
|
|
12
13
|
const jsonExtensions = (0, tslib_1.__importStar)(require("../meta/json-extensions.json"));
|
|
13
|
-
const
|
|
14
|
+
const alias_1 = require("./validators/alias");
|
|
15
|
+
const function_1 = require("./validators/function");
|
|
14
16
|
const validators = {
|
|
15
17
|
js: null,
|
|
16
18
|
json: null,
|
|
@@ -26,15 +28,21 @@ function createValidator(format) {
|
|
|
26
28
|
strictRequired: false,
|
|
27
29
|
keywords: ['$anchor'],
|
|
28
30
|
schemas: [ruleSchema, shared],
|
|
31
|
+
passContext: true,
|
|
29
32
|
});
|
|
30
33
|
(0, ajv_formats_1.default)(ajv);
|
|
31
34
|
(0, ajv_errors_1.default)(ajv);
|
|
32
35
|
ajv.addKeyword({
|
|
33
|
-
keyword: 'spectral-runtime',
|
|
36
|
+
keyword: 'x-spectral-runtime',
|
|
34
37
|
schemaType: 'string',
|
|
35
38
|
error: {
|
|
36
|
-
message(
|
|
37
|
-
|
|
39
|
+
message(cxt) {
|
|
40
|
+
var _a;
|
|
41
|
+
return (0, ajv_1._) `${((_a = cxt.params) === null || _a === void 0 ? void 0 : _a.message) !== void 0 ? cxt.params.message : ''}`;
|
|
42
|
+
},
|
|
43
|
+
params(cxt) {
|
|
44
|
+
var _a;
|
|
45
|
+
return (0, ajv_1._) `{ errors: ${((_a = cxt.params) === null || _a === void 0 ? void 0 : _a.errors) !== void 0 && cxt.params.errors} || [] }`;
|
|
38
46
|
},
|
|
39
47
|
},
|
|
40
48
|
code(cxt) {
|
|
@@ -43,10 +51,20 @@ function createValidator(format) {
|
|
|
43
51
|
case 'format':
|
|
44
52
|
cxt.fail((0, ajv_1._) `typeof ${data} !== "function"`);
|
|
45
53
|
break;
|
|
46
|
-
case 'ruleset-function':
|
|
47
|
-
cxt.
|
|
48
|
-
cxt.
|
|
54
|
+
case 'ruleset-function': {
|
|
55
|
+
const fn = cxt.gen.const('spectralFunction', (0, ajv_1._) `this.validateFunction(${data}.function, ${data}.functionOptions === void 0 ? null : ${data}.functionOptions, ${names_1.default.instancePath})`);
|
|
56
|
+
cxt.gen.if((0, ajv_1._) `${fn} !== void 0`);
|
|
57
|
+
cxt.error(false, { errors: fn });
|
|
58
|
+
cxt.gen.endIf();
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'alias': {
|
|
62
|
+
const alias = cxt.gen.const('spectralAlias', (0, ajv_1._) `this.validateAlias(${names_1.default.rootData}, ${data}, ${names_1.default.instancePath})`);
|
|
63
|
+
cxt.gen.if((0, ajv_1._) `${alias} !== void 0`);
|
|
64
|
+
cxt.error(false, { errors: alias });
|
|
65
|
+
cxt.gen.endIf();
|
|
49
66
|
break;
|
|
67
|
+
}
|
|
50
68
|
}
|
|
51
69
|
},
|
|
52
70
|
});
|
|
@@ -56,7 +74,11 @@ function createValidator(format) {
|
|
|
56
74
|
else {
|
|
57
75
|
ajv.addSchema(jsonExtensions);
|
|
58
76
|
}
|
|
59
|
-
const validator = ajv.compile(rulesetSchema)
|
|
77
|
+
const validator = new Proxy(ajv.compile(rulesetSchema), {
|
|
78
|
+
apply(target, thisArg, args) {
|
|
79
|
+
return Reflect.apply(target, { validateAlias: alias_1.validateAlias, validateFunction: function_1.validateFunction }, args);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
60
82
|
validators[format] = validator;
|
|
61
83
|
return validator;
|
|
62
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ajv.js","sourceRoot":"","sources":["../../../src/ruleset/validation/ajv.ts"],"names":[],"mappings":";;;;AAAA,wDAA+C;AAC/C,2EAAqC;AACrC,yEAAmC;AACnC,kFAAuD;AACvD,yEAA8C;AAC9C,wFAA6D;AAC7D,sFAA2D;AAC3D,0FAA+D;
|
|
1
|
+
{"version":3,"file":"ajv.js","sourceRoot":"","sources":["../../../src/ruleset/validation/ajv.ts"],"names":[],"mappings":";;;;AAAA,wDAA+C;AAC/C,gFAA2C;AAC3C,2EAAqC;AACrC,yEAAmC;AACnC,kFAAuD;AACvD,yEAA8C;AAC9C,wFAA6D;AAC7D,sFAA2D;AAC3D,0FAA+D;AAC/D,8CAAmD;AACnD,oDAAyD;AAEzD,MAAM,UAAU,GAAwD;IACtE,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,SAAgB,eAAe,CAAC,MAAqB;IACnD,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,iBAAiB,KAAK,IAAI,EAAE;QAC9B,OAAO,iBAAiB,CAAC;KAC1B;IAED,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC;QAClB,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,cAAc,EAAE,KAAK;QACrB,QAAQ,EAAE,CAAC,SAAS,CAAC;QACrB,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAC;IAChB,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;IACf,GAAG,CAAC,UAAU,CAAC;QACb,OAAO,EAAE,oBAAoB;QAC7B,UAAU,EAAE,QAAQ;QACpB,KAAK,EAAE;YACL,OAAO,CAAC,GAAG;;gBACT,OAAO,IAAA,OAAC,EAAA,GAAG,CAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,OAAO,MAAK,KAAK,CAAC,CAAC,CA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Aa,CAAC,CAAC;oBACnC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;oBACpC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;oBAChB,MAAM;iBACP;aACF;QACH,CAAC;KACF,CAAC,CAAC;IAEH,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;KAC7B;SAAM;QACL,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;KAC/B;IAED,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACtD,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAe;YACpC,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,aAAa,EAAb,qBAAa,EAAE,gBAAgB,EAAhB,2BAAgB,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1E,CAAC;KACF,CAAC,CAAC;IAEH,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC/B,OAAO,SAAS,CAAC;AACnB,CAAC;AAxED,0CAwEC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { FileRuleDefinition, RuleDefinition, RulesetDefinition } from '../types';
|
|
2
2
|
export declare function assertValidRuleset(ruleset: unknown, format?: 'js' | 'json'): asserts ruleset is RulesetDefinition;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function assertValidRule(rule: FileRuleDefinition): asserts rule is RuleDefinition;
|
|
3
|
+
export declare function assertValidRule(rule: FileRuleDefinition, name: string): asserts rule is RuleDefinition;
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertValidRule = exports.
|
|
3
|
+
exports.assertValidRule = exports.assertValidRuleset = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const json_1 = require("@stoplight/json");
|
|
5
6
|
const ajv_1 = require("./ajv");
|
|
6
7
|
const errors_1 = require("./errors");
|
|
8
|
+
const es_aggregate_error_1 = (0, tslib_1.__importDefault)(require("es-aggregate-error"));
|
|
7
9
|
function assertValidRuleset(ruleset, format = 'js') {
|
|
8
10
|
var _a;
|
|
9
11
|
if (!(0, json_1.isPlainObject)(ruleset)) {
|
|
10
|
-
throw new
|
|
12
|
+
throw new errors_1.RulesetValidationError('Provided ruleset is not an object', []);
|
|
11
13
|
}
|
|
12
14
|
if (!('rules' in ruleset) && !('extends' in ruleset) && !('overrides' in ruleset)) {
|
|
13
|
-
throw new errors_1.RulesetValidationError('Ruleset must have rules or extends or overrides defined');
|
|
15
|
+
throw new errors_1.RulesetValidationError('Ruleset must have rules or extends or overrides defined', []);
|
|
14
16
|
}
|
|
15
17
|
const validate = (0, ajv_1.createValidator)(format);
|
|
16
18
|
if (!validate(ruleset)) {
|
|
17
|
-
throw new
|
|
19
|
+
throw new es_aggregate_error_1.default((0, errors_1.convertAjvErrors)((_a = validate.errors) !== null && _a !== void 0 ? _a : []));
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
exports.assertValidRuleset = assertValidRuleset;
|
|
21
|
-
function
|
|
23
|
+
function isRuleDefinition(rule) {
|
|
22
24
|
return typeof rule === 'object' && rule !== null && !Array.isArray(rule) && ('given' in rule || 'then' in rule);
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
throw new TypeError('Invalid rule');
|
|
26
|
+
function assertValidRule(rule, name) {
|
|
27
|
+
if (!isRuleDefinition(rule)) {
|
|
28
|
+
throw new errors_1.RulesetValidationError('Rule definition expected', ['rules', name]);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
exports.assertValidRule = assertValidRule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/ruleset/validation/assertions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/ruleset/validation/assertions.ts"],"names":[],"mappings":";;;;AAAA,0CAAgD;AAChD,+BAAwC;AACxC,qCAAoE;AAEpE,yFAAgD;AAEhD,SAAgB,kBAAkB,CAChC,OAAgB,EAChB,SAAwB,IAAI;;IAE5B,IAAI,CAAC,IAAA,oBAAa,EAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,+BAAsB,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;KAC3E;IAED,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,EAAE;QACjF,MAAM,IAAI,+BAAsB,CAAC,yDAAyD,EAAE,EAAE,CAAC,CAAC;KACjG;IAED,MAAM,QAAQ,GAAG,IAAA,qBAAe,EAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACtB,MAAM,IAAI,4BAAc,CAAC,IAAA,yBAAgB,EAAC,MAAA,QAAQ,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,CAAC;KACnE;AACH,CAAC;AAjBD,gDAiBC;AAED,SAAS,gBAAgB,CAAC,IAAwB;IAChD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,CAAC,CAAC;AAClH,CAAC;AAED,SAAgB,eAAe,CAAC,IAAwB,EAAE,IAAY;IACpE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE;QAC3B,MAAM,IAAI,+BAAsB,CAAC,0BAA0B,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;KAC/E;AACH,CAAC;AAJD,0CAIC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ErrorObject } from 'ajv';
|
|
2
|
-
|
|
1
|
+
import type { ErrorObject } from 'ajv';
|
|
2
|
+
import type { IDiagnostic, JsonPath } from '@stoplight/types';
|
|
3
|
+
declare type RulesetValidationSingleError = Pick<IDiagnostic, 'message' | 'path'>;
|
|
4
|
+
export declare class RulesetValidationError extends Error implements RulesetValidationSingleError {
|
|
3
5
|
readonly message: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare class RulesetAjvValidationError extends RulesetValidationError {
|
|
7
|
-
ruleset: Record<string, unknown>;
|
|
8
|
-
errors: ErrorObject[];
|
|
9
|
-
constructor(ruleset: Record<string, unknown>, errors: ErrorObject[]);
|
|
10
|
-
static serializeAjvErrors(ruleset: Record<string, unknown>, errors: ErrorObject[]): string;
|
|
6
|
+
readonly path: JsonPath;
|
|
7
|
+
constructor(message: string, path: JsonPath);
|
|
11
8
|
}
|
|
9
|
+
export declare function convertAjvErrors(errors: ErrorObject[]): RulesetValidationError[];
|
|
10
|
+
export {};
|
|
@@ -1,59 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.convertAjvErrors = exports.RulesetValidationError = void 0;
|
|
4
|
+
const isAggregateError_1 = require("../../guards/isAggregateError");
|
|
5
5
|
class RulesetValidationError extends Error {
|
|
6
|
-
constructor(message) {
|
|
6
|
+
constructor(message, path) {
|
|
7
7
|
super(message);
|
|
8
8
|
this.message = message;
|
|
9
|
+
this.path = path;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
exports.RulesetValidationError = RulesetValidationError;
|
|
12
13
|
const RULE_INSTANCE_PATH = /^\/rules\/[^/]+/;
|
|
13
14
|
const GENERIC_INSTANCE_PATH = /^\/(?:aliases|extends|overrides(?:\/\d+\/extends)?)/;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
while (i + x < sortedErrors.length) {
|
|
34
|
-
if (sortedErrors[i + x].instancePath.startsWith(error.instancePath) ||
|
|
35
|
-
!GENERIC_INSTANCE_PATH.test(sortedErrors[i + x].instancePath)) {
|
|
36
|
-
continue l;
|
|
37
|
-
}
|
|
38
|
-
x++;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (prevError === null) {
|
|
42
|
-
filteredErrors.push(error);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const match = RULE_INSTANCE_PATH.exec(error.instancePath);
|
|
47
|
-
if (match !== null && match[0] !== match.input && match[0] === prevError.instancePath) {
|
|
48
|
-
filteredErrors.pop();
|
|
15
|
+
function convertAjvErrors(errors) {
|
|
16
|
+
const sortedErrors = [...errors]
|
|
17
|
+
.sort((errorA, errorB) => {
|
|
18
|
+
const diff = errorA.instancePath.length - errorB.instancePath.length;
|
|
19
|
+
return diff === 0 ? (errorA.keyword === 'errorMessage' && errorB.keyword !== 'errorMessage' ? -1 : 0) : diff;
|
|
20
|
+
})
|
|
21
|
+
.filter((error, i, sortedErrors) => i === 0 || sortedErrors[i - 1].instancePath !== error.instancePath);
|
|
22
|
+
const filteredErrors = [];
|
|
23
|
+
l: for (let i = 0; i < sortedErrors.length; i++) {
|
|
24
|
+
const error = sortedErrors[i];
|
|
25
|
+
const prevError = filteredErrors.length === 0 ? null : filteredErrors[filteredErrors.length - 1];
|
|
26
|
+
if (error.keyword === 'if')
|
|
27
|
+
continue;
|
|
28
|
+
if (GENERIC_INSTANCE_PATH.test(error.instancePath)) {
|
|
29
|
+
let x = 1;
|
|
30
|
+
while (i + x < sortedErrors.length) {
|
|
31
|
+
if (sortedErrors[i + x].instancePath.startsWith(error.instancePath) ||
|
|
32
|
+
!GENERIC_INSTANCE_PATH.test(sortedErrors[i + x].instancePath)) {
|
|
33
|
+
continue l;
|
|
49
34
|
}
|
|
35
|
+
x++;
|
|
50
36
|
}
|
|
37
|
+
}
|
|
38
|
+
else if (prevError === null) {
|
|
51
39
|
filteredErrors.push(error);
|
|
40
|
+
continue;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.
|
|
42
|
+
else {
|
|
43
|
+
const match = RULE_INSTANCE_PATH.exec(error.instancePath);
|
|
44
|
+
if (match !== null && match[0] !== match.input && match[0] === prevError.instancePath) {
|
|
45
|
+
filteredErrors.pop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
filteredErrors.push(error);
|
|
49
|
+
}
|
|
50
|
+
return filteredErrors.flatMap(error => {
|
|
51
|
+
var _a;
|
|
52
|
+
return error.keyword === 'x-spectral-runtime'
|
|
53
|
+
? flatErrors(error.params.errors)
|
|
54
|
+
: new RulesetValidationError((_a = error.message) !== null && _a !== void 0 ? _a : 'unknown error', error.instancePath.slice(1).split('/'));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.convertAjvErrors = convertAjvErrors;
|
|
58
|
+
function flatErrors(error) {
|
|
59
|
+
if ((0, isAggregateError_1.isAggregateError)(error)) {
|
|
60
|
+
return error.errors.flatMap(flatErrors);
|
|
56
61
|
}
|
|
62
|
+
return error;
|
|
57
63
|
}
|
|
58
|
-
exports.RulesetAjvValidationError = RulesetAjvValidationError;
|
|
59
64
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/ruleset/validation/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/ruleset/validation/errors.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AO,mCAAI,eAAe,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;KAAA,CACzG,CAAC;AACJ,CAAC;AA/CD,4CA+CC;AAED,SAAS,UAAU,CAAC,KAA8C;IAChE,IAAI,IAAA,mCAAgB,EAAC,KAAK,CAAC,EAAE;QAC3B,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;KACzC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAlias = void 0;
|
|
4
|
+
const json_1 = require("@stoplight/json");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const alias_1 = require("../../alias");
|
|
7
|
+
const formats_1 = require("../../formats");
|
|
8
|
+
const error_1 = require("./common/error");
|
|
9
|
+
function getOverrides(overrides, key) {
|
|
10
|
+
if (!Array.isArray(overrides))
|
|
11
|
+
return null;
|
|
12
|
+
const index = Number(key);
|
|
13
|
+
if (Number.isNaN(index))
|
|
14
|
+
return null;
|
|
15
|
+
if (index < 0 && index >= overrides.length)
|
|
16
|
+
return null;
|
|
17
|
+
const actualOverrides = overrides[index];
|
|
18
|
+
return (0, json_1.isPlainObject)(actualOverrides) && (0, json_1.isPlainObject)(actualOverrides.aliases) ? actualOverrides.aliases : null;
|
|
19
|
+
}
|
|
20
|
+
function validateAlias(ruleset, alias, path) {
|
|
21
|
+
try {
|
|
22
|
+
const parsedPath = path.slice(1).split('/');
|
|
23
|
+
const formats = (0, lodash_1.get)(ruleset, [...parsedPath.slice(0, parsedPath.indexOf('rules') + 2), 'formats']);
|
|
24
|
+
const aliases = parsedPath[0] === 'overrides'
|
|
25
|
+
? {
|
|
26
|
+
...ruleset.aliases,
|
|
27
|
+
...getOverrides(ruleset.overrides, parsedPath[1]),
|
|
28
|
+
}
|
|
29
|
+
: ruleset.aliases;
|
|
30
|
+
(0, alias_1.resolveAlias)(aliases !== null && aliases !== void 0 ? aliases : null, alias, Array.isArray(formats) ? new formats_1.Formats(formats) : null);
|
|
31
|
+
}
|
|
32
|
+
catch (ex) {
|
|
33
|
+
return (0, error_1.wrapError)(ex, path);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.validateAlias = validateAlias;
|
|
37
|
+
//# sourceMappingURL=alias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias.js","sourceRoot":"","sources":["../../../../src/ruleset/validation/validators/alias.ts"],"names":[],"mappings":";;;AAAA,0CAAgD;AAChD,mCAA6B;AAC7B,uCAA2C;AAC3C,2CAAwC;AACxC,0CAA2C;AAE3C,SAAS,YAAY,CAAC,SAAkB,EAAE,GAAW;IACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAE3C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,SAAS,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAExD,MAAM,eAAe,GAAY,SAAS,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,IAAA,oBAAa,EAAC,eAAe,CAAC,IAAI,IAAA,oBAAa,EAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACnH,CAAC;AAED,SAAgB,aAAa,CAC3B,OAAmF,EACnF,KAAa,EACb,IAAY;IAEZ,IAAI;QACF,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAY,IAAA,YAAG,EAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;QAE5G,MAAM,OAAO,GACX,UAAU,CAAC,CAAC,CAAC,KAAK,WAAW;YAC3B,CAAC,CAAC;gBACE,GAAG,OAAO,CAAC,OAAO;gBAClB,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;aAClD;YACH,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QAEtB,IAAA,oBAAY,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KAC5F;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,IAAA,iBAAS,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC;KAC5B;AACH,CAAC;AArBD,sCAqBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wrapError(ex: unknown, path: string): Error;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const es_aggregate_error_1 = (0, tslib_1.__importDefault)(require("es-aggregate-error"));
|
|
7
|
+
const errors_1 = require("../../errors");
|
|
8
|
+
const isAggregateError_1 = require("../../../../guards/isAggregateError");
|
|
9
|
+
function toRulesetValidationError(ex) {
|
|
10
|
+
if (ex instanceof errors_1.RulesetValidationError) {
|
|
11
|
+
ex.path.unshift(...this);
|
|
12
|
+
return ex;
|
|
13
|
+
}
|
|
14
|
+
return new errors_1.RulesetValidationError((0, lodash_1.isError)(ex) ? ex.message : String(ex), [...this]);
|
|
15
|
+
}
|
|
16
|
+
function wrapError(ex, path) {
|
|
17
|
+
const parsedPath = path.slice(1).split('/');
|
|
18
|
+
if ((0, isAggregateError_1.isAggregateError)(ex)) {
|
|
19
|
+
return new es_aggregate_error_1.default(ex.errors.map(toRulesetValidationError, parsedPath));
|
|
20
|
+
}
|
|
21
|
+
return toRulesetValidationError.call(parsedPath, ex);
|
|
22
|
+
}
|
|
23
|
+
exports.wrapError = wrapError;
|
|
24
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../../src/ruleset/validation/validators/common/error.ts"],"names":[],"mappings":";;;;AAAA,mCAAiC;AACjC,yFAAgD;AAEhD,yCAAsD;AACtD,0EAAuE;AAEvE,SAAS,wBAAwB,CAA8B,EAAW;IACxE,IAAI,EAAE,YAAY,+BAAsB,EAAE;QACxC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,OAAO,EAAE,CAAC;KACX;IAED,OAAO,IAAI,+BAAsB,CAAC,IAAA,gBAAO,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAgB,SAAS,CAAC,EAAW,EAAE,IAAY;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE5C,IAAI,IAAA,mCAAgB,EAAC,EAAE,CAAC,EAAE;QACxB,OAAO,IAAI,4BAAc,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC,CAAC;KAChF;IAED,OAAO,wBAAwB,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC;AARD,8BAQC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFunction = void 0;
|
|
4
|
+
const error_1 = require("./common/error");
|
|
5
|
+
function assertRulesetFunction(maybeRulesetFunction) {
|
|
6
|
+
if (typeof maybeRulesetFunction !== 'function') {
|
|
7
|
+
throw Error('Function is not defined');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function validateFunction(fn, opts, path) {
|
|
11
|
+
try {
|
|
12
|
+
assertRulesetFunction(fn);
|
|
13
|
+
if (!('validator' in fn))
|
|
14
|
+
return;
|
|
15
|
+
const validator = fn.validator.bind(fn);
|
|
16
|
+
validator(opts);
|
|
17
|
+
}
|
|
18
|
+
catch (ex) {
|
|
19
|
+
return (0, error_1.wrapError)(ex, path);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.validateFunction = validateFunction;
|
|
23
|
+
//# sourceMappingURL=function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../../src/ruleset/validation/validators/function.ts"],"names":[],"mappings":";;;AACA,0CAA2C;AAE3C,SAAS,qBAAqB,CAC5B,oBAA6B;IAE7B,IAAI,OAAO,oBAAoB,KAAK,UAAU,EAAE;QAC9C,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAC;KACxC;AACH,CAAC;AAED,SAAgB,gBAAgB,CAC9B,EAA4D,EAC5D,IAAa,EACb,IAAY;IAEZ,IAAI;QACF,qBAAqB,CAAC,EAAE,CAAC,CAAC;QAE1B,IAAI,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC;YAAE,OAAO;QAEjC,MAAM,SAAS,GAA8C,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnF,SAAS,CAAC,IAAI,CAAC,CAAC;KACjB;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,IAAA,iBAAS,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC;KAC5B;AACH,CAAC;AAfD,4CAeC"}
|
package/dist/types/function.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { IDocumentInventory } from '../documentInventory';
|
|
|
3
3
|
import type { IRule } from '../ruleset/rule';
|
|
4
4
|
import type { IDocument } from '../document';
|
|
5
5
|
import type { JSONSchema7 } from 'json-schema';
|
|
6
|
-
export declare type RulesetFunction<I
|
|
6
|
+
export declare type RulesetFunction<I = unknown, O = unknown> = (input: I, options: O, context: RulesetFunctionContext) => void | IFunctionResult[] | Promise<void | IFunctionResult[]>;
|
|
7
7
|
export declare type RulesetFunctionContext = {
|
|
8
8
|
path: JsonPath;
|
|
9
9
|
document: IDocument;
|
|
@@ -11,7 +11,7 @@ export declare type RulesetFunctionContext = {
|
|
|
11
11
|
rule: IRule;
|
|
12
12
|
};
|
|
13
13
|
export declare type IFunction = RulesetFunction;
|
|
14
|
-
export declare type RulesetFunctionWithValidator<I
|
|
14
|
+
export declare type RulesetFunctionWithValidator<I = unknown, O = unknown> = RulesetFunction<I, O> & {
|
|
15
15
|
validator<O = unknown>(options: unknown): asserts options is O;
|
|
16
16
|
readonly schemas: Readonly<{
|
|
17
17
|
input: Readonly<JSONSchema7> | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replacer.js","sourceRoot":"","sources":["../../src/utils/replacer.ts"],"names":[],"mappings":";;;;AACA,
|
|
1
|
+
{"version":3,"file":"replacer.js","sourceRoot":"","sources":["../../src/utils/replacer.ts"],"names":[],"mappings":";;;;AACA,2EAAgC;AAIhC,MAAa,QAAQ;IAInB,YAAY,KAAa;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CA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": "https://github.com/stoplightio/spectral",
|
|
6
6
|
"bugs": "https://github.com/stoplightio/spectral/issues",
|
|
@@ -37,19 +37,21 @@
|
|
|
37
37
|
"release": "semantic-release -e semantic-release-monorepo"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stoplight/better-ajv-errors": "1.0.
|
|
41
|
-
"@stoplight/json": "~3.
|
|
40
|
+
"@stoplight/better-ajv-errors": "1.0.3",
|
|
41
|
+
"@stoplight/json": "~3.20.1",
|
|
42
42
|
"@stoplight/lifecycle": "2.3.2",
|
|
43
43
|
"@stoplight/path": "1.3.2",
|
|
44
44
|
"@stoplight/spectral-parsers": "^1.0.0",
|
|
45
45
|
"@stoplight/spectral-ref-resolver": "^1.0.0",
|
|
46
46
|
"@stoplight/spectral-runtime": "^1.0.0",
|
|
47
|
-
"@stoplight/types": "~13.
|
|
47
|
+
"@stoplight/types": "~13.6.0",
|
|
48
|
+
"@types/es-aggregate-error": "^1.0.2",
|
|
48
49
|
"@types/json-schema": "^7.0.11",
|
|
49
50
|
"ajv": "^8.6.0",
|
|
50
51
|
"ajv-errors": "~3.0.0",
|
|
51
52
|
"ajv-formats": "~2.1.0",
|
|
52
53
|
"blueimp-md5": "2.18.0",
|
|
54
|
+
"es-aggregate-error": "^1.0.7",
|
|
53
55
|
"jsonpath-plus": "6.0.1",
|
|
54
56
|
"lodash": "~4.17.21",
|
|
55
57
|
"lodash.topath": "^4.5.2",
|