Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions tools/spectral/ipa/rulesets/IPA-102.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,50 @@ rules:
given: $.paths
then:
field: '@key'
function: collectionIdentifierCamelCase
function: IPA102CollectionIdentifierCamelCase
functionOptions:
# Contains list of ignored path params
ignoredValues: ['v2', 'v1']

xgen-IPA-102-path-alternate-resource-name-path-param:
description: 'Paths should alternate between resource names and path params.'
description: |
Paths should alternate between resource names and path params.

##### Implementation details
Rule checks for the following conditions:

- Paths must follow a pattern where resource names and path parameters strictly alternate
- Even-indexed path segments should be resource names (not path parameters)
- Odd-indexed path segments should be path parameters
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-102-path-alternate-resource-name-path-param'
severity: error
given: '$.paths'
then:
field: '@key'
function: 'eachPathAlternatesBetweenResourceNameAndPathParam'
function: IPA102EachPathAlternatesBetweenResourceNameAndPathParam

xgen-IPA-102-collection-identifier-pattern:
description: Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers.
description: |
Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers.

##### Implementation details
Rule checks for the following conditions:

- All path segments that are not path parameters must match pattern `/^[a-z][a-zA-Z0-9]*$/`
- Path parameters (inside curly braces) are excluded from validation
- Custom methods (segments containing colons) are excluded from validation
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
- Each non-parameter path segment must start with a lowercase letter followed by any combination of ASCII letters and numbers

message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-102-collection-identifier-pattern'
severity: warn
given: $.paths
then:
field: '@key'
function: collectionIdentifierPattern
function: IPA102CollectionIdentifierPattern

functions:
- collectionIdentifierPattern
- eachPathAlternatesBetweenResourceNameAndPathParam
- collectionIdentifierCamelCase
- IPA102CollectionIdentifierPattern
- IPA102EachPathAlternatesBetweenResourceNameAndPathParam
- IPA102CollectionIdentifierCamelCase
24 changes: 12 additions & 12 deletions tools/spectral/ipa/rulesets/IPA-104.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# http://go/ipa/104

functions:
- eachResourceHasGetMethod
- getMethodReturnsSingleResource
- getMethodReturnsResponseSuffixedObject
- getResponseCodeShouldBe200OK
- getMethodResponseHasNoInputFields
- getMethodHasNoRequestBody
- IPA104EachResourceHasGetMethod
- IPA104GetMethodReturnsSingleResource
- IPA104GetMethodReturnsResponseSuffixedObject
- IPA104GetResponseCodeShouldBe200OK
- IPA104GetMethodResponseHasNoInputFields
- IPA104GetMethodHasNoRequestBody

rules:
xgen-IPA-104-resource-has-GET:
Expand All @@ -17,42 +17,42 @@ rules:
given: '$.paths'
then:
field: '@key'
function: 'eachResourceHasGetMethod'
function: 'IPA104EachResourceHasGetMethod'
xgen-IPA-104-get-method-returns-single-resource:
description: 'The purpose of the Get method is to return data from a single resource.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-single-resource'
severity: warn
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
function: 'getMethodReturnsSingleResource'
function: 'IPA104GetMethodReturnsSingleResource'
xgen-IPA-104-get-method-response-code-is-200:
description: 'The Get method must return a 200 OK response.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-code-is-200'
severity: warn
given: '$.paths[*].get'
then:
function: 'getResponseCodeShouldBe200OK'
function: 'IPA104GetResponseCodeShouldBe200OK'
xgen-IPA-104-get-method-returns-response-suffixed-object:
description: 'The Get method of a resource should return a "Response" suffixed object.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-response-suffixed-object'
severity: warn
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
function: 'getMethodReturnsResponseSuffixedObject'
function: 'IPA104GetMethodReturnsResponseSuffixedObject'
xgen-IPA-104-get-method-response-has-no-input-fields:
description: 'The Get method response object must not include writeOnly properties (fields that should be used only on creation or update, ie output fields).'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-has-no-input-fields'
severity: warn
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
function: 'getMethodResponseHasNoInputFields'
function: 'IPA104GetMethodResponseHasNoInputFields'
xgen-IPA-104-get-method-no-request-body:
description: 'The Get method request must not include a body.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-no-request-body'
severity: warn
given: '$.paths[*].get'
then:
function: 'getMethodHasNoRequestBody'
function: 'IPA104GetMethodHasNoRequestBody'
16 changes: 8 additions & 8 deletions tools/spectral/ipa/rulesets/IPA-105.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# http://go/ipa/105

functions:
- listResponseCodeShouldBe200OK
- listMethodHasNoRequestBody
- eachResourceHasListMethod
- listMethodResponseIsGetMethodResponse
- IPA105ListResponseCodeShouldBe200OK
- IPA105ListMethodHasNoRequestBody
- IPA105EachResourceHasListMethod
- IPA105ListMethodResponseIsGetMethodResponse

