@redocly/openapi-core 1.26.1 → 1.27.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/CHANGELOG.md +10 -0
- package/lib/config/all.js +2 -3
- package/lib/config/minimal.js +1 -2
- package/lib/config/recommended-strict.js +2 -3
- package/lib/config/recommended.js +2 -3
- package/lib/config/rules.js +3 -0
- package/lib/config/spec.js +2 -3
- package/lib/config/types.d.ts +2 -3
- package/lib/rules/arazzo/index.js +2 -4
- package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
- package/lib/rules/spot/{version-enum.js → spot-supported-versions.js} +3 -3
- package/lib/types/redocly-yaml.d.ts +1 -1
- package/lib/types/redocly-yaml.js +1 -2
- package/lib/visitors.d.ts +3 -0
- package/lib/visitors.js +2 -2
- package/lib/walk.js +14 -11
- package/package.json +1 -1
- package/src/__tests__/walk.test.ts +51 -0
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +4 -6
- package/src/config/all.ts +2 -3
- package/src/config/minimal.ts +1 -2
- package/src/config/recommended-strict.ts +2 -3
- package/src/config/recommended.ts +2 -3
- package/src/config/rules.ts +3 -1
- package/src/config/spec.ts +2 -3
- package/src/config/types.ts +2 -6
- package/src/rules/arazzo/__tests__/{version-enum.test.ts → spot-supported-versions.test.ts} +3 -3
- package/src/rules/arazzo/index.ts +2 -4
- package/src/rules/spot/{version-enum.ts → spot-supported-versions.ts} +1 -1
- package/src/types/redocly-yaml.ts +1 -2
- package/src/visitors.ts +5 -2
- package/src/walk.ts +20 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/spot/parameters-not-in-body.d.ts +0 -2
- package/lib/rules/spot/parameters-not-in-body.js +0 -18
- package/lib/rules/spot/version-enum.d.ts +0 -2
- package/src/rules/arazzo/__tests__/parameters-not-in-body.test.ts +0 -73
- package/src/rules/spot/parameters-not-in-body.ts +0 -17
package/CHANGELOG.md
CHANGED
package/lib/config/all.js
CHANGED
|
@@ -210,8 +210,7 @@ const all = {
|
|
|
210
210
|
},
|
|
211
211
|
arazzo1Rules: {
|
|
212
212
|
'criteria-unique': 'error',
|
|
213
|
-
'no-criteria-xpath': '
|
|
214
|
-
'parameters-not-in-body': 'error',
|
|
213
|
+
'no-criteria-xpath': 'off',
|
|
215
214
|
'parameters-unique': 'error',
|
|
216
215
|
'requestBody-replacements-unique': 'error',
|
|
217
216
|
'sourceDescription-type': 'error',
|
|
@@ -220,7 +219,7 @@ const all = {
|
|
|
220
219
|
'stepId-unique': 'error',
|
|
221
220
|
'sourceDescription-name-unique': 'error',
|
|
222
221
|
'sourceDescriptions-not-empty': 'error',
|
|
223
|
-
'
|
|
222
|
+
'spot-supported-versions': 'off',
|
|
224
223
|
'workflowId-unique': 'error',
|
|
225
224
|
'workflow-dependsOn': 'error',
|
|
226
225
|
},
|
package/lib/config/minimal.js
CHANGED
|
@@ -187,7 +187,6 @@ const minimal = {
|
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'off',
|
|
189
189
|
'no-criteria-xpath': 'off',
|
|
190
|
-
'parameters-not-in-body': 'off',
|
|
191
190
|
'parameters-unique': 'off',
|
|
192
191
|
'requestBody-replacements-unique': 'off',
|
|
193
192
|
'sourceDescription-type': 'off',
|
|
@@ -196,7 +195,7 @@ const minimal = {
|
|
|
196
195
|
'step-onFailure-unique': 'off',
|
|
197
196
|
'stepId-unique': 'error',
|
|
198
197
|
'sourceDescription-name-unique': 'off',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'off',
|
|
202
201
|
},
|
|
@@ -186,8 +186,7 @@ const recommendedStrict = {
|
|
|
186
186
|
},
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'error',
|
|
189
|
-
'no-criteria-xpath': '
|
|
190
|
-
'parameters-not-in-body': 'error',
|
|
189
|
+
'no-criteria-xpath': 'off',
|
|
191
190
|
'parameters-unique': 'error',
|
|
192
191
|
'requestBody-replacements-unique': 'error',
|
|
193
192
|
'sourceDescription-type': 'error',
|
|
@@ -196,7 +195,7 @@ const recommendedStrict = {
|
|
|
196
195
|
'stepId-unique': 'error',
|
|
197
196
|
'sourceDescription-name-unique': 'error',
|
|
198
197
|
'sourceDescriptions-not-empty': 'error',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'error',
|
|
202
201
|
},
|
|
@@ -186,8 +186,7 @@ const recommended = {
|
|
|
186
186
|
},
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'warn',
|
|
189
|
-
'no-criteria-xpath': '
|
|
190
|
-
'parameters-not-in-body': 'warn',
|
|
189
|
+
'no-criteria-xpath': 'off',
|
|
191
190
|
'parameters-unique': 'error',
|
|
192
191
|
'requestBody-replacements-unique': 'warn',
|
|
193
192
|
'sourceDescription-type': 'error',
|
|
@@ -196,7 +195,7 @@ const recommended = {
|
|
|
196
195
|
'stepId-unique': 'error',
|
|
197
196
|
'sourceDescription-name-unique': 'error',
|
|
198
197
|
'sourceDescriptions-not-empty': 'error',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'error',
|
|
202
201
|
},
|
package/lib/config/rules.js
CHANGED
|
@@ -15,16 +15,19 @@ function initRules(rules, config, type, oasVersion) {
|
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
17
|
const severity = ruleSettings.severity;
|
|
18
|
+
const message = ruleSettings.message;
|
|
18
19
|
const visitors = rule(ruleSettings);
|
|
19
20
|
if (Array.isArray(visitors)) {
|
|
20
21
|
return visitors.map((visitor) => ({
|
|
21
22
|
severity,
|
|
22
23
|
ruleId,
|
|
24
|
+
message,
|
|
23
25
|
visitor: visitor,
|
|
24
26
|
}));
|
|
25
27
|
}
|
|
26
28
|
return {
|
|
27
29
|
severity,
|
|
30
|
+
message,
|
|
28
31
|
ruleId,
|
|
29
32
|
visitor: visitors, // note: actually it is only one visitor object
|
|
30
33
|
};
|
package/lib/config/spec.js
CHANGED
|
@@ -11,9 +11,8 @@ const spec = {
|
|
|
11
11
|
async2Rules: {},
|
|
12
12
|
async3Rules: {},
|
|
13
13
|
arazzo1Rules: {
|
|
14
|
-
'parameters-not-in-body': 'error',
|
|
15
14
|
'sourceDescription-type': 'error',
|
|
16
|
-
'
|
|
15
|
+
'spot-supported-versions': 'off',
|
|
17
16
|
'workflowId-unique': 'error',
|
|
18
17
|
'stepId-unique': 'error',
|
|
19
18
|
'sourceDescription-name-unique': 'error',
|
|
@@ -23,7 +22,7 @@ const spec = {
|
|
|
23
22
|
'step-onSuccess-unique': 'error',
|
|
24
23
|
'step-onFailure-unique': 'error',
|
|
25
24
|
'requestBody-replacements-unique': 'error',
|
|
26
|
-
'no-criteria-xpath': '
|
|
25
|
+
'no-criteria-xpath': 'off',
|
|
27
26
|
'criteria-unique': 'error',
|
|
28
27
|
},
|
|
29
28
|
};
|
package/lib/config/types.d.ts
CHANGED
|
@@ -7,11 +7,10 @@ import type { JSONSchema } from 'json-schema-to-ts';
|
|
|
7
7
|
export type RuleSeverity = ProblemSeverity | 'off';
|
|
8
8
|
export type RuleSettings = {
|
|
9
9
|
severity: RuleSeverity;
|
|
10
|
+
message?: string;
|
|
10
11
|
};
|
|
11
12
|
export type PreprocessorSeverity = RuleSeverity | 'on';
|
|
12
|
-
export type RuleConfig = RuleSeverity | (
|
|
13
|
-
severity?: ProblemSeverity;
|
|
14
|
-
} & Record<string, any>);
|
|
13
|
+
export type RuleConfig = RuleSeverity | (Partial<RuleSettings> & Record<string, any>);
|
|
15
14
|
export type PreprocessorConfig = PreprocessorSeverity | ({
|
|
16
15
|
severity?: ProblemSeverity;
|
|
17
16
|
} & Record<string, any>);
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.preprocessors = exports.rules = void 0;
|
|
4
4
|
const struct_1 = require("../common/struct");
|
|
5
5
|
const assertions_1 = require("../common/assertions");
|
|
6
|
-
const parameters_not_in_body_1 = require("../spot/parameters-not-in-body");
|
|
7
6
|
const sourceDescription_type_1 = require("../arazzo/sourceDescription-type");
|
|
8
7
|
const sourceDescriptions_not_empty_1 = require("./sourceDescriptions-not-empty");
|
|
9
|
-
const
|
|
8
|
+
const spot_supported_versions_1 = require("../spot/spot-supported-versions");
|
|
10
9
|
const workflowId_unique_1 = require("./workflowId-unique");
|
|
11
10
|
const stepId_unique_1 = require("./stepId-unique");
|
|
12
11
|
const sourceDescriptions_name_unique_1 = require("./sourceDescriptions-name-unique");
|
|
@@ -20,9 +19,8 @@ const criteria_unique_1 = require("./criteria-unique");
|
|
|
20
19
|
exports.rules = {
|
|
21
20
|
struct: struct_1.Struct,
|
|
22
21
|
assertions: assertions_1.Assertions,
|
|
23
|
-
'parameters-not-in-body': parameters_not_in_body_1.ParametersNotInBody,
|
|
24
22
|
'sourceDescription-type': sourceDescription_type_1.SourceDescriptionType,
|
|
25
|
-
'
|
|
23
|
+
'spot-supported-versions': spot_supported_versions_1.SpotSupportedVersions,
|
|
26
24
|
'workflowId-unique': workflowId_unique_1.WorkflowIdUnique,
|
|
27
25
|
'stepId-unique': stepId_unique_1.StepIdUnique,
|
|
28
26
|
'sourceDescription-name-unique': sourceDescriptions_name_unique_1.SourceDescriptionsNameUnique,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SpotSupportedVersions = void 0;
|
|
4
4
|
const arazzo_1 = require("../../typings/arazzo");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
const
|
|
6
|
+
const SpotSupportedVersions = () => {
|
|
7
7
|
const supportedVersions = arazzo_1.ARAZZO_VERSIONS_SUPPORTED_BY_SPOT.join(', ');
|
|
8
8
|
return {
|
|
9
9
|
Root: {
|
|
@@ -18,4 +18,4 @@ const VersionEnum = () => {
|
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
exports.
|
|
21
|
+
exports.SpotSupportedVersions = SpotSupportedVersions;
|
|
@@ -9,7 +9,7 @@ declare const builtInAsync2Rules: readonly ["info-contact", "info-license-strict
|
|
|
9
9
|
declare const builtInAsync3Rules: readonly ["info-contact", "info-license-strict", "operation-operationId", "tag-description", "tags-alphabetical", "channels-kebab-case", "no-channel-trailing-slash"];
|
|
10
10
|
export type BuiltInAsync2RuleId = typeof builtInAsync2Rules[number];
|
|
11
11
|
export type BuiltInAsync3RuleId = typeof builtInAsync3Rules[number];
|
|
12
|
-
declare const builtInArazzo1Rules: readonly ["
|
|
12
|
+
declare const builtInArazzo1Rules: readonly ["sourceDescription-type", "workflowId-unique", "stepId-unique", "sourceDescription-name-unique", "sourceDescriptions-not-empty", "workflow-dependsOn", "parameters-unique", "step-onSuccess-unique", "step-onFailure-unique", "spot-supported-versions", "requestBody-replacements-unique", "no-criteria-xpath", "criteria-unique"];
|
|
13
13
|
export type BuiltInArazzo1RuleId = typeof builtInArazzo1Rules[number];
|
|
14
14
|
declare const oas2NodeTypesList: readonly ["Root", "Tag", "TagList", "ExternalDocs", "SecurityRequirement", "SecurityRequirementList", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "ParameterList", "ParameterItems", "Operation", "Example", "ExamplesMap", "Examples", "Header", "Responses", "Response", "Schema", "Xml", "SchemaProperties", "NamedSchemas", "NamedResponses", "NamedParameters", "NamedSecuritySchemes", "SecurityScheme", "TagGroup", "TagGroups", "EnumDescriptions", "Logo", "XCodeSample", "XCodeSampleList", "XServer", "XServerList"];
|
|
15
15
|
export type Oas2NodeType = typeof oas2NodeTypesList[number];
|
|
@@ -128,9 +128,7 @@ const builtInAsync3Rules = [
|
|
|
128
128
|
'no-channel-trailing-slash',
|
|
129
129
|
];
|
|
130
130
|
const builtInArazzo1Rules = [
|
|
131
|
-
'parameters-not-in-body',
|
|
132
131
|
'sourceDescription-type',
|
|
133
|
-
'version-enum',
|
|
134
132
|
'workflowId-unique',
|
|
135
133
|
'stepId-unique',
|
|
136
134
|
'sourceDescription-name-unique',
|
|
@@ -139,6 +137,7 @@ const builtInArazzo1Rules = [
|
|
|
139
137
|
'parameters-unique',
|
|
140
138
|
'step-onSuccess-unique',
|
|
141
139
|
'step-onFailure-unique',
|
|
140
|
+
'spot-supported-versions',
|
|
142
141
|
'requestBody-replacements-unique',
|
|
143
142
|
'no-criteria-xpath',
|
|
144
143
|
'criteria-unique',
|
package/lib/visitors.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
|
23
23
|
export type VisitorNode<T> = {
|
|
24
24
|
ruleId: string;
|
|
25
25
|
severity: ProblemSeverity;
|
|
26
|
+
message?: string;
|
|
26
27
|
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
|
27
28
|
depth: number;
|
|
28
29
|
visit: VisitFunction<T>;
|
|
@@ -31,6 +32,7 @@ export type VisitorNode<T> = {
|
|
|
31
32
|
type VisitorRefNode = {
|
|
32
33
|
ruleId: string;
|
|
33
34
|
severity: ProblemSeverity;
|
|
35
|
+
message?: string;
|
|
34
36
|
context: VisitorLevelContext;
|
|
35
37
|
depth: number;
|
|
36
38
|
visit: VisitRefFunction;
|
|
@@ -219,6 +221,7 @@ export type OasDecorator = Oas3Decorator;
|
|
|
219
221
|
export type RuleInstanceConfig = {
|
|
220
222
|
ruleId: string;
|
|
221
223
|
severity: ProblemSeverity;
|
|
224
|
+
message?: string;
|
|
222
225
|
};
|
|
223
226
|
export declare function normalizeVisitors<T extends BaseVisitor>(visitorsConfig: (RuleInstanceConfig & {
|
|
224
227
|
visitor: NestedVisitObject<unknown, T>;
|
package/lib/visitors.js
CHANGED
|
@@ -31,8 +31,8 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
31
31
|
enter: [],
|
|
32
32
|
leave: [],
|
|
33
33
|
};
|
|
34
|
-
for (const { ruleId, severity, visitor } of visitorsConfig) {
|
|
35
|
-
normalizeVisitorLevel({ ruleId, severity }, visitor, null);
|
|
34
|
+
for (const { ruleId, severity, message, visitor } of visitorsConfig) {
|
|
35
|
+
normalizeVisitorLevel({ ruleId, severity, message }, visitor, null);
|
|
36
36
|
}
|
|
37
37
|
for (const v of Object.keys(normalizedVisitors)) {
|
|
38
38
|
normalizedVisitors[v].enter.sort((a, b) => b.depth - a.depth);
|
package/lib/walk.js
CHANGED
|
@@ -54,9 +54,9 @@ function walkDocument(opts) {
|
|
|
54
54
|
const enteredContexts = new Set();
|
|
55
55
|
if ((0, ref_utils_1.isRef)(node)) {
|
|
56
56
|
const refEnterVisitors = normalizedVisitors.ref.enter;
|
|
57
|
-
for (const { visit: visitor, ruleId, severity, context } of refEnterVisitors) {
|
|
57
|
+
for (const { visit: visitor, ruleId, severity, message, context } of refEnterVisitors) {
|
|
58
58
|
enteredContexts.add(context);
|
|
59
|
-
const report = reportFn.bind(undefined, ruleId, severity);
|
|
59
|
+
const report = reportFn.bind(undefined, ruleId, severity, message);
|
|
60
60
|
visitor(node, {
|
|
61
61
|
report,
|
|
62
62
|
resolve,
|
|
@@ -82,7 +82,7 @@ function walkDocument(opts) {
|
|
|
82
82
|
const anyEnterVisitors = normalizedVisitors.any.enter;
|
|
83
83
|
const currentEnterVisitors = anyEnterVisitors.concat(normalizedVisitors[type.name]?.enter || []);
|
|
84
84
|
const activatedContexts = [];
|
|
85
|
-
for (const { context, visit, skip, ruleId, severity } of currentEnterVisitors) {
|
|
85
|
+
for (const { context, visit, skip, ruleId, severity, message } of currentEnterVisitors) {
|
|
86
86
|
if (ignoredNodes.has(`${currentLocation.absolutePointer}${currentLocation.pointer}`))
|
|
87
87
|
break;
|
|
88
88
|
if (context.isSkippedLevel) {
|
|
@@ -127,7 +127,7 @@ function walkDocument(opts) {
|
|
|
127
127
|
if (!activatedOn.skipped) {
|
|
128
128
|
visitedBySome = true;
|
|
129
129
|
enteredContexts.add(context);
|
|
130
|
-
visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
|
|
130
|
+
visitWithContext(visit, resolvedNode, node, context, ruleId, severity, message);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -209,18 +209,18 @@ function walkDocument(opts) {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
for (const { context, visit, ruleId, severity } of currentLeaveVisitors) {
|
|
212
|
+
for (const { context, visit, ruleId, severity, message } of currentLeaveVisitors) {
|
|
213
213
|
if (!context.isSkippedLevel && enteredContexts.has(context)) {
|
|
214
|
-
visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
|
|
214
|
+
visitWithContext(visit, resolvedNode, node, context, ruleId, severity, message);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
currentLocation = location;
|
|
219
219
|
if ((0, ref_utils_1.isRef)(node)) {
|
|
220
220
|
const refLeaveVisitors = normalizedVisitors.ref.leave;
|
|
221
|
-
for (const { visit: visitor, ruleId, severity, context } of refLeaveVisitors) {
|
|
221
|
+
for (const { visit: visitor, ruleId, severity, context, message } of refLeaveVisitors) {
|
|
222
222
|
if (enteredContexts.has(context)) {
|
|
223
|
-
const report = reportFn.bind(undefined, ruleId, severity);
|
|
223
|
+
const report = reportFn.bind(undefined, ruleId, severity, message);
|
|
224
224
|
visitor(node, {
|
|
225
225
|
report,
|
|
226
226
|
resolve,
|
|
@@ -238,8 +238,8 @@ function walkDocument(opts) {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
// returns true ignores all the next visitors on the specific node
|
|
241
|
-
function visitWithContext(visit, resolvedNode, node, context, ruleId, severity) {
|
|
242
|
-
const report = reportFn.bind(undefined, ruleId, severity);
|
|
241
|
+
function visitWithContext(visit, resolvedNode, node, context, ruleId, severity, customMessage) {
|
|
242
|
+
const report = reportFn.bind(undefined, ruleId, severity, customMessage);
|
|
243
243
|
visit(resolvedNode, {
|
|
244
244
|
report,
|
|
245
245
|
resolve,
|
|
@@ -257,7 +257,7 @@ function walkDocument(opts) {
|
|
|
257
257
|
getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
|
|
258
258
|
}, collectParents(context), context);
|
|
259
259
|
}
|
|
260
|
-
function reportFn(ruleId, severity, opts) {
|
|
260
|
+
function reportFn(ruleId, severity, customMessage, opts) {
|
|
261
261
|
const normalizedLocation = opts.location
|
|
262
262
|
? Array.isArray(opts.location)
|
|
263
263
|
? opts.location
|
|
@@ -274,6 +274,9 @@ function walkDocument(opts) {
|
|
|
274
274
|
ruleId: opts.ruleId || ruleId,
|
|
275
275
|
severity: ruleSeverity,
|
|
276
276
|
...opts,
|
|
277
|
+
message: customMessage
|
|
278
|
+
? customMessage.replace('{{message}}', opts.message)
|
|
279
|
+
: opts.message,
|
|
277
280
|
suggest: opts.suggest || [],
|
|
278
281
|
location,
|
|
279
282
|
});
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { BaseResolver, Document } from '../resolve';
|
|
13
13
|
import { listOf } from '../types';
|
|
14
14
|
import { Oas3RuleSet } from '../oas-types';
|
|
15
|
+
import { createConfig } from '../config';
|
|
15
16
|
|
|
16
17
|
describe('walk order', () => {
|
|
17
18
|
it('should run visitors', async () => {
|
|
@@ -1338,6 +1339,56 @@ describe('context.report', () => {
|
|
|
1338
1339
|
]
|
|
1339
1340
|
`);
|
|
1340
1341
|
});
|
|
1342
|
+
|
|
1343
|
+
it('should report errors with custom messages', async () => {
|
|
1344
|
+
const document = parseYamlToDocument(
|
|
1345
|
+
outdent`
|
|
1346
|
+
openapi: 3.0.0
|
|
1347
|
+
info:
|
|
1348
|
+
license: {}
|
|
1349
|
+
paths: {}
|
|
1350
|
+
`,
|
|
1351
|
+
'foobar.yaml'
|
|
1352
|
+
);
|
|
1353
|
+
|
|
1354
|
+
const config = await createConfig(`
|
|
1355
|
+
rules:
|
|
1356
|
+
info-contact:
|
|
1357
|
+
message: "MY ERR DESCRIPTION: {{message}}"
|
|
1358
|
+
severity: "error"
|
|
1359
|
+
`);
|
|
1360
|
+
|
|
1361
|
+
const results = await lintDocument({
|
|
1362
|
+
externalRefResolver: new BaseResolver(),
|
|
1363
|
+
document,
|
|
1364
|
+
config: config.styleguide,
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1367
|
+
expect(results).toMatchInlineSnapshot(`
|
|
1368
|
+
[
|
|
1369
|
+
{
|
|
1370
|
+
"location": [
|
|
1371
|
+
{
|
|
1372
|
+
"pointer": "#/info/contact",
|
|
1373
|
+
"reportOnKey": true,
|
|
1374
|
+
"source": Source {
|
|
1375
|
+
"absoluteRef": "foobar.yaml",
|
|
1376
|
+
"body": "openapi: 3.0.0
|
|
1377
|
+
info:
|
|
1378
|
+
license: {}
|
|
1379
|
+
paths: {}",
|
|
1380
|
+
"mimeType": undefined,
|
|
1381
|
+
},
|
|
1382
|
+
},
|
|
1383
|
+
],
|
|
1384
|
+
"message": "MY ERR DESCRIPTION: Info object should contain \`contact\` field.",
|
|
1385
|
+
"ruleId": "info-contact",
|
|
1386
|
+
"severity": "error",
|
|
1387
|
+
"suggest": [],
|
|
1388
|
+
},
|
|
1389
|
+
]
|
|
1390
|
+
`);
|
|
1391
|
+
});
|
|
1341
1392
|
});
|
|
1342
1393
|
|
|
1343
1394
|
describe('context.resolve', () => {
|
|
@@ -6,17 +6,16 @@ exports[`resolveConfig should ignore minimal from the root and read local file 1
|
|
|
6
6
|
"arazzo1Preprocessors": {},
|
|
7
7
|
"arazzo1Rules": {
|
|
8
8
|
"criteria-unique": "warn",
|
|
9
|
-
"no-criteria-xpath": "
|
|
10
|
-
"parameters-not-in-body": "warn",
|
|
9
|
+
"no-criteria-xpath": "off",
|
|
11
10
|
"parameters-unique": "error",
|
|
12
11
|
"requestBody-replacements-unique": "warn",
|
|
13
12
|
"sourceDescription-name-unique": "error",
|
|
14
13
|
"sourceDescription-type": "error",
|
|
15
14
|
"sourceDescriptions-not-empty": "error",
|
|
15
|
+
"spot-supported-versions": "off",
|
|
16
16
|
"step-onFailure-unique": "warn",
|
|
17
17
|
"step-onSuccess-unique": "warn",
|
|
18
18
|
"stepId-unique": "error",
|
|
19
|
-
"version-enum": "warn",
|
|
20
19
|
"workflow-dependsOn": "error",
|
|
21
20
|
"workflowId-unique": "error",
|
|
22
21
|
},
|
|
@@ -233,17 +232,16 @@ exports[`resolveStyleguideConfig should resolve extends with local file config w
|
|
|
233
232
|
"arazzo1Preprocessors": {},
|
|
234
233
|
"arazzo1Rules": {
|
|
235
234
|
"criteria-unique": "warn",
|
|
236
|
-
"no-criteria-xpath": "
|
|
237
|
-
"parameters-not-in-body": "warn",
|
|
235
|
+
"no-criteria-xpath": "off",
|
|
238
236
|
"parameters-unique": "error",
|
|
239
237
|
"requestBody-replacements-unique": "warn",
|
|
240
238
|
"sourceDescription-name-unique": "error",
|
|
241
239
|
"sourceDescription-type": "error",
|
|
242
240
|
"sourceDescriptions-not-empty": "error",
|
|
241
|
+
"spot-supported-versions": "off",
|
|
243
242
|
"step-onFailure-unique": "warn",
|
|
244
243
|
"step-onSuccess-unique": "warn",
|
|
245
244
|
"stepId-unique": "error",
|
|
246
|
-
"version-enum": "warn",
|
|
247
245
|
"workflow-dependsOn": "error",
|
|
248
246
|
"workflowId-unique": "error",
|
|
249
247
|
},
|
package/src/config/all.ts
CHANGED
|
@@ -210,8 +210,7 @@ const all: PluginStyleguideConfig<'built-in'> = {
|
|
|
210
210
|
},
|
|
211
211
|
arazzo1Rules: {
|
|
212
212
|
'criteria-unique': 'error',
|
|
213
|
-
'no-criteria-xpath': '
|
|
214
|
-
'parameters-not-in-body': 'error',
|
|
213
|
+
'no-criteria-xpath': 'off',
|
|
215
214
|
'parameters-unique': 'error',
|
|
216
215
|
'requestBody-replacements-unique': 'error',
|
|
217
216
|
'sourceDescription-type': 'error',
|
|
@@ -220,7 +219,7 @@ const all: PluginStyleguideConfig<'built-in'> = {
|
|
|
220
219
|
'stepId-unique': 'error',
|
|
221
220
|
'sourceDescription-name-unique': 'error',
|
|
222
221
|
'sourceDescriptions-not-empty': 'error',
|
|
223
|
-
'
|
|
222
|
+
'spot-supported-versions': 'off',
|
|
224
223
|
'workflowId-unique': 'error',
|
|
225
224
|
'workflow-dependsOn': 'error',
|
|
226
225
|
},
|
package/src/config/minimal.ts
CHANGED
|
@@ -187,7 +187,6 @@ const minimal: PluginStyleguideConfig<'built-in'> = {
|
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'off',
|
|
189
189
|
'no-criteria-xpath': 'off',
|
|
190
|
-
'parameters-not-in-body': 'off',
|
|
191
190
|
'parameters-unique': 'off',
|
|
192
191
|
'requestBody-replacements-unique': 'off',
|
|
193
192
|
'sourceDescription-type': 'off',
|
|
@@ -196,7 +195,7 @@ const minimal: PluginStyleguideConfig<'built-in'> = {
|
|
|
196
195
|
'step-onFailure-unique': 'off',
|
|
197
196
|
'stepId-unique': 'error',
|
|
198
197
|
'sourceDescription-name-unique': 'off',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'off',
|
|
202
201
|
},
|
|
@@ -186,8 +186,7 @@ const recommendedStrict: PluginStyleguideConfig<'built-in'> = {
|
|
|
186
186
|
},
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'error',
|
|
189
|
-
'no-criteria-xpath': '
|
|
190
|
-
'parameters-not-in-body': 'error',
|
|
189
|
+
'no-criteria-xpath': 'off',
|
|
191
190
|
'parameters-unique': 'error',
|
|
192
191
|
'requestBody-replacements-unique': 'error',
|
|
193
192
|
'sourceDescription-type': 'error',
|
|
@@ -196,7 +195,7 @@ const recommendedStrict: PluginStyleguideConfig<'built-in'> = {
|
|
|
196
195
|
'stepId-unique': 'error',
|
|
197
196
|
'sourceDescription-name-unique': 'error',
|
|
198
197
|
'sourceDescriptions-not-empty': 'error',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'error',
|
|
202
201
|
},
|
|
@@ -186,8 +186,7 @@ const recommended: PluginStyleguideConfig<'built-in'> = {
|
|
|
186
186
|
},
|
|
187
187
|
arazzo1Rules: {
|
|
188
188
|
'criteria-unique': 'warn',
|
|
189
|
-
'no-criteria-xpath': '
|
|
190
|
-
'parameters-not-in-body': 'warn',
|
|
189
|
+
'no-criteria-xpath': 'off',
|
|
191
190
|
'parameters-unique': 'error',
|
|
192
191
|
'requestBody-replacements-unique': 'warn',
|
|
193
192
|
'sourceDescription-type': 'error',
|
|
@@ -196,7 +195,7 @@ const recommended: PluginStyleguideConfig<'built-in'> = {
|
|
|
196
195
|
'stepId-unique': 'error',
|
|
197
196
|
'sourceDescription-name-unique': 'error',
|
|
198
197
|
'sourceDescriptions-not-empty': 'error',
|
|
199
|
-
'
|
|
198
|
+
'spot-supported-versions': 'off',
|
|
200
199
|
'workflowId-unique': 'error',
|
|
201
200
|
'workflow-dependsOn': 'error',
|
|
202
201
|
},
|
package/src/config/rules.ts
CHANGED
|
@@ -39,19 +39,21 @@ export function initRules(
|
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
41
|
const severity: ProblemSeverity = ruleSettings.severity;
|
|
42
|
-
|
|
42
|
+
const message = ruleSettings.message;
|
|
43
43
|
const visitors = rule(ruleSettings);
|
|
44
44
|
|
|
45
45
|
if (Array.isArray(visitors)) {
|
|
46
46
|
return visitors.map((visitor: any) => ({
|
|
47
47
|
severity,
|
|
48
48
|
ruleId,
|
|
49
|
+
message,
|
|
49
50
|
visitor: visitor,
|
|
50
51
|
}));
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
return {
|
|
54
55
|
severity,
|
|
56
|
+
message,
|
|
55
57
|
ruleId,
|
|
56
58
|
visitor: visitors, // note: actually it is only one visitor object
|
|
57
59
|
};
|
package/src/config/spec.ts
CHANGED
|
@@ -11,9 +11,8 @@ const spec: PluginStyleguideConfig<'built-in'> = {
|
|
|
11
11
|
async2Rules: {},
|
|
12
12
|
async3Rules: {},
|
|
13
13
|
arazzo1Rules: {
|
|
14
|
-
'parameters-not-in-body': 'error',
|
|
15
14
|
'sourceDescription-type': 'error',
|
|
16
|
-
'
|
|
15
|
+
'spot-supported-versions': 'off',
|
|
17
16
|
'workflowId-unique': 'error',
|
|
18
17
|
'stepId-unique': 'error',
|
|
19
18
|
'sourceDescription-name-unique': 'error',
|
|
@@ -23,7 +22,7 @@ const spec: PluginStyleguideConfig<'built-in'> = {
|
|
|
23
22
|
'step-onSuccess-unique': 'error',
|
|
24
23
|
'step-onFailure-unique': 'error',
|
|
25
24
|
'requestBody-replacements-unique': 'error',
|
|
26
|
-
'no-criteria-xpath': '
|
|
25
|
+
'no-criteria-xpath': 'off',
|
|
27
26
|
'criteria-unique': 'error',
|
|
28
27
|
},
|
|
29
28
|
};
|
package/src/config/types.ts
CHANGED
|
@@ -26,15 +26,11 @@ import type { JSONSchema } from 'json-schema-to-ts';
|
|
|
26
26
|
|
|
27
27
|
export type RuleSeverity = ProblemSeverity | 'off';
|
|
28
28
|
|
|
29
|
-
export type RuleSettings = { severity: RuleSeverity };
|
|
29
|
+
export type RuleSettings = { severity: RuleSeverity; message?: string };
|
|
30
30
|
|
|
31
31
|
export type PreprocessorSeverity = RuleSeverity | 'on';
|
|
32
32
|
|
|
33
|
-
export type RuleConfig =
|
|
34
|
-
| RuleSeverity
|
|
35
|
-
| ({
|
|
36
|
-
severity?: ProblemSeverity;
|
|
37
|
-
} & Record<string, any>);
|
|
33
|
+
export type RuleConfig = RuleSeverity | (Partial<RuleSettings> & Record<string, any>);
|
|
38
34
|
|
|
39
35
|
export type PreprocessorConfig =
|
|
40
36
|
| PreprocessorSeverity
|
|
@@ -3,7 +3,7 @@ import { lintDocument } from '../../../lint';
|
|
|
3
3
|
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
4
|
import { BaseResolver } from '../../../resolve';
|
|
5
5
|
|
|
6
|
-
describe('Arazzo
|
|
6
|
+
describe('Arazzo spot-supported-versions', () => {
|
|
7
7
|
const document = parseYamlToDocument(
|
|
8
8
|
outdent`
|
|
9
9
|
arazzo: '1.0.1'
|
|
@@ -38,7 +38,7 @@ describe('Arazzo version-enum', () => {
|
|
|
38
38
|
externalRefResolver: new BaseResolver(),
|
|
39
39
|
document,
|
|
40
40
|
config: await makeConfig({
|
|
41
|
-
rules: { '
|
|
41
|
+
rules: { 'spot-supported-versions': 'error' },
|
|
42
42
|
}),
|
|
43
43
|
});
|
|
44
44
|
|
|
@@ -53,7 +53,7 @@ describe('Arazzo version-enum', () => {
|
|
|
53
53
|
},
|
|
54
54
|
],
|
|
55
55
|
"message": "Only 1.0.0 Arazzo version is supported by Spot.",
|
|
56
|
-
"ruleId": "
|
|
56
|
+
"ruleId": "spot-supported-versions",
|
|
57
57
|
"severity": "error",
|
|
58
58
|
"suggest": [],
|
|
59
59
|
},
|