@stoplight/spectral-core 1.10.2 → 1.12.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/index.d.ts +1 -1
- package/dist/ruleset/index.js +3 -3
- package/dist/ruleset/index.js.map +1 -1
- package/dist/ruleset/mergers/rules.js +2 -2
- package/dist/ruleset/mergers/rules.js.map +1 -1
- package/dist/ruleset/meta/js-extensions.json +64 -0
- package/dist/ruleset/meta/json-extensions.json +79 -0
- package/dist/{meta → ruleset/meta}/rule.schema.json +1 -3
- package/dist/{meta → ruleset/meta}/ruleset.schema.json +10 -33
- package/dist/{meta → ruleset/meta}/shared.json +1 -6
- package/dist/ruleset/validation/ajv.d.ts +2 -0
- package/dist/ruleset/validation/ajv.js +64 -0
- package/dist/ruleset/validation/ajv.js.map +1 -0
- package/dist/ruleset/{validation.d.ts → validation/assertions.d.ts} +2 -6
- package/dist/ruleset/validation/assertions.js +31 -0
- package/dist/ruleset/validation/assertions.js.map +1 -0
- package/dist/ruleset/validation/errors.d.ts +11 -0
- package/dist/ruleset/validation/errors.js +59 -0
- package/dist/ruleset/validation/errors.js.map +1 -0
- package/dist/ruleset/validation/index.d.ts +2 -0
- package/dist/ruleset/validation/index.js +8 -0
- package/dist/ruleset/validation/index.js.map +1 -0
- package/dist/runner/lintNode.js +13 -4
- package/dist/runner/lintNode.js.map +1 -1
- package/dist/runner/runner.js +1 -0
- package/dist/runner/runner.js.map +1 -1
- package/package.json +16 -4
- package/dist/ruleset/validation.js +0 -115
- package/dist/ruleset/validation.js.map +0 -1
package/dist/ruleset/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { assertValidRuleset, RulesetValidationError } from './validation';
|
|
1
|
+
export { assertValidRuleset, RulesetValidationError } from './validation/index';
|
|
2
2
|
export { getDiagnosticSeverity } from './utils';
|
|
3
3
|
export { createRulesetFunction, SchemaDefinition as RulesetFunctionSchemaDefinition } from './rulesetFunction';
|
|
4
4
|
export { Format } from './format';
|
package/dist/ruleset/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Rule = exports.Ruleset = exports.createRulesetFunction = exports.getDiagnosticSeverity = exports.RulesetValidationError = exports.assertValidRuleset = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "assertValidRuleset", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "RulesetValidationError", { enumerable: true, get: function () { return
|
|
4
|
+
var index_1 = require("./validation/index");
|
|
5
|
+
Object.defineProperty(exports, "assertValidRuleset", { enumerable: true, get: function () { return index_1.assertValidRuleset; } });
|
|
6
|
+
Object.defineProperty(exports, "RulesetValidationError", { enumerable: true, get: function () { return index_1.RulesetValidationError; } });
|
|
7
7
|
var utils_1 = require("./utils");
|
|
8
8
|
Object.defineProperty(exports, "getDiagnosticSeverity", { enumerable: true, get: function () { return utils_1.getDiagnosticSeverity; } });
|
|
9
9
|
var rulesetFunction_1 = require("./rulesetFunction");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ruleset/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ruleset/index.ts"],"names":[],"mappings":";;;AAAA,4CAAgF;AAAvE,2GAAA,kBAAkB,OAAA;AAAE,+GAAA,sBAAsB,OAAA;AACnD,iCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,qDAA+G;AAAtG,wHAAA,qBAAqB,OAAA;AAG9B,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,+BAA8B;AAArB,4FAAA,IAAI,OAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeRule = void 0;
|
|
4
|
-
const
|
|
4
|
+
const assertions_1 = require("../validation/assertions");
|
|
5
5
|
const rule_1 = require("../rule");
|
|
6
6
|
function assertExistingRule(maybeRule, name) {
|
|
7
7
|
if (maybeRule === void 0) {
|
|
@@ -30,7 +30,7 @@ function mergeRule(existingRule, name, rule, ruleset) {
|
|
|
30
30
|
Object.assign(existingRule, rule, { owner: existingRule.owner });
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
(0,
|
|
33
|
+
(0, assertions_1.assertValidRule)(rule);
|
|
34
34
|
return new rule_1.Rule(name, rule, ruleset);
|
|
35
35
|
}
|
|
36
36
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../src/ruleset/mergers/rules.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../src/ruleset/mergers/rules.ts"],"names":[],"mappings":";;;AACA,yDAA2D;AAC3D,kCAA+B;AAI/B,SAAS,kBAAkB,CAAC,SAAyB,EAAE,IAAY;IACjE,IAAI,SAAS,KAAK,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,cAAc,CAAC,qCAAqC,IAAI,GAAG,CAAC,CAAC;KACxE;AACH,CAAC;AAQD,SAAgB,SAAS,CACvB,YAA4B,EAC5B,IAAY,EACZ,IAAwB,EACxB,OAAgB;IAEhB,QAAQ,OAAO,IAAI,EAAE;QACnB,KAAK,SAAS;YACZ,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACvC,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;YAC5B,MAAM;QACR,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACvC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC7B,IAAI,IAAI,KAAK,KAAK,EAAE;gBAClB,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;aAC9B;iBAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;gBAChC,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;aAC7B;YACD,MAAM;QACR,KAAK,QAAQ;YACX,IAAI,YAAY,KAAK,KAAK,CAAC,EAAE;gBAC3B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC;aAClE;iBAAM;gBACL,IAAA,4BAAe,EAAC,IAAI,CAAC,CAAC;gBACtB,OAAO,IAAI,WAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;aACtC;YAED,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;KACpC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAnCD,8BAmCC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "@stoplight/spectral-core/meta/extensions",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"Extends": {
|
|
6
|
+
"$anchor": "extends",
|
|
7
|
+
"oneOf": [
|
|
8
|
+
{
|
|
9
|
+
"$id": "ruleset",
|
|
10
|
+
"$ref": "ruleset.schema#",
|
|
11
|
+
"errorMessage": "must be a valid ruleset"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "array",
|
|
15
|
+
"items": {
|
|
16
|
+
"anyOf": [
|
|
17
|
+
{
|
|
18
|
+
"$ref": "ruleset"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "array",
|
|
22
|
+
"minItems": 2,
|
|
23
|
+
"additionalItems": false,
|
|
24
|
+
"items": [
|
|
25
|
+
{
|
|
26
|
+
"$ref": "ruleset"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"type": "string",
|
|
30
|
+
"enum": ["off", "recommended", "all"],
|
|
31
|
+
"errorMessage": "allowed types are \"off\", \"recommended\" and \"all\""
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"errorMessage": "must be a valid ruleset"
|
|
40
|
+
},
|
|
41
|
+
"Format": {
|
|
42
|
+
"$anchor": "format",
|
|
43
|
+
"spectral-runtime": "format",
|
|
44
|
+
"errorMessage": "must be a valid format"
|
|
45
|
+
},
|
|
46
|
+
"Function": {
|
|
47
|
+
"$anchor": "function",
|
|
48
|
+
"spectral-runtime": "function",
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"function": true
|
|
52
|
+
},
|
|
53
|
+
"required": ["function"]
|
|
54
|
+
},
|
|
55
|
+
"Functions": {
|
|
56
|
+
"$anchor": "functions",
|
|
57
|
+
"not": {}
|
|
58
|
+
},
|
|
59
|
+
"FunctionsDir": {
|
|
60
|
+
"$anchor": "functionsDir",
|
|
61
|
+
"not": {}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "@stoplight/spectral-core/meta/extensions",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"Extends": {
|
|
6
|
+
"$anchor": "extends",
|
|
7
|
+
"oneOf": [
|
|
8
|
+
{
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": {
|
|
14
|
+
"oneOf": [
|
|
15
|
+
{
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"type": "array",
|
|
20
|
+
"minItems": 2,
|
|
21
|
+
"additionalItems": false,
|
|
22
|
+
"items": [
|
|
23
|
+
{
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"enum": ["all", "recommended", "off"],
|
|
28
|
+
"errorMessage": "allowed types are \"off\", \"recommended\" and \"all\""
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"Format": {
|
|
38
|
+
"$anchor": "format",
|
|
39
|
+
"enum": [
|
|
40
|
+
"oas2",
|
|
41
|
+
"oas3",
|
|
42
|
+
"oas3.0",
|
|
43
|
+
"oas3.1",
|
|
44
|
+
"asyncapi2",
|
|
45
|
+
"json-schema",
|
|
46
|
+
"json-schema-loose",
|
|
47
|
+
"json-schema-draft4",
|
|
48
|
+
"json-schema-draft6",
|
|
49
|
+
"json-schema-draft7",
|
|
50
|
+
"json-schema-draft-2019-09",
|
|
51
|
+
"json-schema-2019-09",
|
|
52
|
+
"json-schema-draft-2020-12",
|
|
53
|
+
"json-schema-2020-12"
|
|
54
|
+
],
|
|
55
|
+
"errorMessage": "must be a valid format"
|
|
56
|
+
},
|
|
57
|
+
"Functions": {
|
|
58
|
+
"$anchor": "functions",
|
|
59
|
+
"type": "array",
|
|
60
|
+
"items": {
|
|
61
|
+
"type": "string"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"FunctionsDir": {
|
|
65
|
+
"$anchor": "functionsDir",
|
|
66
|
+
"type": "string"
|
|
67
|
+
},
|
|
68
|
+
"Function": {
|
|
69
|
+
"$anchor": "function",
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"function": {
|
|
73
|
+
"type": "string"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": ["function"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -9,49 +9,26 @@
|
|
|
9
9
|
"format": "url",
|
|
10
10
|
"errorMessage": "must be a valid URL"
|
|
11
11
|
},
|
|
12
|
-
"description": {
|
|
12
|
+
"description": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
13
15
|
"rules": {
|
|
14
16
|
"type": "object",
|
|
15
17
|
"additionalProperties": {
|
|
16
18
|
"$ref": "rule.schema#"
|
|
17
19
|
}
|
|
18
20
|
},
|
|
21
|
+
"functions": {
|
|
22
|
+
"$ref": "extensions#functions"
|
|
23
|
+
},
|
|
24
|
+
"functionsDir": {
|
|
25
|
+
"$ref": "extensions#functionsDir"
|
|
26
|
+
},
|
|
19
27
|
"formats": {
|
|
20
28
|
"$ref": "shared#formats"
|
|
21
29
|
},
|
|
22
30
|
"extends": {
|
|
23
|
-
"
|
|
24
|
-
{
|
|
25
|
-
"$ref": "#",
|
|
26
|
-
"errorMessage": "must be a valid ruleset"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"type": "array",
|
|
30
|
-
"items": {
|
|
31
|
-
"oneOf": [
|
|
32
|
-
{
|
|
33
|
-
"$ref": "#/properties/extends/oneOf/0"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"type": "array",
|
|
37
|
-
"minItems": 2,
|
|
38
|
-
"additionalItems": false,
|
|
39
|
-
"items": [
|
|
40
|
-
{
|
|
41
|
-
"$ref": "#"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"type": "string",
|
|
45
|
-
"enum": ["off", "recommended", "all"],
|
|
46
|
-
"errorMessage": "allowed types are \"off\", \"recommended\" and \"all\""
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
"errorMessage": "must be a valid ruleset"
|
|
31
|
+
"$ref": "extensions#extends"
|
|
55
32
|
},
|
|
56
33
|
"parserOptions": {
|
|
57
34
|
"type": "object",
|
|
@@ -6,15 +6,10 @@
|
|
|
6
6
|
"$anchor": "formats",
|
|
7
7
|
"type": "array",
|
|
8
8
|
"items": {
|
|
9
|
-
"$ref": "#format"
|
|
9
|
+
"$ref": "extensions#format"
|
|
10
10
|
},
|
|
11
11
|
"errorMessage": "must be an array of formats"
|
|
12
12
|
},
|
|
13
|
-
"Format": {
|
|
14
|
-
"$anchor": "format",
|
|
15
|
-
"spectral-runtime": "spectral-format",
|
|
16
|
-
"errorMessage": "must be a valid format"
|
|
17
|
-
},
|
|
18
13
|
"DiagnosticSeverity": {
|
|
19
14
|
"enum": [-1, 0, 1, 2, 3]
|
|
20
15
|
},
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createValidator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ajv_1 = (0, tslib_1.__importStar)(require("ajv"));
|
|
6
|
+
const ajv_formats_1 = (0, tslib_1.__importDefault)(require("ajv-formats"));
|
|
7
|
+
const ajv_errors_1 = (0, tslib_1.__importDefault)(require("ajv-errors"));
|
|
8
|
+
const ruleSchema = (0, tslib_1.__importStar)(require("../meta/rule.schema.json"));
|
|
9
|
+
const shared = (0, tslib_1.__importStar)(require("../meta/shared.json"));
|
|
10
|
+
const rulesetSchema = (0, tslib_1.__importStar)(require("../meta/ruleset.schema.json"));
|
|
11
|
+
const jsExtensions = (0, tslib_1.__importStar)(require("../meta/js-extensions.json"));
|
|
12
|
+
const jsonExtensions = (0, tslib_1.__importStar)(require("../meta/json-extensions.json"));
|
|
13
|
+
const message = (0, ajv_1._) `'spectral-message'`;
|
|
14
|
+
const validators = {
|
|
15
|
+
js: null,
|
|
16
|
+
json: null,
|
|
17
|
+
};
|
|
18
|
+
function createValidator(format) {
|
|
19
|
+
const existingValidator = validators[format];
|
|
20
|
+
if (existingValidator !== null) {
|
|
21
|
+
return existingValidator;
|
|
22
|
+
}
|
|
23
|
+
const ajv = new ajv_1.default({
|
|
24
|
+
allErrors: true,
|
|
25
|
+
strict: true,
|
|
26
|
+
strictRequired: false,
|
|
27
|
+
keywords: ['$anchor'],
|
|
28
|
+
schemas: [ruleSchema, shared],
|
|
29
|
+
});
|
|
30
|
+
(0, ajv_formats_1.default)(ajv);
|
|
31
|
+
(0, ajv_errors_1.default)(ajv);
|
|
32
|
+
ajv.addKeyword({
|
|
33
|
+
keyword: 'spectral-runtime',
|
|
34
|
+
schemaType: 'string',
|
|
35
|
+
error: {
|
|
36
|
+
message(ctx) {
|
|
37
|
+
return (0, ajv_1._) `${ctx.data}[Symbol.for(${message})]`;
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
code(cxt) {
|
|
41
|
+
const { data } = cxt;
|
|
42
|
+
switch (cxt.schema) {
|
|
43
|
+
case 'format':
|
|
44
|
+
cxt.fail((0, ajv_1._) `typeof ${data} !== "function"`);
|
|
45
|
+
break;
|
|
46
|
+
case 'ruleset-function':
|
|
47
|
+
cxt.pass((0, ajv_1._) `typeof ${data}.function === "function"`);
|
|
48
|
+
cxt.pass((0, ajv_1._) `(() => { try { ${data}.function.validator && ${data}.function.validator('functionOptions' in ${data} ? ${data} : null); } catch (e) { ${data}[${message}] = e.message } })()`);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
if (format === 'js') {
|
|
54
|
+
ajv.addSchema(jsExtensions);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
ajv.addSchema(jsonExtensions);
|
|
58
|
+
}
|
|
59
|
+
const validator = ajv.compile(rulesetSchema);
|
|
60
|
+
validators[format] = validator;
|
|
61
|
+
return validator;
|
|
62
|
+
}
|
|
63
|
+
exports.createValidator = createValidator;
|
|
64
|
+
//# sourceMappingURL=ajv.js.map
|
|
@@ -0,0 +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,wFAA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A,kBAAkB,IAAI,0BAA0B,IAAI,4CAA4C,IAAI,MAAM,IAAI,2BAA2B,IAAI,IAAI,OAAO,sBAAsB,CAChL,CAAC;oBACF,MAAM;aACT;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,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7C,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC/B,OAAO,SAAS,CAAC;AACnB,CAAC;AAjDD,0CAiDC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { FileRuleDefinition, RuleDefinition, RulesetDefinition } from '
|
|
2
|
-
export declare
|
|
3
|
-
readonly message: string;
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
}
|
|
6
|
-
export declare function assertValidRuleset(ruleset: unknown): asserts ruleset is RulesetDefinition;
|
|
1
|
+
import type { FileRuleDefinition, RuleDefinition, RulesetDefinition } from '../types';
|
|
2
|
+
export declare function assertValidRuleset(ruleset: unknown, format?: 'js' | 'json'): asserts ruleset is RulesetDefinition;
|
|
7
3
|
export declare function isValidRule(rule: FileRuleDefinition): rule is RuleDefinition;
|
|
8
4
|
export declare function assertValidRule(rule: FileRuleDefinition): asserts rule is RuleDefinition;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidRule = exports.isValidRule = exports.assertValidRuleset = void 0;
|
|
4
|
+
const json_1 = require("@stoplight/json");
|
|
5
|
+
const ajv_1 = require("./ajv");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
function assertValidRuleset(ruleset, format = 'js') {
|
|
8
|
+
var _a;
|
|
9
|
+
if (!(0, json_1.isPlainObject)(ruleset)) {
|
|
10
|
+
throw new Error('Provided ruleset is not an object');
|
|
11
|
+
}
|
|
12
|
+
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');
|
|
14
|
+
}
|
|
15
|
+
const validate = (0, ajv_1.createValidator)(format);
|
|
16
|
+
if (!validate(ruleset)) {
|
|
17
|
+
throw new errors_1.RulesetAjvValidationError(ruleset, (_a = validate.errors) !== null && _a !== void 0 ? _a : []);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.assertValidRuleset = assertValidRuleset;
|
|
21
|
+
function isValidRule(rule) {
|
|
22
|
+
return typeof rule === 'object' && rule !== null && !Array.isArray(rule) && ('given' in rule || 'then' in rule);
|
|
23
|
+
}
|
|
24
|
+
exports.isValidRule = isValidRule;
|
|
25
|
+
function assertValidRule(rule) {
|
|
26
|
+
if (!isValidRule(rule)) {
|
|
27
|
+
throw new TypeError('Invalid rule');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.assertValidRule = assertValidRule;
|
|
31
|
+
//# sourceMappingURL=assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../../src/ruleset/validation/assertions.ts"],"names":[],"mappings":";;;AAAA,0CAAgD;AAChD,+BAAwC;AACxC,qCAA6E;AAG7E,SAAgB,kBAAkB,CAChC,OAAgB,EAChB,SAAwB,IAAI;;IAE5B,IAAI,CAAC,IAAA,oBAAa,EAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;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,CAAC,CAAC;KAC7F;IAED,MAAM,QAAQ,GAAG,IAAA,qBAAe,EAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACtB,MAAM,IAAI,kCAAyB,CAAC,OAAO,EAAE,MAAA,QAAQ,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AAjBD,gDAiBC;AAED,SAAgB,WAAW,CAAC,IAAwB;IAClD,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;AAFD,kCAEC;AAED,SAAgB,eAAe,CAAC,IAAwB;IACtD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;QACtB,MAAM,IAAI,SAAS,CAAC,cAAc,CAAC,CAAC;KACrC;AACH,CAAC;AAJD,0CAIC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ErrorObject } from 'ajv';
|
|
2
|
+
export declare class RulesetValidationError extends Error {
|
|
3
|
+
readonly message: string;
|
|
4
|
+
constructor(message: string);
|
|
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;
|
|
11
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RulesetAjvValidationError = exports.RulesetValidationError = void 0;
|
|
4
|
+
const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
5
|
+
class RulesetValidationError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.RulesetValidationError = RulesetValidationError;
|
|
12
|
+
const RULE_INSTANCE_PATH = /^\/rules\/[^/]+/;
|
|
13
|
+
const GENERIC_INSTANCE_PATH = /^\/(?:aliases|extends|overrides(?:\/\d+\/extends)?)/;
|
|
14
|
+
class RulesetAjvValidationError extends RulesetValidationError {
|
|
15
|
+
constructor(ruleset, errors) {
|
|
16
|
+
super(RulesetAjvValidationError.serializeAjvErrors(ruleset, errors));
|
|
17
|
+
this.ruleset = ruleset;
|
|
18
|
+
this.errors = errors;
|
|
19
|
+
}
|
|
20
|
+
static serializeAjvErrors(ruleset, errors) {
|
|
21
|
+
const sortedErrors = [...errors]
|
|
22
|
+
.sort((errorA, errorB) => {
|
|
23
|
+
const diff = errorA.instancePath.length - errorB.instancePath.length;
|
|
24
|
+
return diff === 0 ? (errorA.keyword === 'errorMessage' && errorB.keyword !== 'errorMessage' ? -1 : 0) : diff;
|
|
25
|
+
})
|
|
26
|
+
.filter((error, i, sortedErrors) => i === 0 || sortedErrors[i - 1].instancePath !== error.instancePath);
|
|
27
|
+
const filteredErrors = [];
|
|
28
|
+
l: for (let i = 0; i < sortedErrors.length; i++) {
|
|
29
|
+
const error = sortedErrors[i];
|
|
30
|
+
const prevError = i === 0 ? null : sortedErrors[i - 1];
|
|
31
|
+
if (GENERIC_INSTANCE_PATH.test(error.instancePath)) {
|
|
32
|
+
let x = 1;
|
|
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();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
filteredErrors.push(error);
|
|
52
|
+
}
|
|
53
|
+
return filteredErrors
|
|
54
|
+
.map(({ message, instancePath }) => `Error at ${(0, spectral_runtime_1.printPath)(instancePath.slice(1).split('/'), spectral_runtime_1.PrintStyle.Pointer)}: ${message !== null && message !== void 0 ? message : ''}`)
|
|
55
|
+
.join('\n');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.RulesetAjvValidationError = RulesetAjvValidationError;
|
|
59
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/ruleset/validation/errors.ts"],"names":[],"mappings":";;;AACA,kEAAoE;AAEpE,MAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAA4B,OAAe;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QADW,YAAO,GAAP,OAAO,CAAQ;IAE3C,CAAC;CACF;AAJD,wDAIC;AAED,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,qBAAqB,GAAG,qDAAqD,CAAC;AAEpF,MAAa,yBAA0B,SAAQ,sBAAsB;IACnE,YAAmB,OAAgC,EAAS,MAAqB;QAC/E,KAAK,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QADpD,YAAO,GAAP,OAAO,CAAyB;QAAS,WAAM,GAAN,MAAM,CAAe;IAEjF,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAC,OAAgC,EAAE,MAAqB;QACtF,MAAM,YAAY,GAAG,CAAC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,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,EAC7D;wBACA,SAAS,CAAC,CAAC;qBACZ;oBAED,CAAC,EAAE,CAAC;iBACL;aACF;iBAAM,IAAI,SAAS,KAAK,IAAI,EAAE;gBAC7B,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC3B,SAAS;aACV;iBAAM;gBACL,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBAE1D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,YAAY,EAAE;oBACrF,cAAc,CAAC,GAAG,EAAE,CAAC;iBACtB;aACF;YAED,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC5B;QAED,OAAO,cAAc;aAClB,GAAG,CACF,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAC5B,YAAY,IAAA,4BAAS,EAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,6BAAU,CAAC,OAAO,CAAC,KAAK,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EAAE,CAClG;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF;AApDD,8DAoDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidRuleset = exports.RulesetValidationError = void 0;
|
|
4
|
+
var errors_1 = require("./errors");
|
|
5
|
+
Object.defineProperty(exports, "RulesetValidationError", { enumerable: true, get: function () { return errors_1.RulesetValidationError; } });
|
|
6
|
+
var assertions_1 = require("./assertions");
|
|
7
|
+
Object.defineProperty(exports, "assertValidRuleset", { enumerable: true, get: function () { return assertions_1.assertValidRuleset; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ruleset/validation/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAAzC,gHAAA,sBAAsB,OAAA;AAC/B,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA"}
|
package/dist/runner/lintNode.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.lintNode = void 0;
|
|
4
4
|
const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
|
+
const pony_cause_1 = require("pony-cause");
|
|
6
7
|
const document_1 = require("../document");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
const lintNode = (context, node, rule) => {
|
|
@@ -18,10 +19,18 @@ const lintNode = (context, node, rule) => {
|
|
|
18
19
|
const targets = (0, utils_1.getLintTargets)(node.value, then.field);
|
|
19
20
|
for (const target of targets) {
|
|
20
21
|
const path = target.path.length > 0 ? [...givenPath, ...target.path] : givenPath;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let targetResults;
|
|
23
|
+
try {
|
|
24
|
+
targetResults = then.function(target.value, (_a = then.functionOptions) !== null && _a !== void 0 ? _a : null, {
|
|
25
|
+
...fnContext,
|
|
26
|
+
path,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new pony_cause_1.ErrorWithCause(`Function "${then.function.name}" threw an exception${(0, lodash_1.isError)(e) ? `: ${e.message}` : ''}`, {
|
|
31
|
+
cause: e,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
25
34
|
if (targetResults === void 0)
|
|
26
35
|
continue;
|
|
27
36
|
if ('then' in targetResults) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lintNode.js","sourceRoot":"","sources":["../../src/runner/lintNode.ts"],"names":[],"mappings":";;;AACA,kEAA+G;AAC/G,
|
|
1
|
+
{"version":3,"file":"lintNode.js","sourceRoot":"","sources":["../../src/runner/lintNode.ts"],"names":[],"mappings":";;;AACA,kEAA+G;AAC/G,mCAAsC;AACtC,2CAA4C;AAE5C,0CAAuC;AAGvC,mCAA+D;AAGxD,MAAM,QAAQ,GAAG,CAAC,OAA+B,EAAE,IAAgB,EAAE,IAAU,EAAQ,EAAE;;IAC9F,MAAM,SAAS,GAA2B;QACxC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,QAAQ;QAC5C,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;QAC5C,IAAI;QACJ,IAAI,EAAE,EAAE;KACT,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IAEhG,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;QAC5B,MAAM,OAAO,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEvD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAEjF,IAAI,aAAa,CAAC;YAClB,IAAI;gBACF,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAA,IAAI,CAAC,eAAe,mCAAI,IAAI,EAAE;oBACxE,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,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;QAE3B,MAAM,QAAQ,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;QAEhH,IAAI,QAAQ,KAAK,CAAC,CAAC;YAAE,SAAS;QAE9B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,aAAa,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;YACzG,IAAI;YACJ,QAAQ;YACR,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACxC,KAAK;SACN,CAAC,CAAC;KACJ;AACH,CAAC"}
|
package/dist/runner/runner.js
CHANGED
|
@@ -85,6 +85,7 @@ function execute(input, callbacks, jsonPathExpressions) {
|
|
|
85
85
|
fallback: fallbacks_1.jsonPathPlus,
|
|
86
86
|
unsafe: false,
|
|
87
87
|
output: 'auto',
|
|
88
|
+
customShorthands: {},
|
|
88
89
|
});
|
|
89
90
|
nimma.query(input, Object.entries(callbacks).reduce((mapped, [key, cbs]) => {
|
|
90
91
|
mapped[key] = scope => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner/runner.ts"],"names":[],"mappings":";;;;AAGA,oCAAkE;AAClE,yCAAsC;AAItC,uEAA+C;AAC/C,+CAA+C;AAC/C,0CA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J;QAED,OAAO;KACR;IAED,MAAM,KAAK,GAAG,IAAI,gBAAK,CAAC,mBAAmB,EAAE;QAC3C,QAAQ,EAAE,wBAAY;QACtB,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,EAAE;KACrB,CAAC,CAAC;IAEH,KAAK,CAAC,KAAK,CACT,KAAK,EACL,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAA2B,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;QAChF,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAAE;YACpB,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;gBACpB,EAAE,CAAC,KAAK,CAAC,CAAC;aACX;QACH,CAAC,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoplight/spectral-core",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "1.12.0",
|
|
6
4
|
"sideEffects": false,
|
|
7
5
|
"homepage": "https://github.com/stoplightio/spectral",
|
|
8
6
|
"bugs": "https://github.com/stoplightio/spectral/issues",
|
|
@@ -15,6 +13,19 @@
|
|
|
15
13
|
"files": [
|
|
16
14
|
"dist"
|
|
17
15
|
],
|
|
16
|
+
"type": "commonjs",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./ruleset/validation": {
|
|
25
|
+
"types": "./dist/ruleset/validation/index.d.ts",
|
|
26
|
+
"require": "./dist/ruleset/validation/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
18
29
|
"engines": {
|
|
19
30
|
"node": "^12.20 || >= 14.13"
|
|
20
31
|
},
|
|
@@ -39,7 +50,8 @@
|
|
|
39
50
|
"lodash": "~4.17.21",
|
|
40
51
|
"lodash.topath": "^4.5.2",
|
|
41
52
|
"minimatch": "3.0.4",
|
|
42
|
-
"nimma": "0.
|
|
53
|
+
"nimma": "0.2.0",
|
|
54
|
+
"pony-cause": "^1.0.0",
|
|
43
55
|
"simple-eval": "1.0.0",
|
|
44
56
|
"tslib": "^2.3.0"
|
|
45
57
|
},
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertValidRule = exports.isValidRule = exports.assertValidRuleset = exports.RulesetValidationError = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ajv_1 = (0, tslib_1.__importStar)(require("ajv"));
|
|
6
|
-
const ajv_formats_1 = (0, tslib_1.__importDefault)(require("ajv-formats"));
|
|
7
|
-
const ajv_errors_1 = (0, tslib_1.__importDefault)(require("ajv-errors"));
|
|
8
|
-
const json_1 = require("@stoplight/json");
|
|
9
|
-
const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
10
|
-
const ruleSchema = (0, tslib_1.__importStar)(require("../meta/rule.schema.json"));
|
|
11
|
-
const rulesetSchema = (0, tslib_1.__importStar)(require("../meta/ruleset.schema.json"));
|
|
12
|
-
const shared = (0, tslib_1.__importStar)(require("../meta/shared.json"));
|
|
13
|
-
const message = (0, ajv_1._) `'spectral-message'`;
|
|
14
|
-
const ajv = new ajv_1.default({ allErrors: true, strict: true, strictRequired: false, keywords: ['$anchor', 'x-internal'] });
|
|
15
|
-
(0, ajv_formats_1.default)(ajv);
|
|
16
|
-
(0, ajv_errors_1.default)(ajv);
|
|
17
|
-
ajv.addKeyword({
|
|
18
|
-
keyword: 'spectral-runtime',
|
|
19
|
-
schemaType: 'string',
|
|
20
|
-
error: {
|
|
21
|
-
message(ctx) {
|
|
22
|
-
return (0, ajv_1._) `${ctx.data}[Symbol.for(${message})]`;
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
code(cxt) {
|
|
26
|
-
const { data } = cxt;
|
|
27
|
-
switch (cxt.schema) {
|
|
28
|
-
case 'spectral-format':
|
|
29
|
-
cxt.fail((0, ajv_1._) `typeof ${data} !== "function"`);
|
|
30
|
-
break;
|
|
31
|
-
case 'spectral-function':
|
|
32
|
-
cxt.pass((0, ajv_1._) `typeof ${data}.function === "function"`);
|
|
33
|
-
cxt.pass((0, ajv_1._) `(() => { try { ${data}.function.validator && ${data}.function.validator('functionOptions' in ${data} ? ${data} : null); } catch (e) { ${data}[${message}] = e.message } })()`);
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
const validate = ajv.addSchema(ruleSchema).addSchema(shared).compile(rulesetSchema);
|
|
39
|
-
class RulesetValidationError extends Error {
|
|
40
|
-
constructor(message) {
|
|
41
|
-
super(message);
|
|
42
|
-
this.message = message;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.RulesetValidationError = RulesetValidationError;
|
|
46
|
-
const RULE_INSTANCE_PATH = /^\/rules\/[^/]+/;
|
|
47
|
-
const GENERIC_INSTANCE_PATH = /^\/(?:aliases|extends|overrides(?:\/\d+\/extends)?)/;
|
|
48
|
-
class RulesetAjvValidationError extends RulesetValidationError {
|
|
49
|
-
constructor(ruleset, errors) {
|
|
50
|
-
super(RulesetAjvValidationError.serializeAjvErrors(ruleset, errors));
|
|
51
|
-
this.ruleset = ruleset;
|
|
52
|
-
this.errors = errors;
|
|
53
|
-
}
|
|
54
|
-
static serializeAjvErrors(ruleset, errors) {
|
|
55
|
-
const sortedErrors = [...errors]
|
|
56
|
-
.sort((errorA, errorB) => {
|
|
57
|
-
const diff = errorA.instancePath.length - errorB.instancePath.length;
|
|
58
|
-
return diff === 0 ? (errorA.keyword === 'errorMessage' && errorB.keyword !== 'errorMessage' ? -1 : 0) : diff;
|
|
59
|
-
})
|
|
60
|
-
.filter((error, i, sortedErrors) => i === 0 || sortedErrors[i - 1].instancePath !== error.instancePath);
|
|
61
|
-
const filteredErrors = [];
|
|
62
|
-
l: for (let i = 0; i < sortedErrors.length; i++) {
|
|
63
|
-
const error = sortedErrors[i];
|
|
64
|
-
const prevError = i === 0 ? null : sortedErrors[i - 1];
|
|
65
|
-
if (GENERIC_INSTANCE_PATH.test(error.instancePath)) {
|
|
66
|
-
let x = 1;
|
|
67
|
-
while (i + x < sortedErrors.length) {
|
|
68
|
-
if (sortedErrors[i + x].instancePath.startsWith(error.instancePath) ||
|
|
69
|
-
!GENERIC_INSTANCE_PATH.test(sortedErrors[i + x].instancePath)) {
|
|
70
|
-
continue l;
|
|
71
|
-
}
|
|
72
|
-
x++;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else if (prevError === null) {
|
|
76
|
-
filteredErrors.push(error);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const match = RULE_INSTANCE_PATH.exec(error.instancePath);
|
|
81
|
-
if (match !== null && match[0] !== match.input && match[0] === prevError.instancePath) {
|
|
82
|
-
filteredErrors.pop();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
filteredErrors.push(error);
|
|
86
|
-
}
|
|
87
|
-
return filteredErrors
|
|
88
|
-
.map(({ message, instancePath }) => `Error at ${(0, spectral_runtime_1.printPath)(instancePath.slice(1).split('/'), spectral_runtime_1.PrintStyle.Pointer)}: ${message !== null && message !== void 0 ? message : ''}`)
|
|
89
|
-
.join('\n');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function assertValidRuleset(ruleset) {
|
|
93
|
-
var _a;
|
|
94
|
-
if (!(0, json_1.isPlainObject)(ruleset)) {
|
|
95
|
-
throw new Error('Provided ruleset is not an object');
|
|
96
|
-
}
|
|
97
|
-
if (!('rules' in ruleset) && !('extends' in ruleset) && !('overrides' in ruleset)) {
|
|
98
|
-
throw new RulesetValidationError('Ruleset must have rules or extends or overrides defined');
|
|
99
|
-
}
|
|
100
|
-
if (!validate(ruleset)) {
|
|
101
|
-
throw new RulesetAjvValidationError(ruleset, (_a = validate.errors) !== null && _a !== void 0 ? _a : []);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.assertValidRuleset = assertValidRuleset;
|
|
105
|
-
function isValidRule(rule) {
|
|
106
|
-
return typeof rule === 'object' && rule !== null && !Array.isArray(rule) && ('given' in rule || 'then' in rule);
|
|
107
|
-
}
|
|
108
|
-
exports.isValidRule = isValidRule;
|
|
109
|
-
function assertValidRule(rule) {
|
|
110
|
-
if (!isValidRule(rule)) {
|
|
111
|
-
throw new TypeError('Invalid rule');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.assertValidRule = assertValidRule;
|
|
115
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/ruleset/validation.ts"],"names":[],"mappings":";;;;AAAA,wDAA0C;AAC1C,2EAAqC;AACrC,yEAAmC;AACnC,0CAAgD;AAChD,kEAAoE;AAEpE,kFAAuD;AACvD,wFAA6D;AAC7D,yEAA8C;AAG9C,MAAM,OAAO,GAAG,IAAA,OAAC,EAAA,oBAAoB,CAAC;AAEtC,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;AACnH,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAC;AAChB,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;AACf,GAAG,CAAC,UAAU,CAAC;IACb,OAAO,EAAE,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