rules:
xgen-IPA-105-list-method-response-code-is-200:
Expand All @@ -14,22 +14,22 @@ rules:
severity: warn
given: '$.paths[*].get'
then:
function: 'listResponseCodeShouldBe200OK'
function: 'IPA105ListResponseCodeShouldBe200OK'
xgen-IPA-105-list-method-no-request-body:
description: 'The List method request must not include a body.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-no-request-body'
severity: warn
given: '$.paths[*].get'
then:
function: 'listMethodHasNoRequestBody'
function: 'IPA105ListMethodHasNoRequestBody'
xgen-IPA-105-resource-has-list:
description: 'APIs must provide a List method for resources.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-resource-has-list'
severity: warn
given: '$.paths'
then:
field: '@key'
function: 'eachResourceHasListMethod'
function: 'IPA105EachResourceHasListMethod'
xgen-IPA-105-list-method-response-is-get-method-response:
description: >-
The response body of the List method should consist of the same resource object returned by the Get method.
Expand All @@ -49,4 +49,4 @@ rules:
given: '$.paths[*].get.responses.200.content'
then:
field: '@key'
function: 'listMethodResponseIsGetMethodResponse'
function: 'IPA105ListMethodResponseIsGetMethodResponse'
24 changes: 12 additions & 12 deletions tools/spectral/ipa/rulesets/IPA-106.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# https://mdb.link/mongodb-atlas-openapi-validation#

functions:
- createMethodRequestBodyIsRequestSuffixedObject
- createMethodShouldNotHaveQueryParameters
- createMethodRequestBodyIsGetResponse
- createMethodRequestHasNoReadonlyFields
- createMethodResponseCodeIs201Created
- createMethodResponseIsGetMethodResponse
- IPA106CreateMethodRequestBodyIsRequestSuffixedObject
- IPA106CreateMethodShouldNotHaveQueryParameters
- IPA106CreateMethodRequestBodyIsGetResponse
- IPA106CreateMethodRequestHasNoReadonlyFields
- IPA106CreateMethodResponseCodeIs201Created
- IPA106CreateMethodResponseIsGetMethodResponse

rules:
xgen-IPA-106-create-method-request-body-is-request-suffixed-object:
Expand All @@ -22,7 +22,7 @@ rules:
given: '$.paths[*].post.requestBody.content'
then:
field: '@key'
function: 'createMethodRequestBodyIsRequestSuffixedObject'
function: 'IPA106CreateMethodRequestBodyIsRequestSuffixedObject'
xgen-IPA-106-create-method-should-not-have-query-parameters:
description: >-
Create operations should not use query parameters.
Expand All @@ -34,7 +34,7 @@ rules:
severity: warn
given: '$.paths[*].post'
then:
function: 'createMethodShouldNotHaveQueryParameters'
function: 'IPA106CreateMethodShouldNotHaveQueryParameters'
functionOptions:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-106-create-method-request-body-is-get-method-response:
Expand All @@ -51,7 +51,7 @@ rules:
given: '$.paths[*].post.requestBody.content'
then:
field: '@key'
function: 'createMethodRequestBodyIsGetResponse'
function: 'IPA106CreateMethodRequestBodyIsGetResponse'
xgen-IPA-106-create-method-request-has-no-readonly-fields:
description: >-
Create method Request object must not include fields with readOnly:true.
Expand All @@ -64,7 +64,7 @@ rules:
given: '$.paths[*].post.requestBody.content'
then:
field: '@key'
function: 'createMethodRequestHasNoReadonlyFields'
function: 'IPA106CreateMethodRequestHasNoReadonlyFields'
xgen-IPA-106-create-method-response-code-is-201:
description: >-
Create methods must return a 201 Created response code.
Expand All @@ -76,7 +76,7 @@ rules:
severity: warn
given: '$.paths[*].post'
then:
function: 'createMethodResponseCodeIs201Created'
function: 'IPA106CreateMethodResponseCodeIs201Created'
xgen-IPA-106-create-method-response-is-get-method-response:
description: >-
The response body of the Create method should consist of the same resource object returned by the Get method.
Expand All @@ -95,4 +95,4 @@ rules:
given: '$.paths[*].post.responses.201.content'
then:
field: '@key'
function: 'createMethodResponseIsGetMethodResponse'
function: 'IPA106CreateMethodResponseIsGetMethodResponse'
12 changes: 6 additions & 6 deletions tools/spectral/ipa/rulesets/IPA-107.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# http://go/ipa/107

functions:
- updateMethodMustNotHaveQueryParams
- updateResponseCodeShouldBe200OK
- IPA107UpdateMethodMustNotHaveQueryParams
- IPA107UpdateResponseCodeShouldBe200OK

