From bc9e11347c0f931f2233232e0c8051bd02f31af9 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 15:56:12 +0000 Subject: [PATCH 1/7] CLOUDP-304055: IPA-106 Create: The request should be a Request suffixed object --- ...RequestBodyIsRequestSuffixedObject.test.js | 181 ++++++++++++++++++ tools/spectral/ipa/ipa-spectral.yaml | 1 + tools/spectral/ipa/rulesets/IPA-106.yaml | 14 ++ tools/spectral/ipa/rulesets/README.md | 8 + ...ethodRequestBodyIsRequestSuffixedObject.js | 41 ++++ 5 files changed, 245 insertions(+) create mode 100644 tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js create mode 100644 tools/spectral/ipa/rulesets/IPA-106.yaml create mode 100644 tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js new file mode 100644 index 0000000000..3cdd9e2495 --- /dev/null +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -0,0 +1,181 @@ +import testRule from './__helpers__/testRule'; +import { DiagnosticSeverity } from '@stoplight/types'; + +const componentSchemas = { + schemas: { + SchemaRequest: { + type: 'object', + }, + Schema: { + type: 'object', + }, + }, +}; +testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ + { + name: 'valid methods', + document: { + components: componentSchemas, + paths: { + '/resource': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + }, + }, + }, + }, + '/resource/{id}': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + }, + }, + }, + }, + '/resource/{id}:customMethod': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + }, + }, + }, + }, + }, + }, + errors: [], + }, + { + name: 'invalid methods', + document: { + components: componentSchemas, + paths: { + '/resource': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + }, + }, + }, + }, + '/resource/{id}': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + }, + }, + }, + }, + '/resource2': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + }, + }, + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + path: ['paths', '/resource/{id}', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', + message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], + severity: DiagnosticSeverity.Warning, + }, + ], + }, + { + name: 'invalid method with exception', + document: { + components: componentSchemas, + paths: { + '/resource': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, + }, + }, + }, + }, + }, + }, + errors: [], + }, +]); diff --git a/tools/spectral/ipa/ipa-spectral.yaml b/tools/spectral/ipa/ipa-spectral.yaml index 4b1b04fd73..d9ee29a7e6 100644 --- a/tools/spectral/ipa/ipa-spectral.yaml +++ b/tools/spectral/ipa/ipa-spectral.yaml @@ -5,6 +5,7 @@ extends: - ./rulesets/IPA-109.yaml - ./rulesets/IPA-113.yaml - ./rulesets/IPA-123.yaml + - ./rulesets/IPA-106.yaml overrides: - files: diff --git a/tools/spectral/ipa/rulesets/IPA-106.yaml b/tools/spectral/ipa/rulesets/IPA-106.yaml new file mode 100644 index 0000000000..babe31b8f0 --- /dev/null +++ b/tools/spectral/ipa/rulesets/IPA-106.yaml @@ -0,0 +1,14 @@ +# IPA-104: Create +# http://go/ipa/106 + +functions: + - createMethodRequestBodyIsRequestSuffixedObject + +rules: + xgen-IPA-106-create-method-request-body-is-request-suffixed-object: + description: 'The Create method request should be a Request suffixed object. http://go/ipa/106' + message: '{{error}} http://go/ipa/106' + severity: warn + given: '$.paths[*].post.requestBody.content' + then: + function: 'createMethodRequestBodyIsRequestSuffixedObject' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index db001ccf4f..43f9ae370a 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -34,6 +34,14 @@ For rule definitions, see [IPA-104.yaml](https://github.com/mongodb/openapi/blob | 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 | The Get method must return a 200 OK response. http://go/ipa/104 | warn | +### IPA-106 + +For rule definitions, see [IPA-106.yaml](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/IPA-106.yaml). + +| Rule Name | Description | Severity | +| ------------------------------------------------------------------ | -------------------------------------------------------------------------------- | -------- | +| xgen-IPA-106-create-method-request-body-is-request-suffixed-object | The Create method request should be a Request suffixed object. http://go/ipa/106 | warn | + ### IPA-109 For rule definitions, see [IPA-109.yaml](https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/IPA-109.yaml). diff --git a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js new file mode 100644 index 0000000000..7f40b0c854 --- /dev/null +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -0,0 +1,41 @@ +import { hasException } from './utils/exceptions.js'; +import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { isCustomMethod } from './utils/resourceEvaluation.js'; +import { resolveObject } from './utils/componentUtils.js'; + +const RULE_NAME = 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object'; +const ERROR_MESSAGE = 'Response body for the Create method should refer to Request suffixed schema.'; + +export default (input, _, { path, documentInventory }) => { + const oas = documentInventory.unresolved; + const resourcePath = path[1]; + if (isCustomMethod(resourcePath)) { + return; + } + + const content = resolveObject(oas, path); + if (hasException(content, RULE_NAME)) { + collectException(content, RULE_NAME, path); + return; + } + + const errors = []; + for (const mediaType in content) { + const media = content[mediaType]; + if (media.schema) { + const schema = media.schema; + if (schema.$ref && !schema.$ref.endsWith('Request')) { + errors.push({ + path: path.concat(mediaType), + message: `${ERROR_MESSAGE}`, + }); + } + } + } + + if (errors.length === 0) { + collectAdoption(path, RULE_NAME); + } else { + return collectAndReturnViolation(path, RULE_NAME, errors); + } +}; From a32c1520dbc1b34e5806e721f438694ec790bbc3 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 16:54:11 +0000 Subject: [PATCH 2/7] inline schemas --- ...RequestBodyIsRequestSuffixedObject.test.js | 66 +++++++++++++++---- tools/spectral/ipa/rulesets/IPA-106.yaml | 1 + tools/spectral/ipa/rulesets/README.md | 2 - ...ethodRequestBodyIsRequestSuffixedObject.js | 32 ++++----- 4 files changed, 67 insertions(+), 34 deletions(-) diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js index 3cdd9e2495..8e43f096b0 100644 --- a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -93,7 +93,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ }, }, }, - '/resource/{id}': { + '/resource2': { post: { requestBody: { content: { @@ -102,22 +102,22 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ $ref: '#/components/schemas/Schema', }, }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + }, }, }, }, }, - '/resource2': { + '/resource3': { post: { requestBody: { content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - $ref: '#/components/schemas/Schema', - }, - }, - 'application/vnd.atlas.2024-01-01+json': { - schema: { - $ref: '#/components/schemas/Schema', + type: "object", }, }, }, @@ -136,19 +136,19 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', - path: ['paths', '/resource/{id}', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', - path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], + path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', - path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], + path: ['paths', '/resource3', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], severity: DiagnosticSeverity.Warning, }, ], @@ -166,9 +166,49 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ schema: { $ref: '#/components/schemas/Schema', }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, + }, + }, + }, + }, + }, + '/resource/{id}': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, + }, + }, + }, + }, + }, + '/resource2': { + post: { + requestBody: { + content: { + 'application/vnd.atlas.2023-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, }, - 'x-xgen-IPA-exception': { - 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-106.yaml b/tools/spectral/ipa/rulesets/IPA-106.yaml index babe31b8f0..b8e695bc50 100644 --- a/tools/spectral/ipa/rulesets/IPA-106.yaml +++ b/tools/spectral/ipa/rulesets/IPA-106.yaml @@ -11,4 +11,5 @@ rules: severity: warn given: '$.paths[*].post.requestBody.content' then: + field: '@key' function: 'createMethodRequestBodyIsRequestSuffixedObject' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 43f9ae370a..bab9e44fc2 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -66,5 +66,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/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js index 7f40b0c854..0fcf2157ac 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -9,33 +9,27 @@ const ERROR_MESSAGE = 'Response body for the Create method should refer to Reque export default (input, _, { path, documentInventory }) => { const oas = documentInventory.unresolved; const resourcePath = path[1]; + if (isCustomMethod(resourcePath)) { return; } - const content = resolveObject(oas, path); - if (hasException(content, RULE_NAME)) { - collectException(content, RULE_NAME, path); + const contentPerMediaType = resolveObject(oas, path); + + if (hasException(contentPerMediaType, RULE_NAME)) { + collectException(contentPerMediaType, RULE_NAME, path); return; } - const errors = []; - for (const mediaType in content) { - const media = content[mediaType]; - if (media.schema) { - const schema = media.schema; - if (schema.$ref && !schema.$ref.endsWith('Request')) { - errors.push({ - path: path.concat(mediaType), - message: `${ERROR_MESSAGE}`, - }); - } + if (contentPerMediaType.schema) { + const schema = contentPerMediaType.schema; + if (schema.$ref && !schema.$ref.endsWith('Request')) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + } + if(!schema.$ref) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } } - if (errors.length === 0) { - collectAdoption(path, RULE_NAME); - } else { - return collectAndReturnViolation(path, RULE_NAME, errors); - } + collectAdoption(path, RULE_NAME); }; From 4d22b78c7b2bda742fa1e891d71be8960840dbbf Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 16:55:03 +0000 Subject: [PATCH 3/7] fix --- .../createMethodRequestBodyIsRequestSuffixedObject.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js index 0fcf2157ac..1a2db79955 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -23,10 +23,11 @@ export default (input, _, { path, documentInventory }) => { if (contentPerMediaType.schema) { const schema = contentPerMediaType.schema; - if (schema.$ref && !schema.$ref.endsWith('Request')) { + if(!schema.$ref) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } - if(!schema.$ref) { + + if (!schema.$ref.endsWith('Request')) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } } From f72a01334371d1c1a787bac93ed7c9f5623ac483 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 16:55:57 +0000 Subject: [PATCH 4/7] test fix --- ...RequestBodyIsRequestSuffixedObject.test.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js index 8e43f096b0..ce1eb6a155 100644 --- a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -174,7 +174,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ }, }, }, - '/resource/{id}': { + '/resource2': { post: { requestBody: { content: { @@ -186,25 +186,25 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', }, }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + $ref: '#/components/schemas/Schema', + }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', + }, + }, }, }, }, }, - '/resource2': { + '/resource3': { post: { requestBody: { content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - $ref: '#/components/schemas/Schema', - }, - 'x-xgen-IPA-exception': { - 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', - }, - }, - 'application/vnd.atlas.2024-01-01+json': { - schema: { - $ref: '#/components/schemas/Schema', + type: "object", }, 'x-xgen-IPA-exception': { 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', From b48e4307d2e5e19fac8f6e0c05a2d63977a76089 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 17:18:08 +0000 Subject: [PATCH 5/7] error message fix --- ...createMethodRequestBodyIsRequestSuffixedObject.test.js | 8 ++++---- .../createMethodRequestBodyIsRequestSuffixedObject.js | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js index ce1eb6a155..f41c06f2fb 100644 --- a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -129,25 +129,25 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ errors: [ { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', - message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', - message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', - message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', - message: 'Response body for the Create method should refer to Request suffixed schema. http://go/ipa/106', + message: 'The response body schema is defined inline and must reference a predefined schema. http://go/ipa/106', path: ['paths', '/resource3', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'], severity: DiagnosticSeverity.Warning, }, diff --git a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js index 1a2db79955..15ecaba765 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -4,7 +4,8 @@ import { isCustomMethod } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object'; -const ERROR_MESSAGE = 'Response body for the Create method should refer to Request suffixed schema.'; +const ERROR_MESSAGE_SCHEMA_NAME = 'The response body schema must reference a schema with a Request suffix.'; +const ERROR_MESSAGE_SCHEMA_REF = 'The response body schema is defined inline and must reference a predefined schema.'; export default (input, _, { path, documentInventory }) => { const oas = documentInventory.unresolved; @@ -24,11 +25,11 @@ export default (input, _, { path, documentInventory }) => { if (contentPerMediaType.schema) { const schema = contentPerMediaType.schema; if(!schema.$ref) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_REF); } if (!schema.$ref.endsWith('Request')) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_NAME); } } From 1c820e5e9fc13b04be1ea35c26cc2228f30b5301 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 17:20:59 +0000 Subject: [PATCH 6/7] prettier fix --- .../createMethodRequestBodyIsRequestSuffixedObject.test.js | 4 ++-- .../createMethodRequestBodyIsRequestSuffixedObject.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js index f41c06f2fb..86a1cd5fbc 100644 --- a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -117,7 +117,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - type: "object", + type: 'object', }, }, }, @@ -204,7 +204,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - type: "object", + type: 'object', }, 'x-xgen-IPA-exception': { 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object': 'reason', diff --git a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js index 15ecaba765..4f3944a4c9 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -24,7 +24,7 @@ export default (input, _, { path, documentInventory }) => { if (contentPerMediaType.schema) { const schema = contentPerMediaType.schema; - if(!schema.$ref) { + if (!schema.$ref) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_REF); } From aedfe99d204c5bccf35deac9eb045c2b14211d95 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Mar 2025 17:25:45 +0000 Subject: [PATCH 7/7] readme fix --- tools/spectral/ipa/rulesets/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index bab9e44fc2..43f9ae370a 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -66,3 +66,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 | + +