@stoplight/spectral-core 1.12.2 → 1.13.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/documentInventory.d.ts +1 -0
- package/dist/documentInventory.js +56 -33
- package/dist/documentInventory.js.map +1 -1
- package/dist/ruleset/function.d.ts +3 -2
- 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/validation/ajv.js +7 -4
- 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 +38 -42
- package/dist/ruleset/validation/errors.js.map +1 -1
- package/package.json +7 -5
|
@@ -28,5 +28,6 @@ export declare class DocumentInventory implements IDocumentInventory {
|
|
|
28
28
|
constructor(document: IDocument, resolver: Resolver);
|
|
29
29
|
resolve(): Promise<void>;
|
|
30
30
|
findAssociatedItemForPath(path: JsonPath, resolved: boolean): DocumentInventoryItem | null;
|
|
31
|
+
protected convertRefMapKeyToPath(refPath: string): JsonPath;
|
|
31
32
|
protected parseResolveResult: Resolver['parseResolveResult'];
|
|
32
33
|
}
|
|
@@ -67,64 +67,87 @@ class DocumentInventory {
|
|
|
67
67
|
findAssociatedItemForPath(path, resolved) {
|
|
68
68
|
if (!resolved) {
|
|
69
69
|
const newPath = (0, spectral_runtime_1.getClosestJsonPath)(this.unresolved, path);
|
|
70
|
-
|
|
70
|
+
const item = {
|
|
71
71
|
document: this.document,
|
|
72
72
|
path: newPath,
|
|
73
73
|
missingPropertyPath: path,
|
|
74
74
|
};
|
|
75
|
+
return item;
|
|
75
76
|
}
|
|
76
77
|
try {
|
|
77
78
|
const newPath = (0, spectral_runtime_1.getClosestJsonPath)(this.resolved, path);
|
|
78
|
-
|
|
79
|
+
const $ref = (0, spectral_runtime_1.traverseObjUntilRef)(this.unresolved, newPath);
|
|
79
80
|
if ($ref === null) {
|
|
80
|
-
|
|
81
|
+
const item = {
|
|
81
82
|
document: this.document,
|
|
82
83
|
path: (0, spectral_runtime_1.getClosestJsonPath)(this.unresolved, path),
|
|
83
84
|
missingPropertyPath: path,
|
|
84
85
|
};
|
|
86
|
+
return item;
|
|
85
87
|
}
|
|
86
88
|
const missingPropertyPath = newPath.length === 0 ? [] : path.slice(path.lastIndexOf(newPath[newPath.length - 1]) + 1);
|
|
87
89
|
let { source } = this;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
90
|
+
if (source === null || this.graph === null) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
let refMap = this.graph.getNodeData(source).refMap;
|
|
94
|
+
let resolvedDoc = this.document;
|
|
95
|
+
const adjustedPath = ['#', ...path.map(String)];
|
|
96
|
+
let refMapKey = '';
|
|
97
|
+
for (const segment of adjustedPath) {
|
|
98
|
+
if (refMapKey.length > 0) {
|
|
99
|
+
refMapKey += '/';
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
path: (0, spectral_runtime_1.getClosestJsonPath)(resolvedDoc.data, path),
|
|
105
|
-
missingPropertyPath: path,
|
|
106
|
-
};
|
|
101
|
+
refMapKey += (0, json_1.encodePointerFragment)(segment);
|
|
102
|
+
while (refMapKey in refMap) {
|
|
103
|
+
const newRef = refMap[refMapKey];
|
|
104
|
+
if ((0, json_1.isLocalRef)(newRef)) {
|
|
105
|
+
refMapKey = newRef;
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
else {
|
|
108
|
+
const extractedSource = (0, json_1.extractSourceFromRef)(newRef);
|
|
109
|
+
if (extractedSource === null) {
|
|
110
|
+
const item = {
|
|
111
|
+
document: resolvedDoc,
|
|
112
|
+
path: (0, spectral_runtime_1.getClosestJsonPath)(resolvedDoc.data, path),
|
|
113
|
+
missingPropertyPath: path,
|
|
114
|
+
};
|
|
115
|
+
return item;
|
|
116
|
+
}
|
|
117
|
+
source = (0, spectral_runtime_1.isAbsoluteRef)(extractedSource) ? extractedSource : (0, path_1.resolve)(source, '..', extractedSource);
|
|
118
|
+
const newResolvedDoc = source === this.document.source ? this.document : this.referencedDocuments[source];
|
|
119
|
+
if (newResolvedDoc === null || newResolvedDoc === void 0) {
|
|
120
|
+
const item = {
|
|
121
|
+
document: resolvedDoc,
|
|
122
|
+
path: (0, spectral_runtime_1.getClosestJsonPath)(resolvedDoc.data, path),
|
|
123
|
+
missingPropertyPath: path,
|
|
124
|
+
};
|
|
125
|
+
return item;
|
|
126
|
+
}
|
|
127
|
+
resolvedDoc = newResolvedDoc;
|
|
128
|
+
refMap = this.graph.getNodeData(source).refMap;
|
|
129
|
+
refMapKey = newRef.indexOf('#') >= 0 ? newRef.slice(newRef.indexOf('#')) : '#';
|
|
114
130
|
}
|
|
115
131
|
}
|
|
116
|
-
const closestPath = (0, spectral_runtime_1.getClosestJsonPath)(resolvedDoc.data, scopedPath);
|
|
117
|
-
return {
|
|
118
|
-
document: resolvedDoc,
|
|
119
|
-
path: closestPath,
|
|
120
|
-
missingPropertyPath: [...closestPath, ...missingPropertyPath],
|
|
121
|
-
};
|
|
122
132
|
}
|
|
133
|
+
const closestPath = (0, spectral_runtime_1.getClosestJsonPath)(resolvedDoc.data, this.convertRefMapKeyToPath(refMapKey));
|
|
134
|
+
const item = {
|
|
135
|
+
document: resolvedDoc,
|
|
136
|
+
path: closestPath,
|
|
137
|
+
missingPropertyPath: [...closestPath, ...missingPropertyPath],
|
|
138
|
+
};
|
|
139
|
+
return item;
|
|
123
140
|
}
|
|
124
141
|
catch {
|
|
125
142
|
return null;
|
|
126
143
|
}
|
|
127
144
|
}
|
|
145
|
+
convertRefMapKeyToPath(refPath) {
|
|
146
|
+
if (refPath.startsWith('#/')) {
|
|
147
|
+
refPath = refPath.slice(2);
|
|
148
|
+
}
|
|
149
|
+
return refPath.split('/').map(json_1.decodePointerFragment);
|
|
150
|
+
}
|
|
128
151
|
}
|
|
129
152
|
exports.DocumentInventory = DocumentInventory;
|
|
130
153
|
DocumentInventory._cachedRemoteDocuments = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentInventory.js","sourceRoot":"","sources":["../src/documentInventory.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"documentInventory.js","sourceRoot":"","sources":["../src/documentInventory.ts"],"names":[],"mappings":";;;;AAAA,0CAAiH;AACjH,0CAAmD;AAEnD,mCAAsC;AACtC,yCAAiD;AAGjD,mDAAgF;AAChF,kFAAuD;AAEvD,kEAAqG;AAerG,MAAa,iBAAiB;IAsB5B,YAA4B,QAAmB,EAAY,QAAkB;QAAjD,aAAQ,GAAR,QAAQ,CAAW;QAAY,aAAQ,GAAR,QAAQ,CAAU;QAhBtE,gBAAW,GAAkB,EAAE,CAAC;QAgK7B,uBAAkB,GAAmC,WAAW,CAAC,EAAE;YAC3E,MAAM,MAAM,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACrE,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC;YAE5B,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAE3C,MAAM,MAAM,GACV,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;YACh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M,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;qBAChF;iBACF;aACF;YAED,MAAM,WAAW,GAAG,IAAA,qCAAkB,EAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;YACjG,MAAM,IAAI,GAA0B;gBAClC,QAAQ,EAAE,WAAW;gBACrB,IAAI,EAAE,WAAW;gBACjB,mBAAmB,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,mBAAmB,CAAC;aAC9D,CAAC;YACF,OAAO,IAAI,CAAC;SACb;QAAC,MAAM;YACN,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAES,sBAAsB,CAAC,OAAe;QAC9C,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC5B;QAED,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,4BAAqB,CAAC,CAAC;IACvD,CAAC;;AApKH,8CA0LC;AAzLyB,wCAAsB,GAAG,IAAI,OAAO,EAA+C,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';
|
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,8CAA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AAQ,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;oBAChC,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,YAAY,CAAC,KAAK;iBAC1B,CAAC,CAAC;aACJ;iBAAM;gBACL,IAAA,4BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC5B,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;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
|
|
@@ -30,11 +30,14 @@ function createValidator(format) {
|
|
|
30
30
|
(0, ajv_formats_1.default)(ajv);
|
|
31
31
|
(0, ajv_errors_1.default)(ajv);
|
|
32
32
|
ajv.addKeyword({
|
|
33
|
-
keyword: 'spectral-runtime',
|
|
33
|
+
keyword: 'x-spectral-runtime',
|
|
34
34
|
schemaType: 'string',
|
|
35
35
|
error: {
|
|
36
|
-
message(
|
|
37
|
-
return (0, ajv_1._) `${
|
|
36
|
+
message(cxt) {
|
|
37
|
+
return (0, ajv_1._) `${cxt.data}[Symbol.for(${message})]`;
|
|
38
|
+
},
|
|
39
|
+
params(cxt) {
|
|
40
|
+
return (0, ajv_1._) `${cxt.data}[Symbol.for(${message})] ? { "errors": ${cxt.data}[Symbol.for(${message})].errors || [${cxt.data}[Symbol.for(${message})]] } : {}`;
|
|
38
41
|
},
|
|
39
42
|
},
|
|
40
43
|
code(cxt) {
|
|
@@ -45,7 +48,7 @@ function createValidator(format) {
|
|
|
45
48
|
break;
|
|
46
49
|
case 'ruleset-function':
|
|
47
50
|
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
|
|
51
|
+
cxt.pass((0, ajv_1._) `(() => { try { ${data}.function.validator && ${data}.function.validator('functionOptions' in ${data} ? ${data}.functionOptions : null); return true; } catch (e) { ${data}[Symbol.for(${message})] = e; return false; } })()`);
|
|
49
52
|
break;
|
|
50
53
|
}
|
|
51
54
|
},
|
|
@@ -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,y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AI,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;AApDD,0CAoDC"}
|
|
@@ -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,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const spectral_runtime_1 = require("@stoplight/spectral-runtime");
|
|
3
|
+
exports.convertAjvErrors = exports.RulesetValidationError = void 0;
|
|
5
4
|
class RulesetValidationError extends Error {
|
|
6
|
-
constructor(message) {
|
|
5
|
+
constructor(message, path) {
|
|
7
6
|
super(message);
|
|
8
7
|
this.message = message;
|
|
8
|
+
this.path = path;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.RulesetValidationError = RulesetValidationError;
|
|
12
12
|
const RULE_INSTANCE_PATH = /^\/rules\/[^/]+/;
|
|
13
13
|
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
|
-
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();
|
|
14
|
+
function convertAjvErrors(errors) {
|
|
15
|
+
const sortedErrors = [...errors]
|
|
16
|
+
.sort((errorA, errorB) => {
|
|
17
|
+
const diff = errorA.instancePath.length - errorB.instancePath.length;
|
|
18
|
+
return diff === 0 ? (errorA.keyword === 'errorMessage' && errorB.keyword !== 'errorMessage' ? -1 : 0) : diff;
|
|
19
|
+
})
|
|
20
|
+
.filter((error, i, sortedErrors) => i === 0 || sortedErrors[i - 1].instancePath !== error.instancePath);
|
|
21
|
+
const filteredErrors = [];
|
|
22
|
+
l: for (let i = 0; i < sortedErrors.length; i++) {
|
|
23
|
+
const error = sortedErrors[i];
|
|
24
|
+
const prevError = i === 0 ? null : sortedErrors[i - 1];
|
|
25
|
+
if (GENERIC_INSTANCE_PATH.test(error.instancePath)) {
|
|
26
|
+
let x = 1;
|
|
27
|
+
while (i + x < sortedErrors.length) {
|
|
28
|
+
if (sortedErrors[i + x].instancePath.startsWith(error.instancePath) ||
|
|
29
|
+
!GENERIC_INSTANCE_PATH.test(sortedErrors[i + x].instancePath)) {
|
|
30
|
+
continue l;
|
|
49
31
|
}
|
|
32
|
+
x++;
|
|
50
33
|
}
|
|
34
|
+
}
|
|
35
|
+
else if (prevError === null) {
|
|
51
36
|
filteredErrors.push(error);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const match = RULE_INSTANCE_PATH.exec(error.instancePath);
|
|
41
|
+
if (match !== null && match[0] !== match.input && match[0] === prevError.instancePath) {
|
|
42
|
+
filteredErrors.pop();
|
|
43
|
+
}
|
|
52
44
|
}
|
|
53
|
-
|
|
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');
|
|
45
|
+
filteredErrors.push(error);
|
|
56
46
|
}
|
|
47
|
+
return filteredErrors.flatMap(error => {
|
|
48
|
+
var _a;
|
|
49
|
+
return error.keyword === 'x-spectral-runtime'
|
|
50
|
+
? error.params.errors
|
|
51
|
+
: new RulesetValidationError((_a = error.message) !== null && _a !== void 0 ? _a : 'unknown error', error.instancePath.slice(1).split('/'));
|
|
52
|
+
});
|
|
57
53
|
}
|
|
58
|
-
exports.
|
|
54
|
+
exports.convertAjvErrors = convertAjvErrors;
|
|
59
55
|
//# 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.ts"],"names":[],"mappings":";;;AAKA,MAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAA4B,OAAe,EAAkB,IAAc;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QADW,YAAO,GAAP,OAAO,CAAQ;QAAkB,SAAI,GAAJ,IAAI,CAAU;IAE3E,CAAC;CACF;AAJD,wDAIC;AAED,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,qBAAqB,GAAG,qDAAqD,CAAC;AAEpF,SAAgB,gBAAgB,CAAC,MAAqB;IACpD,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC;SAC7B,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,M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c,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,SAAS;SACV;aAAM;YACL,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAE1D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,YAAY,EAAE;gBACrF,cAAc,CAAC,GAAG,EAAE,CAAC;aACtB;SACF;QAED,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC5B;IAED,OAAO,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;;QACpC,OAAA,KAAK,CAAC,OAAO,KAAK,oBAAoB;YACpC,CAAC,CAAE,KAAK,CAAC,MAAM,CAAC,MAAmC;YACnD,CAAC,CAAC,IAAI,sBAAsB,CAAC,MAAA,KAAK,CAAC,OAAO,mCAAI,eAAe,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;KAAA,CACzG,CAAC;AACJ,CAAC;AA7CD,4CA6CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoplight/spectral-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"homepage": "https://github.com/stoplightio/spectral",
|
|
6
6
|
"bugs": "https://github.com/stoplightio/spectral/issues",
|
|
@@ -44,17 +44,19 @@
|
|
|
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.
|
|
48
|
-
"@types/
|
|
47
|
+
"@stoplight/types": "~13.2.0",
|
|
48
|
+
"@types/es-aggregate-error": "^1.0.2",
|
|
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",
|
|
56
|
-
"minimatch": "3.
|
|
57
|
-
"nimma": "0.2.
|
|
58
|
+
"minimatch": "3.1.2",
|
|
59
|
+
"nimma": "0.2.2",
|
|
58
60
|
"pony-cause": "^1.0.0",
|
|
59
61
|
"simple-eval": "1.0.0",
|
|
60
62
|
"tslib": "^2.3.0"
|