Skip to content

Commit fcef3e4

Browse files
author
Sophia Marie Terry
committed
CLOUDP-328959: Added tests for validating IPA107 valid operationIds
1 parent bb78336 commit fcef3e4

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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-107-valid-operation-id', [
17+
{
18+
name: 'valid methods',
19+
document: {
20+
components: componentSchemas,
21+
paths: {
22+
'groups/{groupId}/clusters/{clusterName}': {
23+
put: {
24+
operationId: 'updateGroupCluster',
25+
},
26+
},
27+
'/groups/{groupId}/settings': {
28+
put: {
29+
operationId: 'updateGroupSettings',
30+
},
31+
},
32+
},
33+
},
34+
errors: [],
35+
},
36+
// This test will be enable when the xgen-IPA-107-valid-operation-id is set to warning severity - CLOUDP-329722
37+
/* {
38+
name: 'invalid methods',
39+
document: {
40+
components: componentSchemas,
41+
paths: {
42+
'/api/atlas/v2/groups/{groupId}/limits/{limitName}': {
43+
patch: {
44+
operationId: 'setProjectLimit',
45+
},
46+
},
47+
'/api/atlas/v2/groups/{groupId}/settings': {
48+
put: {
49+
operationId: 'updateProjectSettings',
50+
},
51+
},
52+
},
53+
},
54+
errors: [
55+
{
56+
code: 'xgen-IPA-107-valid-operation-id',
57+
message:
58+
'Invalid OperationID. The Operation ID must start with the verb “update” 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. For singleton resources - the last noun may be in plural form.',
59+
path: ['paths', '/api/atlas/v2/groups/{groupId}/limits/{limitName}', 'patch'],
60+
severity: DiagnosticSeverity.Warning,
61+
},
62+
{
63+
code: 'xgen-IPA-107-valid-operation-id',
64+
message:
65+
'Invalid OperationID. The Operation ID must start with the verb “update” 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. For singleton resources - the last noun may be in plural form.',
66+
path: ['paths', '/api/atlas/v2/groups/{groupId}/settings', 'put'],
67+
severity: DiagnosticSeverity.Warning,
68+
},
69+
],
70+
}, */
71+
{
72+
name: 'invalid methods with exceptions',
73+
document: {
74+
components: componentSchemas,
75+
paths: {
76+
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
77+
post: {
78+
operationId: 'updateRollingIndex',
79+
'x-xgen-IPA-exception': {
80+
'xgen-IPA-107-valid-operation-id': 'Reason',
81+
},
82+
},
83+
},
84+
},
85+
},
86+
errors: [],
87+
},
88+
]);

tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import testRule from './__helpers__/testRule';
2-
import { DiagnosticSeverity } from '@stoplight/types';
32

43
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
54
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722

0 commit comments

Comments
 (0)