Skip to content

Commit d0c6db0

Browse files
wtrockiyelizhenden-mdblovisaberggren
authored
CLOUDP-305862 - Add missing rule Technical Specifications (#546)
Co-authored-by: Yeliz Henden <[email protected]> Co-authored-by: Lovisa Berggren <[email protected]>
1 parent b8aa96d commit d0c6db0

File tree

8 files changed

+266
-64
lines changed

8 files changed

+266
-64
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ rules:
4343
xgen-IPA-104-get-method-response-code-is-200:
4444
description: |
4545
The Get method must return a 200 OK response.
46-
4746
##### Implementation details
4847
Rule checks for the following conditions:
4948
- Applies only to GET methods on single resources or singleton resources
@@ -57,7 +56,6 @@ rules:
5756
xgen-IPA-104-get-method-returns-response-suffixed-object:
5857
description: |
5958
The Get method of a resource should return a "Response" suffixed object.
60-
6159
##### Implementation details
6260
Rule checks for the following conditions:
6361
- Applies only to 2xx responses of GET methods on single resources or singleton resources
@@ -72,7 +70,6 @@ rules:
7270
xgen-IPA-104-get-method-response-has-no-input-fields:
7371
description: |
7472
The Get method response object must not include writeOnly properties (fields that should be used only on creation or update, ie output fields).
75-
7673
##### Implementation details
7774
Rule checks for the following conditions:
7875
- Applies only to 2xx responses of GET methods on single resources or singleton resources
@@ -87,7 +84,6 @@ rules:
8784
xgen-IPA-104-get-method-no-request-body:
8885
description: |
8986
The Get method request must not include a body.
90-
9187
##### Implementation details
9288
Rule checks for the following conditions:
9389
- Applies only to GET methods on single resources or singleton resources

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,44 @@ functions:
99

1010
rules:
1111
xgen-IPA-105-list-method-response-code-is-200:
12-
description: 'The List method must return a 200 OK response.'
12+
description: |
13+
The List method must return a 200 OK response.
14+
15+
##### Implementation details
16+
Rule checks for the following conditions:
17+
- Applies only to GET methods on resource collection paths
18+
- Ignores singleton resources
19+
- Verifies the 200 OK response code is present
20+
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
1321
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-code-is-200'
1422
severity: warn
1523
given: '$.paths[*].get'
1624
then:
1725
function: 'IPA105ListResponseCodeShouldBe200OK'
1826
xgen-IPA-105-list-method-no-request-body:
19-
description: 'The List method request must not include a body.'
27+
description: |
28+
The List method request must not include a body.
29+
30+
##### Implementation details
31+
Rule checks for the following conditions:
32+
- Applies only to GET methods on resource collection paths
33+
- Ignores singleton resources
34+
- Verifies that the operation object does not contain a requestBody property
2035
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-no-request-body'
2136
severity: warn
2237
given: '$.paths[*].get'
2338
then:
2439
function: 'IPA105ListMethodHasNoRequestBody'
2540
xgen-IPA-105-resource-has-list:
26-
description: 'APIs must provide a List method for resources.'
41+
description: |
42+
APIs must provide a List method for resources.
43+
44+
##### Implementation details
45+
Rule checks for the following conditions:
46+
- Applies only to resource collection paths
47+
- Ignores singleton resources
48+
- Verifies the resource path has a GET method
49+
- Fails if the resource path does not have a GET method
2750
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-resource-has-list'
2851
severity: warn
2952
given: '$.paths'
@@ -35,13 +58,13 @@ rules:
3558
The response body of the List method should consist of the same resource object returned by the Get method.
3659
3760
##### Implementation details
38-
39-
Validation checks that the List method 200 OK response contains items property with reference to the same schema as the Get method response.
40-
41-
- Validation applies to List methods for resource collections only
42-
- Validation applies to json response content only
43-
- Validation ignores responses without schema and non-paginated responses
44-
- A response is considered paginated if it contains an array property named `results`
61+
Rule checks for the following conditions:
62+
- Applies only to resource collection paths with JSON content types
63+
- Ignores singleton resources
64+
- Ignores responses without a schema or non-paginated responses
65+
- A response is considered paginated if it has a schema with a 'results' array property
66+
- Verifies that the schema of items in the 'results' array matches the schema used in the Get method response
67+
- Fails if the Get method doesn't have a schema reference or if the schemas don't match
4568
- Validation ignores resources without a Get method
4669
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
4770
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-is-get-method-response'

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,30 @@ functions:
1111

1212
rules:
1313
xgen-IPA-106-create-method-request-body-is-request-suffixed-object:
14-
description: >-
14+
description: |
1515
The Create method request should be a Request suffixed object.
1616
1717
##### Implementation details
18-
19-
Validation checks the POST method for resource collection paths.
18+
Rule checks for the following conditions:
19+
- Applies only to POST methods on resource collection paths (non-singleton resources)
20+
- Applies only to JSON content types
21+
- Verifies the schema references a predefined schema (not inline)
22+
- Confirms the referenced schema name ends with "Request" suffix
2023
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-body-is-request-suffixed-object'
2124
severity: warn
2225
given: '$.paths[*].post.requestBody.content'
2326
then:
2427
field: '@key'
2528
function: 'IPA106CreateMethodRequestBodyIsRequestSuffixedObject'
2629
xgen-IPA-106-create-method-should-not-have-query-parameters:
27-
description: >-
30+
description: |
2831
Create operations should not use query parameters.
2932
3033
##### Implementation details
31-
32-
Validation checks the POST method for resource collection paths.
34+
Rule checks for the following conditions:
35+
- Applies only to POST methods on resource collection paths (non-singleton resources)
36+
- Verifies the operation does not contain query parameters
37+
- Ignores specified parameters like 'pretty' and 'envelope' via configuration
3338
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-should-not-have-query-parameters'
3439
severity: warn
3540
given: '$.paths[*].post'
@@ -38,7 +43,7 @@ rules:
3843
functionOptions:
3944
ignoredValues: ['pretty', 'envelope']
4045
xgen-IPA-106-create-method-request-body-is-get-method-response:
41-
description: >-
46+
description: |
4247
Request body content of the Create method and response content of the Get method should refer to the same resource.
4348
4449
##### Implementation details
@@ -56,42 +61,46 @@ rules:
5661
field: '@key'
5762
function: 'IPA106CreateMethodRequestBodyIsGetResponse'
5863
xgen-IPA-106-create-method-request-has-no-readonly-fields:
59-
description: >-
64+
description: |
6065
Create method Request object must not include fields with readOnly:true.
6166
6267
##### Implementation details
63-
64-
Validation checks the POST method for resource collection paths.
68+
Rule checks for the following conditions:
69+
- Applies only to POST methods on resource collection paths (non-singleton resources)
70+
- Applies only to JSON content types
71+
- Searches through the request schema to find any properties marked with readOnly attribute
72+
- Fails if any readOnly properties are found in the request schema
6573
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-has-no-readonly-fields'
6674
severity: warn
6775
given: '$.paths[*].post.requestBody.content'
6876
then:
6977
field: '@key'
7078
function: 'IPA106CreateMethodRequestHasNoReadonlyFields'
7179
xgen-IPA-106-create-method-response-code-is-201:
72-
description: >-
80+
description: |
7381
Create methods must return a 201 Created response code.
7482
7583
##### Implementation details
76-
77-
Validation checks the POST method for resource collection paths.
84+
Rule checks for the following conditions:
85+
- Applies only to POST methods on resource collection paths (non-singleton resources)
86+
- Verifies the 201 Created response code is present
87+
- Fails if the method lacks a 201 Created response or defines a different 2xx status code
7888
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-code-is-201'
7989
severity: warn
8090
given: '$.paths[*].post'
8191
then:
8292
function: 'IPA106CreateMethodResponseCodeIs201Created'
8393
xgen-IPA-106-create-method-response-is-get-method-response:
84-
description: >-
94+
description: |
8595
The response body of the Create method should consist of the same resource object returned by the Get method.
8696
8797
##### Implementation details
88-
89-
Validation checks that the Create method 201 Created response contains reference to the same schema as the Get method response.
90-
91-
- Validation applies to Create methods for resource collections only
92-
- Validation applies to json response content only
93-
- Validation ignores responses without schema
94-
- Validation ignores resources without a Get method
98+
Rule checks for the following conditions:
99+
- Applies only to POST methods on resource collection paths
100+
- Applies only to JSON response content types
101+
- Verifies that both Create and Get methods have schema references
102+
- Confirms that the Create method 201 response schema reference matches the Get method response schema reference
103+
- Ignores resources without a Get method
95104
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
96105
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-is-get-method-response'
97106
severity: warn

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,61 @@
33

44
rules:
55
xgen-IPA-108-delete-response-should-be-empty:
6-
description: Delete method response should not have schema reference to object.
6+
description: |
7+
Delete method response should not have schema reference to object.
8+
9+
##### Implementation details
10+
Rule checks for the following conditions:
11+
- Applies to 204 responses in DELETE methods
12+
- Verifies that the response does not contain a schema property
13+
- Fails if any content type in the response has a defined schema as reference
714
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-response-should-be-empty'
815
severity: warn
916
given: $.paths[*].delete.responses[204]
1017
then:
1118
function: IPA108DeleteMethodResponseShouldNotHaveSchema
1219

1320
xgen-IPA-108-delete-method-return-204-response:
14-
description: DELETE method must return 204 No Content.
21+
description: |
22+
DELETE method must return 204 No Content.
23+
24+
##### Implementation details
25+
Rule checks for the following conditions:
26+
- Applies to all DELETE methods
27+
- Verifies the 204 No Content response code is present
28+
- Fails if the method lacks a 204 No Content response or defines a different 2xx status code
29+
- Ensures no other 2xx response codes are defined
30+
- Fails if the 204 status code is missing or if other 2xx responses exist
1531
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-method-return-204-response'
1632
severity: warn
1733
given: $.paths[*].delete
1834
then:
1935
function: IPA108DeleteMethod204Response
2036

2137
xgen-IPA-108-delete-include-404-response:
22-
description: DELETE method must include 404 response and return it when resource not found.
38+
description: |
39+
DELETE method must include 404 response and return it when resource not found.
40+
41+
##### Implementation details
42+
Rule checks for the following conditions:
43+
- Applies to all DELETE methods
44+
- Verifies that the method includes a 404 response code
45+
- Fails if the 404 status code is missing from the responses
2346
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-include-404-response'
2447
severity: warn
2548
given: $.paths[*].delete
2649
then:
2750
function: IPA108DeleteMethod404Response
2851

2952
xgen-IPA-108-delete-request-no-body:
30-
description: DELETE method must not have request body.
53+
description: |
54+
DELETE method must not have request body.
55+
56+
##### Implementation details
57+
Rule checks for the following conditions:
58+
- Applies to all DELETE methods
59+
- Verifies that the operation object does not contain a requestBody property
60+
- Fails if any requestBody is defined for the DELETE method
3161
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-request-no-body'
3262
severity: warn
3363
given: $.paths[*].delete

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,32 @@ functions:
77

88
rules:
99
xgen-IPA-109-custom-method-must-be-GET-or-POST:
10-
description: 'The HTTP method for custom methods must be GET or POST.'
10+
description: |
11+
The HTTP method for custom methods must be GET or POST.
12+
13+
##### Implementation details
14+
Rule checks for the following conditions:
15+
- Applies only to paths containing custom method identifiers (with colon format)
16+
- Verifies the HTTP methods used are either GET or POST
17+
- Fails if any other HTTP methods are used (PUT, DELETE, PATCH, etc.)
18+
- Fails if multiple valid methods are defined for the same custom method endpoint
1119
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-custom-method-must-be-GET-or-POST'
1220
severity: error
1321
given: '$.paths[*]'
1422
then:
1523
function: 'IPA109EachCustomMethodMustBeGetOrPost'
1624

1725
xgen-IPA-109-custom-method-must-use-camel-case:
18-
description: 'The custom method must use camelCase format.'
26+
description: |
27+
The custom method must use camelCase format.
28+
29+
##### Implementation details
30+
Rule checks for the following conditions:
31+
- Applies only to paths containing custom method identifiers (with colon format)
32+
- Extracts the method name portion following the colon
33+
- Verifies the method name is not empty or blank
34+
- Validates that the method name uses proper camelCase formatting
35+
- Fails if the method name contains invalid casing (such as snake_case, PascalCase, etc.)
1936
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-custom-method-must-use-camel-case'
2037
severity: error
2138
given: '$.paths[*]'

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ functions:
66

77
rules:
88
xgen-IPA-113-singleton-must-not-have-id:
9-
description: 'Singleton resources must not have a user-provided or system-generated ID.'
9+
description: |
10+
Singleton resources must not have a user-provided or system-generated ID.
11+
12+
##### Implementation details
13+
Rule checks for the following conditions:
14+
- Applies only to singleton resources that are identified as resource collection identifiers
15+
- Checks that the resource has a GET method defined
16+
- Examines all 2xx response schemas from the GET method
17+
- Verifies that no schema contains 'id' or '_id' properties in their object definitions
18+
- Fails if any response schema contains these identifier properties
1019
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-113-singleton-must-not-have-id'
1120
severity: warn
1221
given: '$.paths[*]'

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ functions:
66

77
rules:
88
xgen-IPA-123-enum-values-must-be-upper-snake-case:
9-
description: 'Enum values must be UPPER_SNAKE_CASE.'
9+
description: |
10+
Enum values must be UPPER_SNAKE_CASE.
11+
12+
##### Implementation details
13+
Rule checks for the following conditions:
14+
- Applies to all enum value arrays defined in the OpenAPI schema
15+
- Resolves the schema object that contains the enum values
16+
- Validates each enum value individually against the UPPER_SNAKE_CASE pattern
17+
- Skips validation if the schema has an exception defined for this rule
1018
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-123-enum-values-must-be-upper-snake-case'
1119
severity: error
1220
given: '$..enum'

0 commit comments

Comments
 (0)