Skip to content

Commit d3b721a

Browse files
authored
CLOUDP 328959: OperationID Validation functions for Create, Delete, and Update methods (#805)
1 parent 5a872a1 commit d3b721a

14 files changed

+452
-8
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"precommit": "husky install"
1515
},
1616
"jest": {
17-
"transformIgnorePatterns": [
18-
"/node_modules/(?!ember-inflector/)"
19-
],
2017
"transform": {
2118
"^.+\\.[t|j]sx?$": "babel-jest"
2219
},
@@ -36,6 +33,7 @@
3633
"dotenv": "^17.0.1",
3734
"ember-inflector": "^6.0.0",
3835
"eslint-plugin-jest": "^29.0.1",
36+
"inflection": "^3.0.2",
3937
"markdown-table": "^3.0.4",
4038
"openapi-to-postmanv2": "5.0.0",
4139
"parquet-wasm": "^0.6.1"
@@ -49,14 +47,14 @@
4947
"aws-sdk-client-mock": "^4.1.0",
5048
"babel-jest": "^30.0.2",
5149
"babel-plugin-transform-import-meta": "^2.3.3",
50+
"brace-expansion": "4.0.1",
5251
"eslint": "^9.30.1",
5352
"eslint-plugin-require-extensions": "^0.1.3",
5453
"globals": "^16.3.0",
5554
"husky": "^9.1.7",
5655
"jest": "^30.0.4",
5756
"lint-staged": "^16.1.2",
58-
"prettier": "3.6.2",
59-
"brace-expansion": "4.0.1"
57+
"prettier": "3.6.2"
6058
},
6159
"engineStrict": false,
6260
"engines": {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import testRule from './__helpers__/testRule';
2+
3+
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
4+
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
5+
6+
testRule('xgen-IPA-106-valid-operation-id', [
7+
{
8+
name: 'valid methods',
9+
document: {
10+
paths: {
11+
'/groups/{groupId}/clusters': {
12+
post: {
13+
operationId: 'createGroupCluster',
14+
},
15+
},
16+
},
17+
},
18+
errors: [],
19+
},
20+
// This test will be enable when the xgen-IPA-106-valid-operation-id is set to warning severity - CLOUDP-329722
21+
/* {
22+
name: 'invalid methods',
23+
document: {
24+
paths: {
25+
'/api/atlas/v2/groups/{groupId}/access': {
26+
post: {
27+
operationId: 'addUserToProject',
28+
},
29+
},
30+
'/api/atlas/v2/groups/{groupId}/invites': {
31+
post: {
32+
operationId: 'createProjectInvitation',
33+
},
34+
},
35+
},
36+
},
37+
errors: [
38+
{
39+
code: 'xgen-IPA-106-valid-operation-id',
40+
message:
41+
'Invalid OperationID. The Operation ID must start with the verb “create” 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. ',
42+
path: ['paths', '/api/atlas/v2/groups/{groupId}/access', 'post'],
43+
severity: DiagnosticSeverity.Warning,
44+
},
45+
{
46+
code: 'xgen-IPA-106-valid-operation-id',
47+
message:
48+
'Invalid OperationID. The Operation ID must start with the verb “create” 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. ',
49+
path: ['paths', '/api/atlas/v2/groups/{groupId}/invites', 'post'],
50+
severity: DiagnosticSeverity.Warning,
51+
},
52+
],
53+
}, */
54+
{
55+
name: 'invalid methods with exceptions',
56+
document: {
57+
paths: {
58+
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
59+
post: {
60+
operationId: 'createRollingIndex',
61+
'x-xgen-IPA-exception': {
62+
'xgen-IPA-106-valid-operation-id': 'Reason',
63+
},
64+
},
65+
},
66+
},
67+
},
68+
errors: [],
69+
},
70+
]);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import testRule from './__helpers__/testRule';
2+
3+
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
4+
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
5+
6+
testRule('xgen-IPA-107-valid-operation-id', [
7+
{
8+
name: 'valid methods',
9+
document: {
10+
paths: {
11+
'groups/{groupId}/clusters/{clusterName}': {
12+
put: {
13+
operationId: 'updateGroupCluster',
14+
},
15+
},
16+
'/groups/{groupId}/settings': {
17+
put: {
18+
operationId: 'updateGroupSettings',
19+
},
20+
},
21+
},
22+
},
23+
errors: [],
24+
},
25+
// This test will be enable when the xgen-IPA-107-valid-operation-id is set to warning severity - CLOUDP-329722
26+
/* {
27+
name: 'invalid methods',
28+
document: {
29+
paths: {
30+
'/api/atlas/v2/groups/{groupId}/limits/{limitName}': {
31+
patch: {
32+
operationId: 'setProjectLimit',
33+
},
34+
},
35+
'/api/atlas/v2/groups/{groupId}/settings': {
36+
put: {
37+
operationId: 'updateProjectSettings',
38+
},
39+
},
40+
},
41+
},
42+
errors: [
43+
{
44+
code: 'xgen-IPA-107-valid-operation-id',
45+
message:
46+
'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.',
47+
path: ['paths', '/api/atlas/v2/groups/{groupId}/limits/{limitName}', 'patch'],
48+
severity: DiagnosticSeverity.Warning,
49+
},
50+
{
51+
code: 'xgen-IPA-107-valid-operation-id',
52+
message:
53+
'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.',
54+
path: ['paths', '/api/atlas/v2/groups/{groupId}/settings', 'put'],
55+
severity: DiagnosticSeverity.Warning,
56+
},
57+
],
58+
}, */
59+
{
60+
name: 'invalid methods with exceptions',
61+
document: {
62+
paths: {
63+
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
64+
post: {
65+
operationId: 'updateRollingIndex',
66+
'x-xgen-IPA-exception': {
67+
'xgen-IPA-107-valid-operation-id': 'Reason',
68+
},
69+
},
70+
},
71+
},
72+
},
73+
errors: [],
74+
},
75+
]);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import testRule from './__helpers__/testRule';
2+
3+
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
4+
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
5+
6+
testRule('xgen-IPA-108-valid-operation-id', [
7+
{
8+
name: 'valid methods',
9+
document: {
10+
paths: {
11+
'/groups/{groupId}/clusters/{clusterName}': {
12+
delete: {
13+
operationId: 'deleteGroupCluster',
14+
},
15+
},
16+
},
17+
},
18+
errors: [],
19+
},
20+
// This test will be enable when the xgen-IPA-108-valid-operation-id is set to warning severity - CLOUDP-329722
21+
/* {
22+
name: 'invalid methods',
23+
document: {
24+
paths: {
25+
'/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}': {
26+
delete: {
27+
operationId: 'removeProjectApiKey',
28+
},
29+
},
30+
'/api/atlas/v2/groups/{groupId}': {
31+
delete: {
32+
operationId: 'deleteProject',
33+
},
34+
},
35+
},
36+
},
37+
errors: [
38+
{
39+
code: 'xgen-IPA-108-valid-operation-id',
40+
message:
41+
'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. ',
42+
path: ['paths', '/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}', 'delete'],
43+
severity: DiagnosticSeverity.Warning,
44+
},
45+
{
46+
code: 'xgen-IPA-108-valid-operation-id',
47+
message:
48+
'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. ',
49+
path: ['paths', '/api/atlas/v2/groups/{groupId}', 'delete'],
50+
severity: DiagnosticSeverity.Warning,
51+
},
52+
],
53+
}, */
54+
{
55+
name: 'invalid methods with exceptions',
56+
document: {
57+
paths: {
58+
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
59+
post: {
60+
operationId: 'deleteRollingIndex',
61+
'x-xgen-IPA-exception': {
62+
'xgen-IPA-108-valid-operation-id': 'Reason',
63+
},
64+
},
65+
},
66+
},
67+
},
68+
errors: [],
69+
},
70+
]);

