From 0f7c74cbaa9b57becdbdee01084ca6c9b1aa9907 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 26 Feb 2025 18:07:22 +0000 Subject: [PATCH 01/15] CLOUDP-271991: IPA-104: Validate for Get methods the response is 200 --- .../getResponseCodeShouldBe200OK.test.js | 100 ++++++++++++++++++ tools/spectral/ipa/rulesets/IPA-104.yaml | 10 ++ .../functions/getResponseCodeShouldBe200OK.js | 29 +++++ 3 files changed, 139 insertions(+) create mode 100644 tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js create mode 100644 tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js new file mode 100644 index 0000000000..58582433bc --- /dev/null +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -0,0 +1,100 @@ +import testRule from './__helpers__/testRule'; +import { DiagnosticSeverity } from '@stoplight/types'; + +testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ + { + name: 'valid methods', + document: { + paths: { + '/path1/{resource}': { + get: { + responses: { + '200': {}, + '400': {}, + '500': {}, + }, + }, + }, + '/path2/{resource}': { + get: { + responses: { + '200': {}, + '401': {}, + '404': {}, + }, + }, + }, + }, + }, + errors: [], + }, + { + name: 'invalid methods', + document: { + paths: { + '/path1/{resource}': { + get: { + responses: { + '201': {}, + '400': {}, + '500': {}, + }, + }, + }, + '/path2/{resource}': { + get: { + responses: { + '400': {}, + '500': {}, + }, + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', + message: 'GET method response code should be 200 OK. http://go/ipa/104', + path: ['paths', '/path1/{resource}'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', + message: 'GET method response code should be 200 OK. http://go/ipa/104', + path: ['paths', '/path2/{resource}'], + severity: DiagnosticSeverity.Warning, + }, + ], + }, + { + name: 'invalid method with exception', + document: { + paths: { + '/path1/{resource}': { + get: { + responses: { + '201': {}, + '400': {}, + '500': {}, + }, + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + }, + }, + '/path2/{resource}': { + get: { + responses: { + '400': {}, + '500': {}, + }, + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + }, + }, + }, + }, + errors: [], + }, +]); diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index f0ef7eed24..1d9a8dcb51 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -3,6 +3,7 @@ functions: - eachResourceHasGetMethod + - getResponseCodeShouldBe200OK rules: xgen-IPA-104-resource-has-GET: @@ -13,3 +14,12 @@ rules: then: field: '@key' function: 'eachResourceHasGetMethod' + + xgen-IPA-104-GET-response-code-should-be-200-OK: + description: 'GET method response code should be 200 OK. http://go/ipa/104' + message: '{{error}} http://go/ipa/104' + severity: warn + given: '$.paths' + then: + field: '@key' + function: 'getResponseCodeShouldBe200OK' \ No newline at end of file diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js new file mode 100644 index 0000000000..dbbf69f4d1 --- /dev/null +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -0,0 +1,29 @@ +import { hasException } from './utils/exceptions.js'; +import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; + +const RULE_NAME = 'xgen-IPA-104-GET-response-code-should-be-200-OK'; +const ERROR_MESSAGE = 'GET method response code should be 200 OK.'; + +export default (input, _, { path, documentInventory }) => { + + const oas = documentInventory.resolved; + + if (hasException(oas.paths[input], RULE_NAME)) { + collectException(oas.paths[input], RULE_NAME, path); + return; + } + + let pathItem = oas.paths[input]; + if(!pathItem.get) { + return; + } + + if(pathItem.get && pathItem.get.responses) { + const responses = pathItem.get.responses; + if(!responses['200']) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + } + } + + collectAdoption(path, RULE_NAME); +}; From 34bd1b6345d72194d7f60464e03e9af87e977ad1 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 10:41:11 +0000 Subject: [PATCH 02/15] prettier fix --- .../getResponseCodeShouldBe200OK.test.js | 32 +++++++++---------- tools/spectral/ipa/rulesets/IPA-104.yaml | 2 +- .../functions/getResponseCodeShouldBe200OK.js | 7 ++-- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index 58582433bc..d1477d88bd 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -9,18 +9,18 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ '/path1/{resource}': { get: { responses: { - '200': {}, - '400': {}, - '500': {}, + 200: {}, + 400: {}, + 500: {}, }, }, }, '/path2/{resource}': { get: { responses: { - '200': {}, - '401': {}, - '404': {}, + 200: {}, + 401: {}, + 404: {}, }, }, }, @@ -35,17 +35,17 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ '/path1/{resource}': { get: { responses: { - '201': {}, - '400': {}, - '500': {}, + 201: {}, + 400: {}, + 500: {}, }, }, }, '/path2/{resource}': { get: { responses: { - '400': {}, - '500': {}, + 400: {}, + 500: {}, }, }, }, @@ -73,9 +73,9 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ '/path1/{resource}': { get: { responses: { - '201': {}, - '400': {}, - '500': {}, + 201: {}, + 400: {}, + 500: {}, }, }, 'x-xgen-IPA-exception': { @@ -85,8 +85,8 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ '/path2/{resource}': { get: { responses: { - '400': {}, - '500': {}, + 400: {}, + 500: {}, }, }, 'x-xgen-IPA-exception': { diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index 1d9a8dcb51..63eb9361aa 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -22,4 +22,4 @@ rules: given: '$.paths' then: field: '@key' - function: 'getResponseCodeShouldBe200OK' \ No newline at end of file + function: 'getResponseCodeShouldBe200OK' diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index dbbf69f4d1..de7794748f 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -5,7 +5,6 @@ const RULE_NAME = 'xgen-IPA-104-GET-response-code-should-be-200-OK'; const ERROR_MESSAGE = 'GET method response code should be 200 OK.'; export default (input, _, { path, documentInventory }) => { - const oas = documentInventory.resolved; if (hasException(oas.paths[input], RULE_NAME)) { @@ -14,13 +13,13 @@ export default (input, _, { path, documentInventory }) => { } let pathItem = oas.paths[input]; - if(!pathItem.get) { + if (!pathItem.get) { return; } - if(pathItem.get && pathItem.get.responses) { + if (pathItem.get && pathItem.get.responses) { const responses = pathItem.get.responses; - if(!responses['200']) { + if (!responses['200']) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } } From 877ab0503ede2f4a7c268be22cc2c2ae93dbd2a6 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 10:42:35 +0000 Subject: [PATCH 03/15] ipa docs gen fix --- tools/spectral/ipa/rulesets/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 1698192e74..3fd6bd54c7 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -28,9 +28,10 @@ For rule definitions, see [IPA-102.yaml](https://github.com/mongodb/openapi/blob For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/IPA-104.yaml). -| Rule Name | Description | Severity | -| ----------------------------- | --------------------------------------------------------------- | -------- | -| xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | +| Rule Name | Description | Severity | +| ----------------------------------------------- | --------------------------------------------------------------- | -------- | +| xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | +| xgen-IPA-104-GET-response-code-should-be-200-OK | GET method response code should be 200 OK. http://go/ipa/104 | warn | ### IPA-109 From 26c1f80120eccbe1d8d8c2784b5c1b73ad80237d Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 13:28:50 +0000 Subject: [PATCH 04/15] operation level exception --- .../getResponseCodeShouldBe200OK.test.js | 20 +++++++++---------- tools/spectral/ipa/rulesets/IPA-104.yaml | 4 ++-- tools/spectral/ipa/rulesets/README.md | 8 ++++---- .../functions/getResponseCodeShouldBe200OK.js | 20 ++++++++----------- .../rulesets/functions/utils/exceptions.js | 1 + 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index d1477d88bd..918cdbbbd9 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -54,14 +54,14 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ errors: [ { code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', - message: 'GET method response code should be 200 OK. http://go/ipa/104', - path: ['paths', '/path1/{resource}'], + message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', + path: ['paths', '/path1/{resource}', 'get'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', - message: 'GET method response code should be 200 OK. http://go/ipa/104', - path: ['paths', '/path2/{resource}'], + message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', + path: ['paths', '/path2/{resource}', 'get'], severity: DiagnosticSeverity.Warning, }, ], @@ -77,9 +77,9 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ 400: {}, 500: {}, }, - }, - 'x-xgen-IPA-exception': { - 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + 'x-xgen-IPA-exception': { + 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + }, }, }, '/path2/{resource}': { @@ -88,9 +88,9 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ 400: {}, 500: {}, }, - }, - 'x-xgen-IPA-exception': { - 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + 'x-xgen-IPA-exception': { + 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + }, }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index 63eb9361aa..ca15fc7b3d 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -16,10 +16,10 @@ rules: function: 'eachResourceHasGetMethod' xgen-IPA-104-GET-response-code-should-be-200-OK: - description: 'GET method response code should be 200 OK. http://go/ipa/104' + description: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104' message: '{{error}} http://go/ipa/104' severity: warn - given: '$.paths' + given: '$.paths.*' then: field: '@key' function: 'getResponseCodeShouldBe200OK' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 3fd6bd54c7..1074c7bc2d 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -28,10 +28,10 @@ For rule definitions, see [IPA-102.yaml](https://github.com/mongodb/openapi/blob For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/IPA-104.yaml). -| Rule Name | Description | Severity | -| ----------------------------------------------- | --------------------------------------------------------------- | -------- | -| xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | -| xgen-IPA-104-GET-response-code-should-be-200-OK | GET method response code should be 200 OK. http://go/ipa/104 | warn | +| Rule Name | Description | Severity | +| ----------------------------------------------- | ------------------------------------------------------------------------------------ | -------- | +| xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | +| xgen-IPA-104-GET-response-code-should-be-200-OK | The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104 | warn | ### IPA-109 diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index de7794748f..ee27451130 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -1,28 +1,24 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-104-GET-response-code-should-be-200-OK'; -const ERROR_MESSAGE = 'GET method response code should be 200 OK.'; +const ERROR_MESSAGE = 'The HTTP response status code for GET operations should be 200 OK.'; export default (input, _, { path, documentInventory }) => { const oas = documentInventory.resolved; - - if (hasException(oas.paths[input], RULE_NAME)) { - collectException(oas.paths[input], RULE_NAME, path); + const getOperation = resolveObject(oas, path); + if (hasException(getOperation, RULE_NAME)) { + collectException(getOperation, RULE_NAME, path); return; } - let pathItem = oas.paths[input]; - if (!pathItem.get) { - return; - } - - if (pathItem.get && pathItem.get.responses) { - const responses = pathItem.get.responses; + if (getOperation.responses) { + const responses = getOperation.responses; if (!responses['200']) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } } - + console.log('adoption'); collectAdoption(path, RULE_NAME); }; diff --git a/tools/spectral/ipa/rulesets/functions/utils/exceptions.js b/tools/spectral/ipa/rulesets/functions/utils/exceptions.js index 256cab89dc..ef2685be1d 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/exceptions.js +++ b/tools/spectral/ipa/rulesets/functions/utils/exceptions.js @@ -9,6 +9,7 @@ export const EXCEPTION_EXTENSION = 'x-xgen-IPA-exception'; */ export function hasException(object, ruleName) { if (object[EXCEPTION_EXTENSION]) { + console.log('exception'); return Object.keys(object[EXCEPTION_EXTENSION]).includes(ruleName); } return false; From d6af94fbf5395c778f41629a6196e5d7b0ecd857 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 16:09:25 +0000 Subject: [PATCH 05/15] fix --- tools/spectral/ipa/rulesets/IPA-104.yaml | 3 +-- .../functions/getResponseCodeShouldBe200OK.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index ca15fc7b3d..02d6d93acc 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -19,7 +19,6 @@ rules: description: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104' message: '{{error}} http://go/ipa/104' severity: warn - given: '$.paths.*' + given: '$.paths[*].get' then: - field: '@key' function: 'getResponseCodeShouldBe200OK' diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index ee27451130..a76cac89e4 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -1,20 +1,19 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; -import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-104-GET-response-code-should-be-200-OK'; const ERROR_MESSAGE = 'The HTTP response status code for GET operations should be 200 OK.'; -export default (input, _, { path, documentInventory }) => { - const oas = documentInventory.resolved; - const getOperation = resolveObject(oas, path); - if (hasException(getOperation, RULE_NAME)) { - collectException(getOperation, RULE_NAME, path); +export default (input, _, { path }) => { + console.log(input); + + if (hasException(input, RULE_NAME)) { + collectException(input, RULE_NAME, path); return; } - if (getOperation.responses) { - const responses = getOperation.responses; + if (input['responses']) { + const responses = input['responses']; if (!responses['200']) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } From 42469fe233a670374d0c817aac8aa228c5b03026 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 16:12:37 +0000 Subject: [PATCH 06/15] fix --- .../getResponseCodeShouldBe200OK.test.js | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index 918cdbbbd9..15b60f09d0 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -6,7 +6,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ name: 'valid methods', document: { paths: { - '/path1/{resource}': { + '/resource': { get: { responses: { 200: {}, @@ -15,12 +15,30 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ }, }, }, - '/path2/{resource}': { + '/resource/{id}': { get: { responses: { 200: {}, - 401: {}, - 404: {}, + 400: {}, + 500: {}, + }, + }, + }, + '/resource/{id}:customMethod': { + get: { + responses: { + 200: {}, + 400: {}, + 500: {}, + }, + }, + }, + '/singleton': { + get: { + responses: { + 200: {}, + 400: {}, + 500: {}, }, }, }, @@ -32,7 +50,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ name: 'invalid methods', document: { paths: { - '/path1/{resource}': { + '/resource1/{id}': { get: { responses: { 201: {}, @@ -41,7 +59,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ }, }, }, - '/path2/{resource}': { + '/resource2/{id}': { get: { responses: { 400: {}, @@ -55,13 +73,13 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ { code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', - path: ['paths', '/path1/{resource}', 'get'], + path: ['paths', '/resource1/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', - path: ['paths', '/path2/{resource}', 'get'], + path: ['paths', '/resource2/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, ], @@ -70,7 +88,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ name: 'invalid method with exception', document: { paths: { - '/path1/{resource}': { + '/resource1/{id}': { get: { responses: { 201: {}, @@ -82,7 +100,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ }, }, }, - '/path2/{resource}': { + '/resource2/{id}': { get: { responses: { 400: {}, From bd7456a96de4fc306902c7f90a062becfe41e1e4 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 16:18:29 +0000 Subject: [PATCH 07/15] rule name fix --- .../__tests__/getResponseCodeShouldBe200OK.test.js | 14 +++++++------- tools/spectral/ipa/rulesets/IPA-104.yaml | 2 +- tools/spectral/ipa/rulesets/README.md | 4 +--- .../functions/getResponseCodeShouldBe200OK.js | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index 15b60f09d0..a43e53acb5 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -1,7 +1,7 @@ import testRule from './__helpers__/testRule'; import { DiagnosticSeverity } from '@stoplight/types'; -testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ +testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ { name: 'valid methods', document: { @@ -71,14 +71,14 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ }, errors: [ { - code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', - message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', + code: 'xgen-IPA-104-get-method-response-code-should-be-200-OK', + message: 'The HTTP response status code for get operations should be 200 OK. http://go/ipa/104', path: ['paths', '/resource1/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, { - code: 'xgen-IPA-104-GET-response-code-should-be-200-OK', - message: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104', + code: 'xgen-IPA-104-get-method-response-code-should-be-200-OK', + message: 'The HTTP response status code for get operations should be 200 OK. http://go/ipa/104', path: ['paths', '/resource2/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, @@ -96,7 +96,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-should-be-200-OK': 'reason', }, }, }, @@ -107,7 +107,7 @@ testRule('xgen-IPA-104-GET-response-code-should-be-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-GET-response-code-should-be-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-should-be-200-OK': 'reason', }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index cc2f73ef32..d0472cb0da 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -23,7 +23,7 @@ rules: then: function: 'getMethodReturnsSingleResource' - xgen-IPA-104-GET-response-code-should-be-200-OK: + xgen-IPA-104-get-method-response-code-is-200-OK: description: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104' message: '{{error}} http://go/ipa/104' severity: warn diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 2fec6beae2..a1a3f4f671 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -32,7 +32,7 @@ For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | -------- | | xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | | xgen-IPA-104-get-method-returns-single-resource | The purpose of the get method is to return data from a single resource. http://go/ipa/104 | warn | -| xgen-IPA-104-GET-response-code-should-be-200-OK | The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104 | warn | +| xgen-IPA-104-get-method-response-code-is-200-OK | The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104 | warn | ### IPA-109 @@ -58,5 +58,3 @@ For rule definitions, see [IPA-123.yaml](https://github.com/mongodb/openapi/blob | Rule Name | Description | Severity | | ------------------------------------------------- | ------------------------------------------------------- | -------- | | xgen-IPA-123-enum-values-must-be-upper-snake-case | Enum values must be UPPER_SNAKE_CASE. http://go/ipa/123 | warn | - - diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index a76cac89e4..03a1a05f27 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -1,7 +1,7 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; -const RULE_NAME = 'xgen-IPA-104-GET-response-code-should-be-200-OK'; +const RULE_NAME = 'xgen-IPA-104-get-method-response-code-is-200-OK'; const ERROR_MESSAGE = 'The HTTP response status code for GET operations should be 200 OK.'; export default (input, _, { path }) => { From 12003f85763ff5196891cd2c7c2531f9cb666cbd Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 27 Feb 2025 16:32:08 +0000 Subject: [PATCH 08/15] rule name fix --- .../getResponseCodeShouldBe200OK.test.js | 31 +++++++++++++++---- tools/spectral/ipa/rulesets/IPA-104.yaml | 2 +- tools/spectral/ipa/rulesets/README.md | 4 ++- .../functions/getResponseCodeShouldBe200OK.js | 14 ++++++--- .../rulesets/functions/utils/exceptions.js | 1 - 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index a43e53acb5..518f815d2d 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -67,21 +67,40 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ }, }, }, + '/resource3/{id}': { + get: { + responses: { + 200: {}, + 201: {}, + 400: {}, + 500: {}, + }, + }, + }, }, }, errors: [ { - code: 'xgen-IPA-104-get-method-response-code-should-be-200-OK', - message: 'The HTTP response status code for get operations should be 200 OK. http://go/ipa/104', + code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + message: + 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', path: ['paths', '/resource1/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, { - code: 'xgen-IPA-104-get-method-response-code-should-be-200-OK', - message: 'The HTTP response status code for get operations should be 200 OK. http://go/ipa/104', + code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + message: + 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', path: ['paths', '/resource2/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, + { + code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + message: + 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', + path: ['paths', '/resource3/{id}', 'get'], + severity: DiagnosticSeverity.Warning, + }, ], }, { @@ -96,7 +115,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-get-method-response-code-should-be-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-is-200-OK': 'reason', }, }, }, @@ -107,7 +126,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-get-method-response-code-should-be-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-is-200-OK': 'reason', }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index d0472cb0da..1360b689ea 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -24,7 +24,7 @@ rules: function: 'getMethodReturnsSingleResource' xgen-IPA-104-get-method-response-code-is-200-OK: - description: 'The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104' + description: 'The Get method must return a 200 OK response. http://go/ipa/104' message: '{{error}} http://go/ipa/104' severity: warn given: '$.paths[*].get' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index a1a3f4f671..c0aa72c9b9 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -32,7 +32,7 @@ For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | -------- | | xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | | xgen-IPA-104-get-method-returns-single-resource | The purpose of the get method is to return data from a single resource. http://go/ipa/104 | warn | -| xgen-IPA-104-get-method-response-code-is-200-OK | The HTTP response status code for GET operations should be 200 OK. http://go/ipa/104 | warn | +| xgen-IPA-104-get-method-response-code-is-200-OK | The Get method must return a 200 OK response. http://go/ipa/104 | warn | ### IPA-109 @@ -58,3 +58,5 @@ For rule definitions, see [IPA-123.yaml](https://github.com/mongodb/openapi/blob | Rule Name | Description | Severity | | ------------------------------------------------- | ------------------------------------------------------- | -------- | | xgen-IPA-123-enum-values-must-be-upper-snake-case | Enum values must be UPPER_SNAKE_CASE. http://go/ipa/123 | warn | + + diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index 03a1a05f27..5941618be0 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -2,11 +2,10 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-104-get-method-response-code-is-200-OK'; -const ERROR_MESSAGE = 'The HTTP response status code for GET operations should be 200 OK.'; +const ERROR_MESSAGE = + 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code.'; export default (input, _, { path }) => { - console.log(input); - if (hasException(input, RULE_NAME)) { collectException(input, RULE_NAME, path); return; @@ -14,10 +13,17 @@ export default (input, _, { path }) => { if (input['responses']) { const responses = input['responses']; + + // If there is no 200 response, return a violation if (!responses['200']) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } + + // If there are other 2xx responses that are not 200, return a violation + if (Object.keys(responses).some((key) => key.startsWith('2') && key !== '200')) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + } } - console.log('adoption'); + collectAdoption(path, RULE_NAME); }; diff --git a/tools/spectral/ipa/rulesets/functions/utils/exceptions.js b/tools/spectral/ipa/rulesets/functions/utils/exceptions.js index ef2685be1d..256cab89dc 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/exceptions.js +++ b/tools/spectral/ipa/rulesets/functions/utils/exceptions.js @@ -9,7 +9,6 @@ export const EXCEPTION_EXTENSION = 'x-xgen-IPA-exception'; */ export function hasException(object, ruleName) { if (object[EXCEPTION_EXTENSION]) { - console.log('exception'); return Object.keys(object[EXCEPTION_EXTENSION]).includes(ruleName); } return false; From d210b0f9c8270b49b5774dad3fdb9323b2e1c3ba Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 10:37:53 +0000 Subject: [PATCH 09/15] address the comments --- .../getResponseCodeShouldBe200OK.test.js | 20 ++++++++++--------- tools/spectral/ipa/rulesets/IPA-104.yaml | 2 +- .../functions/getResponseCodeShouldBe200OK.js | 12 ++++++++++- .../rulesets/functions/utils/methodUtils.js | 6 ++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index 518f815d2d..efd64c4295 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -1,7 +1,7 @@ import testRule from './__helpers__/testRule'; import { DiagnosticSeverity } from '@stoplight/types'; -testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ +testRule('xgen-IPA-104-get-method-response-code-is-200', [ { name: 'valid methods', document: { @@ -9,7 +9,6 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ '/resource': { get: { responses: { - 200: {}, 400: {}, 500: {}, }, @@ -27,7 +26,6 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ '/resource/{id}:customMethod': { get: { responses: { - 200: {}, 400: {}, 500: {}, }, @@ -36,7 +34,6 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ '/singleton': { get: { responses: { - 200: {}, 400: {}, 500: {}, }, @@ -50,6 +47,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ name: 'invalid methods', document: { paths: { + '/resource1': { get: { responses: {}}}, '/resource1/{id}': { get: { responses: { @@ -59,6 +57,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ }, }, }, + '/resource2': { get: { responses: {} }}, '/resource2/{id}': { get: { responses: { @@ -67,6 +66,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ }, }, }, + '/resource3': { get: { responses: {}}}, '/resource3/{id}': { get: { responses: { @@ -81,21 +81,21 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ }, errors: [ { - code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + code: 'xgen-IPA-104-get-method-response-code-is-200', message: 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', path: ['paths', '/resource1/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, { - code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + code: 'xgen-IPA-104-get-method-response-code-is-200', message: 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', path: ['paths', '/resource2/{id}', 'get'], severity: DiagnosticSeverity.Warning, }, { - code: 'xgen-IPA-104-get-method-response-code-is-200-OK', + code: 'xgen-IPA-104-get-method-response-code-is-200', message: 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa/104', path: ['paths', '/resource3/{id}', 'get'], @@ -107,6 +107,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ name: 'invalid method with exception', document: { paths: { + '/resource1': { get: {responses: {}}}, '/resource1/{id}': { get: { responses: { @@ -115,10 +116,11 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-get-method-response-code-is-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-is-200': 'reason', }, }, }, + '/resource2': { get: {responses: {}}}, '/resource2/{id}': { get: { responses: { @@ -126,7 +128,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200-OK', [ 500: {}, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-104-get-method-response-code-is-200-OK': 'reason', + 'xgen-IPA-104-get-method-response-code-is-200': 'reason', }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-104.yaml b/tools/spectral/ipa/rulesets/IPA-104.yaml index 1360b689ea..da80f33d11 100644 --- a/tools/spectral/ipa/rulesets/IPA-104.yaml +++ b/tools/spectral/ipa/rulesets/IPA-104.yaml @@ -23,7 +23,7 @@ rules: then: function: 'getMethodReturnsSingleResource' - xgen-IPA-104-get-method-response-code-is-200-OK: + xgen-IPA-104-get-method-response-code-is-200: description: 'The Get method must return a 200 OK response. http://go/ipa/104' message: '{{error}} http://go/ipa/104' severity: warn diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index 5941618be0..7f47d14c5c 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -1,11 +1,21 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { + isChild, + isCustomMethod, +} from './utils/resourceEvaluation.js'; -const RULE_NAME = 'xgen-IPA-104-get-method-response-code-is-200-OK'; +const RULE_NAME = 'xgen-IPA-104-get-method-response-code-is-200'; const ERROR_MESSAGE = 'The Get method must return a 200 OK response. This method either lacks a 200 OK response or defines a different 2xx status code.'; export default (input, _, { path }) => { + const resourcePath = path[1]; + + if (isCustomMethod(resourcePath) || !isChild(resourcePath)) { + return; + } + if (hasException(input, RULE_NAME)) { collectException(input, RULE_NAME, path); return; diff --git a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js index 8781360966..d39b8cfb15 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js +++ b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js @@ -1,3 +1,5 @@ +import { schemaIsArray, schemaIsPaginated } from './schemaUtils.js'; + /** * Returns a list of all successful response schemas for the passed operation, i.e. for any 2xx response. * @@ -29,3 +31,7 @@ export function getAllSuccessfulResponseSchemas(operationObject) { }); return result; } + +export function returnsSingleResource(schema) { + return !schemaIsArray(schema) && !schemaIsPaginated(schema); +} From 62be91a1e36945ab2ff85d7db41735de700149d3 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 10:38:39 +0000 Subject: [PATCH 10/15] address the comments --- .../ipa/__tests__/getResponseCodeShouldBe200OK.test.js | 10 +++++----- tools/spectral/ipa/rulesets/README.md | 4 +--- .../rulesets/functions/getResponseCodeShouldBe200OK.js | 5 +---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js index efd64c4295..4d26b4109b 100644 --- a/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js +++ b/tools/spectral/ipa/__tests__/getResponseCodeShouldBe200OK.test.js @@ -47,7 +47,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [ name: 'invalid methods', document: { paths: { - '/resource1': { get: { responses: {}}}, + '/resource1': { get: { responses: {} } }, '/resource1/{id}': { get: { responses: { @@ -57,7 +57,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [ }, }, }, - '/resource2': { get: { responses: {} }}, + '/resource2': { get: { responses: {} } }, '/resource2/{id}': { get: { responses: { @@ -66,7 +66,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [ }, }, }, - '/resource3': { get: { responses: {}}}, + '/resource3': { get: { responses: {} } }, '/resource3/{id}': { get: { responses: { @@ -107,7 +107,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [ name: 'invalid method with exception', document: { paths: { - '/resource1': { get: {responses: {}}}, + '/resource1': { get: { responses: {} } }, '/resource1/{id}': { get: { responses: { @@ -120,7 +120,7 @@ testRule('xgen-IPA-104-get-method-response-code-is-200', [ }, }, }, - '/resource2': { get: {responses: {}}}, + '/resource2': { get: { responses: {} } }, '/resource2/{id}': { get: { responses: { diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index c0aa72c9b9..635c5bcb6c 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -32,7 +32,7 @@ For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | -------- | | xgen-IPA-104-resource-has-GET | APIs must provide a get method for resources. http://go/ipa/104 | warn | | xgen-IPA-104-get-method-returns-single-resource | The purpose of the get method is to return data from a single resource. http://go/ipa/104 | warn | -| xgen-IPA-104-get-method-response-code-is-200-OK | The Get method must return a 200 OK response. http://go/ipa/104 | warn | +| xgen-IPA-104-get-method-response-code-is-200 | The Get method must return a 200 OK response. http://go/ipa/104 | warn | ### IPA-109 @@ -58,5 +58,3 @@ For rule definitions, see [IPA-123.yaml](https://github.com/mongodb/openapi/blob | Rule Name | Description | Severity | | ------------------------------------------------- | ------------------------------------------------------- | -------- | | xgen-IPA-123-enum-values-must-be-upper-snake-case | Enum values must be UPPER_SNAKE_CASE. http://go/ipa/123 | warn | - - diff --git a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js index 7f47d14c5c..aab6a0ff8f 100644 --- a/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/getResponseCodeShouldBe200OK.js @@ -1,9 +1,6 @@ import { hasException } from './utils/exceptions.js'; import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; -import { - isChild, - isCustomMethod, -} from './utils/resourceEvaluation.js'; +import { isChild, isCustomMethod } from './utils/resourceEvaluation.js'; const RULE_NAME = 'xgen-IPA-104-get-method-response-code-is-200'; const ERROR_MESSAGE = From 99de49f3f1a23a2272f151311a8d1d7b1b55767b Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 10:41:29 +0000 Subject: [PATCH 11/15] rollback changes --- .../spectral/ipa/rulesets/functions/utils/methodUtils.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js index d39b8cfb15..ea558bdd17 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js +++ b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js @@ -1,5 +1,3 @@ -import { schemaIsArray, schemaIsPaginated } from './schemaUtils.js'; - /** * Returns a list of all successful response schemas for the passed operation, i.e. for any 2xx response. * @@ -30,8 +28,4 @@ export function getAllSuccessfulResponseSchemas(operationObject) { } }); return result; -} - -export function returnsSingleResource(schema) { - return !schemaIsArray(schema) && !schemaIsPaginated(schema); -} +} \ No newline at end of file From 97c5bbf590c6bf3d967375572a177143d9b81e0a Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 10:41:54 +0000 Subject: [PATCH 12/15] rollback changes --- tools/spectral/ipa/rulesets/functions/utils/methodUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js index ea558bdd17..8781360966 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js +++ b/tools/spectral/ipa/rulesets/functions/utils/methodUtils.js @@ -28,4 +28,4 @@ export function getAllSuccessfulResponseSchemas(operationObject) { } }); return result; -} \ No newline at end of file +} From 7a1f68d3b231c08c38448241b6943ef7db753902 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 11:26:36 +0000 Subject: [PATCH 13/15] rollback changes --- tools/spectral/ipa/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/spectral/ipa/README.md b/tools/spectral/ipa/README.md index a7e42d1275..359f357318 100644 --- a/tools/spectral/ipa/README.md +++ b/tools/spectral/ipa/README.md @@ -32,6 +32,7 @@ spectral lint {path/to/oas/file} --ruleset=./tools/spectral/ipa/ipa-spectral.yam The rule validations are custom JS functions (see [/rulesets/functions](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/rulesets/functions)). To learn more about custom functions, refer to the [Spectral Documentation](https://docs.stoplight.io/docs/spectral/a781e290eb9f9-custom-functions). The custom rule implementation allows for: + - Advanced validations not available using the standard Spectral rules - Custom exception handling - Metrics collection @@ -49,8 +50,8 @@ Instead of using the [Spectral overrides approach](https://docs.stoplight.io/doc ## Testing - IPA Validation related code is tested using [Jest](https://jestjs.io/) -- Each custom validation function has tests, located in [/\__tests\__](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__). They use the test hook [testRule.js](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/__tests__/__helpers__/testRule.js) as a common approach for Spectral rule testing -- Helper/util functions are tested as well, see [/\__tests\__/utils](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__/utils) +- Each custom validation function has tests, located in [/\_\_tests\_\_](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__). They use the test hook [testRule.js](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/__tests__/__helpers__/testRule.js) as a common approach for Spectral rule testing +- Helper/util functions are tested as well, see [/\_\_tests\_\_/utils](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__/utils) Install necessary dependencies with `npm install` if you haven't already. All Jest tests can be run with: From cadb9ca88647a539b5059e6f9737d77b4d31e9e8 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 11:28:35 +0000 Subject: [PATCH 14/15] rollback changes --- tools/spectral/ipa/README.md | 5 ++--- tools/spectral/ipa/rulesets/README.md | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/spectral/ipa/README.md b/tools/spectral/ipa/README.md index 359f357318..a7e42d1275 100644 --- a/tools/spectral/ipa/README.md +++ b/tools/spectral/ipa/README.md @@ -32,7 +32,6 @@ spectral lint {path/to/oas/file} --ruleset=./tools/spectral/ipa/ipa-spectral.yam The rule validations are custom JS functions (see [/rulesets/functions](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/rulesets/functions)). To learn more about custom functions, refer to the [Spectral Documentation](https://docs.stoplight.io/docs/spectral/a781e290eb9f9-custom-functions). The custom rule implementation allows for: - - Advanced validations not available using the standard Spectral rules - Custom exception handling - Metrics collection @@ -50,8 +49,8 @@ Instead of using the [Spectral overrides approach](https://docs.stoplight.io/doc ## Testing - IPA Validation related code is tested using [Jest](https://jestjs.io/) -- Each custom validation function has tests, located in [/\_\_tests\_\_](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__). They use the test hook [testRule.js](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/__tests__/__helpers__/testRule.js) as a common approach for Spectral rule testing -- Helper/util functions are tested as well, see [/\_\_tests\_\_/utils](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__/utils) +- Each custom validation function has tests, located in [/\__tests\__](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__). They use the test hook [testRule.js](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/__tests__/__helpers__/testRule.js) as a common approach for Spectral rule testing +- Helper/util functions are tested as well, see [/\__tests\__/utils](https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa/__tests__/utils) Install necessary dependencies with `npm install` if you haven't already. All Jest tests can be run with: diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 635c5bcb6c..09cc863155 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -58,3 +58,4 @@ For rule definitions, see [IPA-123.yaml](https://github.com/mongodb/openapi/blob | Rule Name | Description | Severity | | ------------------------------------------------- | ------------------------------------------------------- | -------- | | xgen-IPA-123-enum-values-must-be-upper-snake-case | Enum values must be UPPER_SNAKE_CASE. http://go/ipa/123 | warn | + From 586eede353db90d02970bbc0090db7e81b96380f Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Mon, 3 Mar 2025 11:35:39 +0000 Subject: [PATCH 15/15] rollback changes --- tools/spectral/ipa/rulesets/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 09cc863155..db001ccf4f 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -59,3 +59,4 @@ For rule definitions, see [IPA-123.yaml](https://github.com/mongodb/openapi/blob | ------------------------------------------------- | ------------------------------------------------------- | -------- | | xgen-IPA-123-enum-values-must-be-upper-snake-case | Enum values must be UPPER_SNAKE_CASE. http://go/ipa/123 | warn | +