Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion .github/workflows/spectral-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
- 'tools/spectral/**'
- 'openapi/**.yaml'
- 'package.json'
permissions:
issues: write
contents: write

jobs:
spectral-lint:
Expand All @@ -34,6 +37,9 @@ jobs:
cache: 'npm'
- name: Install npm dependencies
run: npm install
- name: Fetch OAS file from Dev Branch
run: curl -O "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/.raw/v2.yaml"
working-directory: ${{ github.workspace }}
- name: Spectral action
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
with:
Expand All @@ -43,5 +49,5 @@ jobs:
- name: IPA validation action
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
with:
file_glob: openapi/.raw/v2.yaml
file_glob: ${{ github.workspace }}//v2.yaml
spectral_ruleset: tools/spectral/ipa/ipa-spectral.yaml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tools/spectral/ipa/rulesets/IPA-104.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rules:
- For singleton resources, verifies the resource has a GET method
- For regular resources, verifies there is a single resource path with a GET method
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-resource-has-GET'
severity: warn
severity: error
given: '$.paths'
then:
field: '@key'
Expand All @@ -35,7 +35,7 @@ rules:
- Verifies the response is not an array or paginated result
- Different error messages are provided for standard vs singleton resources
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-single-resource'
severity: warn
severity: error
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
Expand All @@ -49,7 +49,7 @@ rules:
- Verifies the 200 OK response code is present
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-code-is-200'
severity: warn
severity: error
given: '$.paths[*].get'
then:
function: 'IPA104GetResponseCodeShouldBe200OK'
Expand All @@ -62,7 +62,7 @@ rules:
- Verifies the schema references a predefined schema (not inline)
- Confirms the referenced schema name ends with "Response" suffix
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-returns-response-suffixed-object'
severity: warn
severity: error
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
Expand All @@ -76,7 +76,7 @@ rules:
- Searches through the schema to find any properties marked with writeOnly attribute
- Fails if any writeOnly properties are found in the response schema
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-response-has-no-input-fields'
severity: warn
severity: error
given: '$.paths[*].get.responses[*].content'
then:
field: '@key'
Expand All @@ -89,7 +89,7 @@ rules:
- Applies only to GET methods on single resources or singleton resources
- Verifies that the operation object does not contain a requestBody property
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-104-get-method-no-request-body'
severity: warn
severity: error
given: '$.paths[*].get'
then:
function: 'IPA104GetMethodHasNoRequestBody'
8 changes: 4 additions & 4 deletions tools/spectral/ipa/rulesets/IPA-105.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rules:
- Verifies the 200 OK response code is present
- Fails if the method lacks a 200 OK response or defines a different 2xx status code
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-code-is-200'
severity: warn
severity: error
given: '$.paths[*].get'
then:
function: 'IPA105ListResponseCodeShouldBe200OK'
Expand All @@ -33,7 +33,7 @@ rules:
- Ignores singleton resources
- Verifies that the operation object does not contain a requestBody property
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-no-request-body'
severity: warn
severity: error
given: '$.paths[*].get'
then:
function: 'IPA105ListMethodHasNoRequestBody'
Expand All @@ -48,7 +48,7 @@ rules:
- Verifies the resource path has a GET method
- Fails if the resource path does not have a GET method
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-resource-has-list'
severity: warn
severity: error
given: '$.paths'
then:
field: '@key'
Expand All @@ -68,7 +68,7 @@ rules:
- Validation ignores resources without a Get method
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-105-list-method-response-is-get-method-response'
severity: warn
severity: error
given: '$.paths[*].get.responses.200.content'
then:
field: '@key'
Expand Down
8 changes: 4 additions & 4 deletions tools/spectral/ipa/rulesets/IPA-106.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rules:
- Verifies the schema references a predefined schema (not inline)
- Confirms the referenced schema name ends with "Request" suffix
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-body-is-request-suffixed-object'
severity: warn
severity: error
given: '$.paths[*].post.requestBody.content'
then:
field: '@key'
Expand All @@ -36,7 +36,7 @@ rules:
- Verifies the operation does not contain query parameters
- Ignores specified parameters like 'pretty' and 'envelope' via configuration
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-should-not-have-query-parameters'
severity: warn
severity: error
given: '$.paths[*].post'
then:
function: 'IPA106CreateMethodShouldNotHaveQueryParameters'
Expand Down Expand Up @@ -71,7 +71,7 @@ rules:
- Searches through the request schema to find any properties marked with readOnly attribute
- Fails if any readOnly properties are found in the request schema
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-request-has-no-readonly-fields'
severity: warn
severity: error
given: '$.paths[*].post.requestBody.content'
then:
field: '@key'
Expand All @@ -86,7 +86,7 @@ rules:
- Verifies the 201 Created response code is present
- Fails if the method lacks a 201 Created response or defines a different 2xx status code
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-create-method-response-code-is-201'
severity: warn
severity: error
given: '$.paths[*].post'
then:
function: 'IPA106CreateMethodResponseCodeIs201Created'
Expand Down
56 changes: 28 additions & 28 deletions tools/spectral/ipa/rulesets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Rules are based on [http://go/ipa/IPA-104](http://go/ipa/IPA-104).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#### xgen-IPA-106-create-method-request-body-is-get-method-response

![warn](https://img.shields.io/badge/warning-yellow)
Request body content of the Create method and response content of the Get method should refer to the same resource.

##### Implementation details

Validation checks the POST method for resource collection paths.
- Validation ignores resources without a Get method.
- `readOnly:true` properties of Get method response will be ignored.
- `writeOnly:true` properties of Create method request will be ignored.
- Property comparison is based on `type` and `name` matching.
- `oneOf` and `discriminator` definitions must match exactly.

#### xgen-IPA-106-create-method-request-has-no-readonly-fields

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

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

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

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

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

#### xgen-IPA-106-create-method-request-body-is-get-method-response

![warn](https://img.shields.io/badge/warning-yellow)
Request body content of the Create method and response content of the Get method should refer to the same resource.

##### Implementation details

Validation checks the POST method for resource collection paths.
- Validation ignores resources without a Get method.
- `readOnly:true` properties of Get method response will be ignored.
- `writeOnly:true` properties of Create method request will be ignored.
- Property comparison is based on `type` and `name` matching.
- `oneOf` and `discriminator` definitions must match exactly.

#### xgen-IPA-106-create-method-response-is-get-method-response

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