Skip to content

Commit 08dd612

Browse files
Second Rollout for IPA validations (#574)
1 parent ae7efcf commit 08dd612

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

.github/workflows/spectral-lint.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ on:
1414
- 'tools/spectral/**'
1515
- 'openapi/**.yaml'
1616
- 'package.json'
17+
permissions:
18+
issues: write
19+
contents: write
1720

1821
jobs:
1922
spectral-lint:
@@ -34,6 +37,9 @@ jobs:
3437
cache: 'npm'
3538
- name: Install npm dependencies
3639
run: npm install
40+
- name: Fetch OAS file from Dev Branch
41+
run: curl -O "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/.raw/v2.yaml"
42+
working-directory: ${{ github.workspace }}
3743
- name: Spectral action
3844
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
3945
with:
@@ -43,5 +49,5 @@ jobs:
4349
- name: IPA validation action
4450
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
4551
with:
46-
file_glob: openapi/.raw/v2.yaml
52+
file_glob: ${{ github.workspace }}//v2.yaml
4753
spectral_ruleset: tools/spectral/ipa/ipa-spectral.yaml

tools/spectral/ipa/__tests__/metrics/data/expected-metric-results.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rules:
2020
- For singleton resources, verifies the resource has a GET method
2121
- For regular resources, verifies there is a single resource path with a GET method
2222
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-resource-has-GET'
23-
severity: warn
23+
severity: error
2424
given: '$.paths'
2525
then:
2626
field: '@key'
@@ -35,7 +35,7 @@ rules:
3535
- Verifies the response is not an array or paginated result
3636
- Different error messages are provided for standard vs singleton resources
3737
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-single-resource'
38-
severity: warn
38+
severity: error
3939
given: '$.paths[*].get.responses[*].content'
4040
then:
4141
field: '@key'
@@ -49,7 +49,7 @@ rules:
4949
- Verifies the 200 OK response code is present
5050
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
5151
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-code-is-200'
52-
severity: warn
52+
severity: error
5353
given: '$.paths[*].get'
5454
then:
5555
function: 'IPA104GetResponseCodeShouldBe200OK'
@@ -62,7 +62,7 @@ rules:
6262
- Verifies the schema references a predefined schema (not inline)
6363
- Confirms the referenced schema name ends with "Response" suffix
6464
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-response-suffixed-object'
65-
severity: warn
65+
severity: error
6666
given: '$.paths[*].get.responses[*].content'
6767
then:
6868
field: '@key'
@@ -76,7 +76,7 @@ rules:
7676
- Searches through the schema to find any properties marked with writeOnly attribute
7777
- Fails if any writeOnly properties are found in the response schema
7878
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-has-no-input-fields'
79-
severity: warn
79+
severity: error
8080
given: '$.paths[*].get.responses[*].content'
8181
then:
8282
field: '@key'
@@ -89,7 +89,7 @@ rules:
8989
- Applies only to GET methods on single resources or singleton resources
9090
- Verifies that the operation object does not contain a requestBody property
9191
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-no-request-body'
92-
severity: warn
92+
severity: error
9393
given: '$.paths[*].get'
9494
then:
9595
function: 'IPA104GetMethodHasNoRequestBody'

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rules:
1919
- Verifies the 200 OK response code is present
2020
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
2121
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-code-is-200'
22-
severity: warn
22+
severity: error
2323
given: '$.paths[*].get'
2424
then:
2525
function: 'IPA105ListResponseCodeShouldBe200OK'
@@ -33,7 +33,7 @@ rules:
3333
- Ignores singleton resources
3434
- Verifies that the operation object does not contain a requestBody property
3535
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-no-request-body'
36-
severity: warn
36+
severity: error
3737
given: '$.paths[*].get'
3838
then:
3939
function: 'IPA105ListMethodHasNoRequestBody'
@@ -48,7 +48,7 @@ rules:
4848
- Verifies the resource path has a GET method
4949
- Fails if the resource path does not have a GET method
5050
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-resource-has-list'
51-
severity: warn
51+
severity: error
5252
given: '$.paths'
5353
then:
5454
field: '@key'
@@ -68,7 +68,7 @@ rules:
6868
- Validation ignores resources without a Get method
6969
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
7070
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-is-get-method-response'
71-
severity: warn
71+
severity: error
7272
given: '$.paths[*].get.responses.200.content'
7373
then:
7474
field: '@key'

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rules:
2121
- Verifies the schema references a predefined schema (not inline)
2222
- Confirms the referenced schema name ends with "Request" suffix
2323
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-body-is-request-suffixed-object'
24-
severity: warn
24+
severity: error
2525
given: '$.paths[*].post.requestBody.content'
2626
then:
2727
field: '@key'
@@ -36,7 +36,7 @@ rules:
3636
- Verifies the operation does not contain query parameters
3737
- Ignores specified parameters like 'pretty' and 'envelope' via configuration
3838
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-should-not-have-query-parameters'
39-
severity: warn
39+
severity: error
4040
given: '$.paths[*].post'
4141
then:
4242
function: 'IPA106CreateMethodShouldNotHaveQueryParameters'
@@ -71,7 +71,7 @@ rules:
7171
- Searches through the request schema to find any properties marked with readOnly attribute
7272
- Fails if any readOnly properties are found in the request schema
7373
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-has-no-readonly-fields'
74-
severity: warn
74+
severity: error
7575
given: '$.paths[*].post.requestBody.content'
7676
then:
7777
field: '@key'
@@ -86,7 +86,7 @@ rules:
8686
- Verifies the 201 Created response code is present
8787
- Fails if the method lacks a 201 Created response or defines a different 2xx status code
8888
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-code-is-201'
89-
severity: warn
89+
severity: error
9090
given: '$.paths[*].post'
9191
then:
9292
function: 'IPA106CreateMethodResponseCodeIs201Created'

tools/spectral/ipa/rulesets/README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Rules are based on [http://go/ipa/IPA-104](http://go/ipa/IPA-104).
8080

8181
#### xgen-IPA-104-resource-has-GET
8282

83-
![warn](https://img.shields.io/badge/warning-yellow)
83+
![error](https://img.shields.io/badge/error-red)
8484
APIs must provide a Get method for resources.
8585

8686
##### Implementation details
@@ -91,7 +91,7 @@ Rule checks for the following conditions:
9191

9292
#### xgen-IPA-104-get-method-returns-single-resource
9393

94-
![warn](https://img.shields.io/badge/warning-yellow)
94+
![error](https://img.shields.io/badge/error-red)
9595
The purpose of the Get method is to return data from a single resource.
9696

9797
##### Implementation details
@@ -102,7 +102,7 @@ Rule checks for the following conditions:
102102

103103
#### xgen-IPA-104-get-method-response-code-is-200
104104

105-
![warn](https://img.shields.io/badge/warning-yellow)
105+
![error](https://img.shields.io/badge/error-red)
106106
The Get method must return a 200 OK response.
107107
##### Implementation details
108108
Rule checks for the following conditions:
@@ -112,7 +112,7 @@ Rule checks for the following conditions:
112112

113113
#### xgen-IPA-104-get-method-returns-response-suffixed-object
114114

115-
![warn](https://img.shields.io/badge/warning-yellow)
115+
![error](https://img.shields.io/badge/error-red)
116116
The Get method of a resource should return a "Response" suffixed object.
117117
##### Implementation details
118118
Rule checks for the following conditions:
@@ -122,7 +122,7 @@ Rule checks for the following conditions:
122122

123123
#### xgen-IPA-104-get-method-response-has-no-input-fields
124124

125-
![warn](https://img.shields.io/badge/warning-yellow)
125+
![error](https://img.shields.io/badge/error-red)
126126
The Get method response object must not include writeOnly properties (fields that should be used only on creation or update, ie output fields).
127127
##### Implementation details
128128
Rule checks for the following conditions:
@@ -132,7 +132,7 @@ Rule checks for the following conditions:
132132

133133
#### xgen-IPA-104-get-method-no-request-body
134134

135-
![warn](https://img.shields.io/badge/warning-yellow)
135+
![error](https://img.shields.io/badge/error-red)
136136
The Get method request must not include a body.
137137
##### Implementation details
138138
Rule checks for the following conditions:
@@ -147,7 +147,7 @@ Rules are based on [http://go/ipa/IPA-105](http://go/ipa/IPA-105).
147147

148148
#### xgen-IPA-105-list-method-response-code-is-200
149149

150-
![warn](https://img.shields.io/badge/warning-yellow)
150+
![error](https://img.shields.io/badge/error-red)
151151
The List method must return a 200 OK response.
152152

153153
##### Implementation details
@@ -159,7 +159,7 @@ Rule checks for the following conditions:
159159

160160
#### xgen-IPA-105-list-method-no-request-body
161161

162-
![warn](https://img.shields.io/badge/warning-yellow)
162+
![error](https://img.shields.io/badge/error-red)
163163
The List method request must not include a body.
164164

165165
##### Implementation details
@@ -170,7 +170,7 @@ Rule checks for the following conditions:
170170

171171
#### xgen-IPA-105-resource-has-list
172172

173-
![warn](https://img.shields.io/badge/warning-yellow)
173+
![error](https://img.shields.io/badge/error-red)
174174
APIs must provide a List method for resources.
175175

176176
##### Implementation details
@@ -182,7 +182,7 @@ Rule checks for the following conditions:
182182

183183
#### xgen-IPA-105-list-method-response-is-get-method-response
184184

185-
![warn](https://img.shields.io/badge/warning-yellow)
185+
![error](https://img.shields.io/badge/error-red)
186186
The response body of the List method should consist of the same resource object returned by the Get method.
187187
##### Implementation details Rule checks for the following conditions:
188188
- Applies only to resource collection paths with JSON content types
@@ -201,7 +201,7 @@ Rules are based on [http://go/ipa/IPA-106](http://go/ipa/IPA-106).
201201

202202
#### xgen-IPA-106-create-method-request-body-is-request-suffixed-object
203203

204-
![warn](https://img.shields.io/badge/warning-yellow)
204+
![error](https://img.shields.io/badge/error-red)
205205
The Create method request should be a Request suffixed object.
206206

207207
##### Implementation details
@@ -213,7 +213,7 @@ Rule checks for the following conditions:
213213

214214
#### xgen-IPA-106-create-method-should-not-have-query-parameters
215215

216-
![warn](https://img.shields.io/badge/warning-yellow)
216+
![error](https://img.shields.io/badge/error-red)
217217
Create operations should not use query parameters.
218218

219219
##### Implementation details
@@ -222,23 +222,9 @@ Rule checks for the following conditions:
222222
- Verifies the operation does not contain query parameters
223223
- Ignores specified parameters like 'pretty' and 'envelope' via configuration
224224

225-
#### xgen-IPA-106-create-method-request-body-is-get-method-response
226-
227-
![warn](https://img.shields.io/badge/warning-yellow)
228-
Request body content of the Create method and response content of the Get method should refer to the same resource.
229-
230-
##### Implementation details
231-
232-
Validation checks the POST method for resource collection paths.
233-
- Validation ignores resources without a Get method.
234-
- `readOnly:true` properties of Get method response will be ignored.
235-
- `writeOnly:true` properties of Create method request will be ignored.
236-
- Property comparison is based on `type` and `name` matching.
237-
- `oneOf` and `discriminator` definitions must match exactly.
238-
239225
#### xgen-IPA-106-create-method-request-has-no-readonly-fields
240226

241-
![warn](https://img.shields.io/badge/warning-yellow)
227+
![error](https://img.shields.io/badge/error-red)
242228
Create method Request object must not include fields with readOnly:true.
243229

244230
##### Implementation details
@@ -250,7 +236,7 @@ Rule checks for the following conditions:
250236

251237
#### xgen-IPA-106-create-method-response-code-is-201
252238

253-
![warn](https://img.shields.io/badge/warning-yellow)
239+
![error](https://img.shields.io/badge/error-red)
254240
Create methods must return a 201 Created response code.
255241

256242
##### Implementation details
@@ -259,6 +245,20 @@ Rule checks for the following conditions:
259245
- Verifies the 201 Created response code is present
260246
- Fails if the method lacks a 201 Created response or defines a different 2xx status code
261247

248+
#### xgen-IPA-106-create-method-request-body-is-get-method-response
249+
250+
![warn](https://img.shields.io/badge/warning-yellow)
251+
Request body content of the Create method and response content of the Get method should refer to the same resource.
252+
253+
##### Implementation details
254+
255+
Validation checks the POST method for resource collection paths.
256+
- Validation ignores resources without a Get method.
257+
- `readOnly:true` properties of Get method response will be ignored.
258+
- `writeOnly:true` properties of Create method request will be ignored.
259+
- Property comparison is based on `type` and `name` matching.
260+
- `oneOf` and `discriminator` definitions must match exactly.
261+
262262
#### xgen-IPA-106-create-method-response-is-get-method-response
263263

264264
![warn](https://img.shields.io/badge/warning-yellow)

0 commit comments

Comments
 (0)