Skip to content

Commit 0f463dc

Browse files
author
Sophia Marie Terry
committed
Draft OperationID validation rules
1 parent b55f9d0 commit 0f463dc

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ functions:
88
- IPA104GetResponseCodeShouldBe200OK
99
- IPA104GetMethodResponseHasNoInputFields
1010
- IPA104GetMethodHasNoRequestBody
11+
- IPA104ValidOperationID
1112

1213
aliases:
1314
GetOperationObject:
@@ -97,3 +98,14 @@ rules:
9798
given: '#GetOperationObject'
9899
then:
99100
function: 'IPA104GetMethodHasNoRequestBody'
101+
xgen-IPA-104-valid-operation-id:
102+
description: |
103+
104+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-valid-operation-id'
105+
severity: warn
106+
given: '#GetOperationObject'
107+
then:
108+
function: 'IPA104ValidOperationID'
109+
functionOptions:
110+
methodName: 'get'
111+
prefixes: ['/api']

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ functions:
66
- IPA105ListMethodHasNoRequestBody
77
- IPA105EachResourceHasListMethod
88
- IPA105ListMethodResponseIsGetMethodResponse
9+
- IPA105ValidOperationID
910

1011
aliases:
1112
GetOperationObject:
@@ -77,3 +78,21 @@ rules:
7778
then:
7879
field: '@key'
7980
function: 'IPA105ListMethodResponseIsGetMethodResponse'
81+
xgen-IPA-105-valid-operation-id:
82+
description: |
83+
The Operation ID must start with the verb “list” and should be followed by a noun or compound noun.
84+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.
85+
86+
##### Implementation details
87+
Rule checks for the following conditions:
88+
- Applies only to GET methods on resource collection paths
89+
- Ignores singleton resources
90+
- Generates the expected OperationId given the resource identifier
91+
- Confirms that the existing operationId is compliant with generated IPA Compliant OperationId
92+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-valid-operation-id'
93+
severity: warn
94+
given: '#GetOperationObject'
95+
then:
96+
function: 'IPA105ValidOperationID'
97+
functionOptions:
98+
methodName: 'list'

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: warn
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: warn
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: warn
70+
given: '#DeleteOperationObject'
71+
then:
72+
function: 'IPA108ValidOperationID'
73+
functionOptions:
74+
methodName: 'delete'
5875

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,22 @@ rules:
5757
given: '$.paths[*]'
5858
then:
5959
function: 'IPA109CustomMethodIdentifierFormat'
60+
xgen-IPA-109-valid-operation-id:
61+
description: |
62+
The Operation ID must start with the custom method verb (the custom method path section delimited by the colon (:) character) and should be followed by a noun or compound noun.
63+
If the custom Operation ID has a verb + noun, the Operation ID should end with the noun.
64+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier.
65+
The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun:
66+
- Is in plural form if the method applies to a collection of resources
67+
- Is in singular form if the method applies to a single resource
68+
69+
##### Implementation details
70+
Rule checks for the following conditions:
71+
- Applies only to paths containing custom method identifiers (with colon format)
72+
- Generates the expected OperationId given the resource identifier and the method name portion following the colon
73+
- Confirms that the existing operationId is compliant with generated IPA Compliant OperationId
74+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-valid-operation-id'
75+
severity: warn
76+
given: '$.paths[*]'
77+
then:
78+
function: 'IPA109ValidOperationID'

0 commit comments

Comments
 (0)