rules:
xgen-IPA-107-put-must-not-have-query-params:
Expand All @@ -20,7 +20,7 @@ rules:
severity: warn
given: '$.paths[*].put'
then:
function: 'updateMethodMustNotHaveQueryParams'
function: 'IPA107UpdateMethodMustNotHaveQueryParams'
functionOptions:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-107-patch-must-not-have-query-params:
Expand All @@ -37,7 +37,7 @@ rules:
severity: warn
given: '$.paths[*].patch'
then:
function: 'updateMethodMustNotHaveQueryParams'
function: 'IPA107UpdateMethodMustNotHaveQueryParams'
functionOptions:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-107-put-method-response-code-is-200:
Expand All @@ -53,7 +53,7 @@ rules:
severity: warn
given: '$.paths[*].put'
then:
function: 'updateResponseCodeShouldBe200OK'
function: 'IPA107UpdateResponseCodeShouldBe200OK'
xgen-IPA-107-patch-method-response-code-is-200:
description: >-
The Update method response status code should be 200 OK.
Expand All @@ -67,4 +67,4 @@ rules:
severity: warn
given: '$.paths[*].patch'
then:
function: 'updateResponseCodeShouldBe200OK'
function: 'IPA107UpdateResponseCodeShouldBe200OK'
16 changes: 8 additions & 8 deletions tools/spectral/ipa/rulesets/IPA-108.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ rules:
severity: warn
given: $.paths[*].delete.responses[204]
then:
function: deleteMethodResponseShouldNotHaveSchema
function: IPA108DeleteMethodResponseShouldNotHaveSchema

xgen-IPA-108-delete-method-return-204-response:
description: DELETE method must return 204 No Content.
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-method-return-204-response'
severity: warn
given: $.paths[*].delete
then:
function: deleteMethod204Response
function: IPA108DeleteMethod204Response

xgen-IPA-108-delete-include-404-response:
description: DELETE method must include 404 response and return it when resource not found.
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-include-404-response'
severity: warn
given: $.paths[*].delete
then:
function: deleteMethod404Response
function: IPA108DeleteMethod404Response

xgen-IPA-108-delete-request-no-body:
description: DELETE method must not have request body.
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-delete-request-no-body'
severity: warn
given: $.paths[*].delete
then:
function: deleteMethodNoRequestBody
function: IPA108DeleteMethodNoRequestBody

functions:
- deleteMethodResponseShouldNotHaveSchema
- deleteMethod204Response
- deleteMethodNoRequestBody
- deleteMethod404Response
- IPA108DeleteMethodResponseShouldNotHaveSchema
- IPA108DeleteMethod204Response
- IPA108DeleteMethodNoRequestBody
- IPA108DeleteMethod404Response
8 changes: 4 additions & 4 deletions tools/spectral/ipa/rulesets/IPA-109.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# http://go/ipa/109

functions:
- eachCustomMethodMustBeGetOrPost
- eachCustomMethodMustUseCamelCase
- IPA109EachCustomMethodMustBeGetOrPost
- IPA109EachCustomMethodMustUseCamelCase

rules:
xgen-IPA-109-custom-method-must-be-GET-or-POST:
Expand All @@ -12,12 +12,12 @@ rules:
severity: error
given: '$.paths[*]'
then:
function: 'eachCustomMethodMustBeGetOrPost'
function: 'IPA109EachCustomMethodMustBeGetOrPost'

xgen-IPA-109-custom-method-must-use-camel-case:
description: 'The custom method must use camelCase format.'
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-custom-method-must-use-camel-case'
severity: error
given: '$.paths[*]'
then:
function: 'eachCustomMethodMustUseCamelCase'
function: 'IPA109EachCustomMethodMustUseCamelCase'
4 changes: 2 additions & 2 deletions tools/spectral/ipa/rulesets/IPA-113.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://go/ipa/113

functions:
- singletonHasNoId
- IPA113SingletonHasNoId

rules:
xgen-IPA-113-singleton-must-not-have-id:
Expand All @@ -11,4 +11,4 @@ rules:
severity: warn
given: '$.paths[*]'
then:
function: 'singletonHasNoId'
function: 'IPA113SingletonHasNoId'
4 changes: 2 additions & 2 deletions tools/spectral/ipa/rulesets/IPA-123.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://go/ipa/123

functions:
- eachEnumValueMustBeUpperSnakeCase
- IPA123EachEnumValueMustBeUpperSnakeCase

rules:
xgen-IPA-123-enum-values-must-be-upper-snake-case:
Expand All @@ -11,4 +11,4 @@ rules:
severity: error
given: '$..enum'
then:
function: 'eachEnumValueMustBeUpperSnakeCase'
function: 'IPA123EachEnumValueMustBeUpperSnakeCase'
Loading
Loading