Skip to content

Commit 277cb19

Browse files
author
Sophia Marie Terry
committed
CLOUDP-328959: Added tests for validating IPA108 valid operationIds
1 parent ff7df80 commit 277cb19

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
5+
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
6+
7+
const componentSchemas = {
8+
schemas: {
9+
Schema: {
10+
type: 'object',
11+
},
12+
},
13+
operationId: 'string',
14+
};
15+
16+
testRule('xgen-IPA-108-valid-operation-id', [
17+
{
18+
name: 'valid methods',
19+
document: {
20+
components: componentSchemas,
21+
paths: {
22+
'/groups/{groupId}/clusters/{clusterName}': {
23+
delete: {
24+
operationId: 'deleteGroupCluster',
25+
},
26+
},
27+
},
28+
},
29+
errors: [],
30+
},
31+
// This test will be enable when the xgen-IPA-108-valid-operation-id is set to warning severity - CLOUDP-329722
32+
{
33+
name: 'invalid methods',
34+
document: {
35+
components: componentSchemas,
36+
paths: {
37+
'/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}': {
38+
delete: {
39+
operationId: 'removeProjectApiKey',
40+
},
41+
},
42+
'/api/atlas/v2/groups/{groupId}': {
43+
delete: {
44+
operationId: 'deleteProject',
45+
},
46+
},
47+
},
48+
},
49+
errors: [
50+
{
51+
code: 'xgen-IPA-108-valid-operation-id',
52+
message:
53+
'Invalid OperationID. The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ',
54+
path: ['paths', '/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}', 'delete'],
55+
severity: DiagnosticSeverity.Warning,
56+
},
57+
{
58+
code: 'xgen-IPA-108-valid-operation-id',
59+
message:
60+
'Invalid OperationID. The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ',
61+
path: ['paths', '/api/atlas/v2/groups/{groupId}', 'delete'],
62+
severity: DiagnosticSeverity.Warning,
63+
},
64+
],
65+
},
66+
{
67+
name: 'invalid methods with exceptions',
68+
document: {
69+
components: componentSchemas,
70+
paths: {
71+
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
72+
post: {
73+
operationId: 'deleteRollingIndex',
74+
'x-xgen-IPA-exception': {
75+
'xgen-IPA-108-valid-operation-id': 'Reason',
76+
},
77+
},
78+
},
79+
},
80+
},
81+
errors: [],
82+
},
83+
]);

0 commit comments

Comments
 (0)