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
292 changes: 292 additions & 0 deletions tools/spectral/ipa/__tests__/updateResponseCodeShouldBe200OK.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import testRule from './__helpers__/testRule';
import { DiagnosticSeverity } from '@stoplight/types';

testRule('xgen-IPA-107-put-method-response-code-is-200', [
{
name: 'valid methods',
document: {
paths: {
'/resource/{id}': {
put: {
responses: {
200: {},
400: {},
500: {},
},
},
},
'/resource/{id}/singleton': {
put: {
responses: {
200: {},
400: {},
500: {},
},
},
},
},
},
errors: [],
},
{
name: 'invalid methods',
document: {
paths: {
'/resourceOne/{id}': {
put: {
responses: {
201: {},
400: {},
500: {},
},
},
},
'/resourceTwo/{id}': {
put: {
responses: {
400: {},
500: {},
},
},
},
'/resourceThree/{id}': {
put: {
responses: {
200: {},
201: {},
400: {},
500: {},
},
},
},
'/resource/{id}/singleton': {
put: {
responses: {
202: {},
400: {},
500: {},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-107-put-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceOne/{id}', 'put'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-put-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceTwo/{id}', 'put'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-put-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceThree/{id}', 'put'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-put-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resource/{id}/singleton', 'put'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'invalid method with exception',
document: {
paths: {
'/resourceOne/{id}': {
put: {
responses: {
201: {},
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
},
},
},
'/resourceTwo/{id}': {
put: {
responses: {
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
},
},
},
'/resource/{id}/singleton': {
put: {
responses: {
202: {},
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
},
},
},
},
},
errors: [],
},
]);

testRule('xgen-IPA-107-patch-method-response-code-is-200', [
{
name: 'valid methods',
document: {
paths: {
'/resource/{id}': {
patch: {
responses: {
200: {},
400: {},
500: {},
},
},
},
'/resource/{id}/singleton': {
patch: {
responses: {
200: {},
400: {},
500: {},
},
},
},
},
},
errors: [],
},
{
name: 'invalid methods',
document: {
paths: {
'/resourceOne/{id}': {
patch: {
responses: {
201: {},
400: {},
500: {},
},
},
},
'/resourceTwo/{id}': {
patch: {
responses: {
400: {},
500: {},
},
},
},
'/resourceThree/{id}': {
patch: {
responses: {
200: {},
201: {},
400: {},
500: {},
},
},
},
'/resource/{id}/singleton': {
patch: {
responses: {
202: {},
400: {},
500: {},
},
},
},
},
},
errors: [
{
code: 'xgen-IPA-107-patch-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceOne/{id}', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-patch-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceTwo/{id}', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-patch-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resourceThree/{id}', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-107-patch-method-response-code-is-200',
message:
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code.',
path: ['paths', '/resource/{id}/singleton', 'patch'],
severity: DiagnosticSeverity.Warning,
},
],
},
{
name: 'invalid method with exception',
document: {
paths: {
'/resourceOne/{id}': {
patch: {
responses: {
201: {},
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
},
},
},
'/resourceTwo/{id}': {
patch: {
responses: {
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
},
},
},
'/resource/{id}/singleton': {
patch: {
responses: {
202: {},
400: {},
500: {},
},
'x-xgen-IPA-exception': {
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
},
},
},
},
},
errors: [],
},
]);
31 changes: 30 additions & 1 deletion tools/spectral/ipa/rulesets/IPA-107.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

functions:
- updateMethodMustNotHaveQueryParams
- updateResponseCodeShouldBe200OK

rules:
xgen-IPA-107-put-must-not-have-query-params:
Expand All @@ -24,7 +25,7 @@ rules:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-107-patch-must-not-have-query-params:
description: >-
Update operations must not accept query parameters.
Update operations must not accept query parameters.

##### Implementation details

Expand All @@ -39,3 +40,31 @@ rules:
function: 'updateMethodMustNotHaveQueryParams'
functionOptions:
ignoredValues: ['pretty', 'envelope']
xgen-IPA-107-put-method-response-code-is-200:
description: >-
The Update method response status code should be 200 OK.

##### Implementation details

Validation checks the PUT method for single resource paths and [singleton resources](https://go/ipa/113).

- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-put-method-response-code-is-200'
severity: warn
given: '$.paths[*].put'
then:
function: 'updateResponseCodeShouldBe200OK'
xgen-IPA-107-patch-method-response-code-is-200:
description: >-
The Update method response status code should be 200 OK.

##### Implementation details

Validation checks the PATCH method for single resource paths and [singleton resources](https://go/ipa/113).

- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-patch-method-response-code-is-200'
severity: warn
given: '$.paths[*].patch'
then:
function: 'updateResponseCodeShouldBe200OK'
18 changes: 17 additions & 1 deletion tools/spectral/ipa/rulesets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,28 @@ Validation checks the PUT method for single resource paths and singleton resourc
#### xgen-IPA-107-patch-must-not-have-query-params

![warn](https://img.shields.io/badge/warning-yellow)
Update operations must not accept query parameters.
Update operations must not accept query parameters.
##### Implementation details
Validation checks the PATCH method for single resource paths and singleton resources.

- Query parameters `envelope` and `pretty` are exempt from this rule
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
#### xgen-IPA-107-put-method-response-code-is-200

![warn](https://img.shields.io/badge/warning-yellow)
The Update method response status code should be 200 OK.
##### Implementation details
Validation checks the PUT method for single resource paths and [singleton resources](https://go/ipa/113).

- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
#### xgen-IPA-107-patch-method-response-code-is-200

![warn](https://img.shields.io/badge/warning-yellow)
The Update method response status code should be 200 OK.
##### Implementation details
Validation checks the PATCH method for single resource paths and [singleton resources](https://go/ipa/113).

- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation


### IPA-108
Expand Down
Loading
Loading