tools/spectral/ipa/rulesets/IPA-106.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ functions:
88
- IPA106CreateMethodRequestHasNoReadonlyFields
99
- IPA106CreateMethodResponseCodeIs201Created
1010
- IPA106CreateMethodResponseIsGetMethodResponse
11+
- IPA106ValidOperationID
1112

1213
aliases:
1314
CreateOperationObject:
@@ -112,3 +113,20 @@ rules:
112113
then:
113114
field: '@key'
114115
function: 'IPA106CreateMethodResponseIsGetMethodResponse'
116+
xgen-IPA-106-valid-operation-id:
117+
description: |
118+
The Operation ID must start with the verb “create” and should be followed by a noun or compound noun.
119+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form.
120+
121+
##### Implementation details
122+
Rule checks for the following conditions:
123+
- Applies only to POST methods on resource collection paths
124+
- Generates the expected OperationId given the resource identifier
125+
- Confirms that the existing operationId is compliant with generated IPA Compliant OperationId
126+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-valid-operation-id'
127+
severity: off
128+
given: '#CreateOperationObject'
129+
then:
130+
function: 'IPA106ValidOperationID'
131+
functionOptions:
132+
methodName: 'create'

tools/spectral/ipa/rulesets/IPA-107.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ functions:
88
- IPA107UpdateMethodRequestHasNoReadonlyFields
99
- IPA107UpdateMethodRequestBodyIsGetResponse
1010
- IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject
11+
- IPA107ValidOperationID
1112

1213
aliases:
1314
UpdateOperationObject:
@@ -112,3 +113,21 @@ rules:
112113
then:
113114
field: '@key'
114115
function: 'IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject'
116+
xgen-IPA-107-valid-operation-id:
117+
description: |
118+
The Operation ID must start with the verb “update” and should be followed by a noun or compound noun.
119+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form.
120+
If the resource is a singleton resource, the last noun may be the plural form of the collection identifier.
121+
122+
##### Implementation details
123+
Rule checks for the following conditions:
124+
- Validation checks the PATCH/PUT methods for single resource paths and [singleton resources](https://go/ipa/113).
125+
- Generates the expected OperationId given the resource identifier
126+
- Confirms that the existing operationId is compliant with generated IPA Compliant OperationId
127+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-valid-operation-id'
128+
severity: off
129+
given: '#UpdateOperationObject'
130+
then:
131+
function: 'IPA107ValidOperationID'
132+
functionOptions:
133+
methodName: 'update'

tools/spectral/ipa/rulesets/IPA-108.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,26 @@ rules:
5555
given: '#DeleteOperationObject'
5656
then:
5757
function: IPA108DeleteMethodNoRequestBody
58+
xgen-IPA-108-valid-operation-id:
59+
description: |
60+
The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun.
61+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form.
62+
63+
##### Implementation details
64+
Rule checks for the following conditions:
65+
- Applies to all DELETE methods for single resource endpoints (with path parameters)
66+
- Generates the expected OperationId given the resource identifier
67+
- Confirms that the existing operationId is compliant with generated IPA Compliant OperationId
68+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-valid-operation-id'
69+
severity: off
70+
given: '#DeleteOperationObject'
71+
then:
72+
function: 'IPA108ValidOperationID'
73+
functionOptions:
74+
methodName: 'delete'
5875

5976
functions:
6077
- IPA108DeleteMethodResponseShouldNotHaveSchema
6178
- IPA108DeleteMethod204Response
6279
- IPA108DeleteMethodNoRequestBody
80+
- IPA108ValidOperationID

0 commit comments

Comments
 (0)