Skip to content

Commit 97aea1f

Browse files
Add Aliases to IPA Validation Rulesets (#688)
1 parent f833b5b commit 97aea1f

File tree

10 files changed

+93
-74
lines changed

10 files changed

+93
-74
lines changed

tools/spectral/ipa/__tests__/__helpers__/testRule.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ async function createSpectral(ruleName) {
5151
function getRulesetForRule(ruleName, ruleset) {
5252
const modifiedRuleset = { rules: {} };
5353
modifiedRuleset.rules[ruleName] = ruleset.rules[ruleName].definition;
54+
if (ruleset.aliases) {
55+
modifiedRuleset.aliases = ruleset.aliases;
56+
}
5457
return modifiedRuleset;
5558
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ functions:
99
- IPA104GetMethodResponseHasNoInputFields
1010
- IPA104GetMethodHasNoRequestBody
1111

12+
aliases:
13+
GetOperationObject:
14+
- '$.paths[*].get'
15+
1216
rules:
1317
xgen-IPA-104-resource-has-GET:
1418
description: |
@@ -36,7 +40,7 @@ rules:
3640
- Different error messages are provided for standard vs singleton resources
3741
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-single-resource'
3842
severity: error
39-
given: '$.paths[*].get.responses[*].content'
43+
given: '#GetOperationObject.responses[*].content'
4044
then:
4145
field: '@key'
4246
function: 'IPA104GetMethodReturnsSingleResource'
@@ -50,7 +54,7 @@ rules:
5054
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
5155
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-code-is-200'
5256
severity: error
53-
given: '$.paths[*].get'
57+
given: '#GetOperationObject'
5458
then:
5559
function: 'IPA104GetResponseCodeShouldBe200OK'
5660
xgen-IPA-104-get-method-returns-response-suffixed-object:
@@ -63,7 +67,7 @@ rules:
6367
- Confirms the referenced schema name ends with "Response" suffix
6468
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-response-suffixed-object'
6569
severity: error
66-
given: '$.paths[*].get.responses[*].content'
70+
given: '#GetOperationObject.responses[*].content'
6771
then:
6872
field: '@key'
6973
function: 'IPA104GetMethodReturnsResponseSuffixedObject'
@@ -77,7 +81,7 @@ rules:
7781
- Fails if any writeOnly properties are found in the response schema
7882
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-has-no-input-fields'
7983
severity: error
80-
given: '$.paths[*].get.responses[*].content'
84+
given: '#GetOperationObject.responses[*].content'
8185
then:
8286
field: '@key'
8387
function: 'IPA104GetMethodResponseHasNoInputFields'
@@ -90,6 +94,6 @@ rules:
9094
- Verifies that the operation object does not contain a requestBody property
9195
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-no-request-body'
9296
severity: error
93-
given: '$.paths[*].get'
97+
given: '#GetOperationObject'
9498
then:
9599
function: 'IPA104GetMethodHasNoRequestBody'

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ functions:
77
- IPA105EachResourceHasListMethod
88
- IPA105ListMethodResponseIsGetMethodResponse
99

10+
aliases:
11+
GetOperationObject:
12+
- '$.paths[*].get'
13+
1014
rules:
1115
xgen-IPA-105-list-method-response-code-is-200:
1216
description: |
@@ -20,7 +24,7 @@ rules:
2024
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
2125
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-code-is-200'
2226
severity: error
23-
given: '$.paths[*].get'
27+
given: '#GetOperationObject'
2428
then:
2529
function: 'IPA105ListResponseCodeShouldBe200OK'
2630
xgen-IPA-105-list-method-no-request-body:
@@ -34,7 +38,7 @@ rules:
3438
- Verifies that the operation object does not contain a requestBody property
3539
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-no-request-body'
3640
severity: error
37-
given: '$.paths[*].get'
41+
given: '#GetOperationObject'
3842
then:
3943
function: 'IPA105ListMethodHasNoRequestBody'
4044
xgen-IPA-105-resource-has-list:
@@ -69,7 +73,7 @@ rules:
6973
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
7074
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-is-get-method-response'
7175
severity: error
72-
given: '$.paths[*].get.responses.200.content'
76+
given: '#GetOperationObject.responses.200.content'
7377
then:
7478
field: '@key'
7579
function: 'IPA105ListMethodResponseIsGetMethodResponse'

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ functions:
99
- IPA106CreateMethodResponseCodeIs201Created
1010
- IPA106CreateMethodResponseIsGetMethodResponse
1111

12+
aliases:
13+
CreateOperationObject:
14+
- '$.paths[*].post'
15+
1216
rules:
1317
xgen-IPA-106-create-method-request-body-is-request-suffixed-object:
1418
description: |
@@ -22,7 +26,7 @@ rules:
2226
- Confirms the referenced schema name ends with "Request" suffix
2327
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-body-is-request-suffixed-object'
2428
severity: error
25-
given: '$.paths[*].post.requestBody.content'
29+
given: '#CreateOperationObject.requestBody.content'
2630
then:
2731
field: '@key'
2832
function: 'IPA106CreateMethodRequestBodyIsRequestSuffixedObject'
@@ -37,7 +41,7 @@ rules:
3741
- Ignores specified parameters like 'pretty' and 'envelope' via configuration
3842
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-should-not-have-query-parameters'
3943
severity: error
40-
given: '$.paths[*].post'
44+
given: '#CreateOperationObject'
4145
then:
4246
function: 'IPA106CreateMethodShouldNotHaveQueryParameters'
4347
functionOptions:
@@ -56,7 +60,7 @@ rules:
5660
- `oneOf` and `discriminator` definitions must match exactly.
5761
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-body-is-get-method-response:'
5862
severity: error
59-
given: '$.paths[*].post.requestBody.content'
63+
given: '#CreateOperationObject.requestBody.content'
6064
then:
6165
field: '@key'
6266
function: 'IPA106CreateMethodRequestBodyIsGetResponse'
@@ -72,7 +76,7 @@ rules:
7276
- Fails if any readOnly properties are found in the request schema
7377
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-has-no-readonly-fields'
7478
severity: error
75-
given: '$.paths[*].post.requestBody.content'
79+
given: '#CreateOperationObject.requestBody.content'
7680
then:
7781
field: '@key'
7882
function: 'IPA106CreateMethodRequestHasNoReadonlyFields'
@@ -87,7 +91,7 @@ rules:
8791
- Fails if the method lacks a 201 Created response or defines a different 2xx status code
8892
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-code-is-201'
8993
severity: error
90-
given: '$.paths[*].post'
94+
given: '#CreateOperationObject'
9195
then:
9296
function: 'IPA106CreateMethodResponseCodeIs201Created'
9397
xgen-IPA-106-create-method-response-is-get-method-response:
@@ -104,7 +108,7 @@ rules:
104108
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
105109
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-is-get-method-response'
106110
severity: error
107-
given: '$.paths[*].post.responses.201.content'
111+
given: '#CreateOperationObject.responses.201.content'
108112
then:
109113
field: '@key'
110114
function: 'IPA106CreateMethodResponseIsGetMethodResponse'

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ functions:
99
- IPA107UpdateMethodRequestBodyIsGetResponse
1010
- IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject
1111

12+
aliases:
13+
UpdateOperationObject:
14+
- '$.paths[*][put,patch]'
15+
1216
rules:
1317
xgen-IPA-107-update-must-not-have-query-params:
1418
description: >-
@@ -22,7 +26,7 @@ rules:
2226
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
2327
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-must-not-have-query-params'
2428
severity: error
25-
given: '$.paths[*][put,patch]'
29+
given: '#UpdateOperationObject'
2630
then:
2731
function: 'IPA107UpdateMethodMustNotHaveQueryParams'
2832
functionOptions:
@@ -38,7 +42,7 @@ rules:
3842
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
3943
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-response-code-is-200'
4044
severity: error
41-
given: '$.paths[*][put,patch]'
45+
given: '#UpdateOperationObject'
4246
then:
4347
function: 'IPA107UpdateResponseCodeShouldBe200OK'
4448
xgen-IPA-107-update-method-response-is-get-method-response:
@@ -54,7 +58,7 @@ rules:
5458
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
5559
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-response-is-get-method-response'
5660
severity: error
57-
given: '$.paths[*][put,patch].responses.200.content'
61+
given: '#UpdateOperationObject.responses.200.content'
5862
then:
5963
field: '@key'
6064
function: 'IPA107UpdateMethodResponseIsGetMethodResponse'
@@ -70,7 +74,7 @@ rules:
7074
- Fails if any readOnly properties are found in the request schema
7175
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-request-has-no-readonly-fields'
7276
severity: error
73-
given: '$.paths[*][put,patch].requestBody.content'
77+
given: '#UpdateOperationObject.requestBody.content'
7478
then:
7579
field: '@key'
7680
function: 'IPA107UpdateMethodRequestHasNoReadonlyFields'
@@ -88,7 +92,7 @@ rules:
8892
- `oneOf` and `discriminator` definitions must match exactly.
8993
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-request-body-is-get-method-response:'
9094
severity: error
91-
given: '$.paths[*][put,patch].requestBody.content'
95+
given: '#UpdateOperationObject.requestBody.content'
9296
then:
9397
field: '@key'
9498
function: 'IPA107UpdateMethodRequestBodyIsGetResponse'
@@ -104,7 +108,7 @@ rules:
104108
- Confirms the referenced schema name ends with "Request" suffix
105109
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object'
106110
severity: error
107-
given: '$.paths[*][put,patch].requestBody.content'
111+
given: '#UpdateOperationObject.requestBody.content'
108112
then:
109113
field: '@key'
110114
function: 'IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject'

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# IPA-108: Delete
22
# http://go/ipa/108
33

4+
aliases:
5+
DeleteOperationObject:
6+
- '$.paths[*].delete'
7+
48
rules:
59
xgen-IPA-108-delete-response-should-be-empty:
610
description: |
@@ -14,7 +18,7 @@ rules:
1418
- Skips validation for collection endpoints (without path parameters)
1519
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-response-should-be-empty'
1620
severity: error
17-
given: $.paths[*].delete.responses[204]
21+
given: '#DeleteOperationObject.responses[204]'
1822
then:
1923
function: IPA108DeleteMethodResponseShouldNotHaveSchema
2024

@@ -32,7 +36,7 @@ rules:
3236
- Skips validation for collection endpoints (without path parameters)
3337
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-method-return-204-response'
3438
severity: error
35-
given: $.paths[*].delete
39+
given: '#DeleteOperationObject'
3640
then:
3741
function: IPA108DeleteMethod204Response
3842

@@ -48,7 +52,7 @@ rules:
4852
- Skips validation for collection endpoints (without path parameters)
4953
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-request-no-body'
5054
severity: error
51-
given: $.paths[*].delete
55+
given: '#DeleteOperationObject'
5256
then:
5357
function: IPA108DeleteMethodNoRequestBody
5458

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ functions:
99
- IPA110CollectionsRequestIncludeCountNotRequired
1010
- IPA110CollectionsResponseDefineLinksArray
1111

12+
aliases:
13+
Get200ResponseContent:
14+
- '$.paths[*].get.responses.200.content'
15+
GetOperationObject:
16+
- '$.paths[*].get'
17+
1218
rules:
1319
xgen-IPA-110-collections-use-paginated-prefix:
1420
description: |
@@ -21,7 +27,7 @@ rules:
2127
- Checks that the 200 response schema references a schema with a "Paginated" prefix
2228
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-use-paginated-prefix'
2329
severity: error
24-
given: '$.paths[*].get.responses.200.content'
30+
given: '#Get200ResponseContent'
2531
then:
2632
field: '@key'
2733
function: 'IPA110CollectionsUsePaginatedPrefix'
@@ -35,7 +41,7 @@ rules:
3541
- Verifies the 200 response schema has the required results fields
3642
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-response-define-results-array'
3743
severity: error
38-
given: '$.paths[*].get.responses.200.content'
44+
given: '#Get200ResponseContent'
3945
then:
4046
field: '@key'
4147
function: 'IPA110CollectionsResponseDefineResultsArray'
@@ -53,7 +59,7 @@ rules:
5359
- Verifies the itemsPerPage query parameter has a default value of 100
5460
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-request-has-itemsPerPage-query-param'
5561
severity: error
56-
given: '$.paths[*].get'
62+
given: '#GetOperationObject'
5763
then:
5864
function: 'IPA110CollectionsRequestHasItemsPerPageQueryParam'
5965
xgen-IPA-110-collections-request-has-pageNum-query-param:
@@ -70,7 +76,7 @@ rules:
7076
- Verifies the pageNum query parameter has a default value of 1
7177
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-request-has-pageNum-query-param'
7278
severity: error
73-
given: '$.paths[*].get'
79+
given: '#GetOperationObject'
7480
then:
7581
function: 'IPA110CollectionsRequestHasPageNumQueryParam'
7682
xgen-IPA-110-collections-request-includeCount-not-required:
@@ -84,7 +90,7 @@ rules:
8490
- If it exists, verifies the includeCount parameter is not required
8591
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-request-includeCount-not-required'
8692
severity: error
87-
given: '$.paths[*].get'
93+
given: '#GetOperationObject'
8894
then:
8995
function: 'IPA110CollectionsRequestIncludeCountNotRequired'
9096
xgen-IPA-110-collections-response-define-links-array:
@@ -97,7 +103,7 @@ rules:
97103
- Verifies the response schema includes a links field of type array
98104
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-response-define-links-array'
99105
severity: error
100-
given: '$.paths[*].get.responses.200.content'
106+
given: '#Get200ResponseContent'
101107
then:
102108
field: '@key'
103109
function: 'IPA110CollectionsResponseDefineLinksArray'

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ functions:
77
- IPA114AuthenticatedEndpointsHaveAuthErrors
88
- IPA114ParameterizedPathsHave404NotFound
99

10+
aliases:
11+
OperationObject:
12+
- '$.paths[*][get,put,post,delete,options,head,patch,trace]'
13+
1014
rules:
1115
xgen-IPA-114-error-responses-refer-to-api-error:
1216
description: |
@@ -44,7 +48,7 @@ rules:
4448
and not containing '/unauth' in the path) include 401 and 403 responses.
4549
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-114-authenticated-endpoints-have-auth-errors'
4650
severity: error
47-
given: '$.paths[*][get,put,post,delete,options,head,patch,trace]'
51+
given: '#OperationObject'
4852
then:
4953
function: 'IPA114AuthenticatedEndpointsHaveAuthErrors'
5054
xgen-IPA-114-parameterized-paths-have-404-not-found:
@@ -57,6 +61,6 @@ rules:
5761
is not found.
5862
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-114-parameterized-paths-have-not-found'
5963
severity: error
60-
given: '$.paths[*][get,put,post,delete,options,head,patch,trace]'
64+
given: '#OperationObject'
6165
then:
6266
function: 'IPA114ParameterizedPathsHave404NotFound'

0 commit comments

Comments
 (0)