diff --git a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js index 86a1cd5fbc..892e5bfbc3 100644 --- a/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js +++ b/tools/spectral/ipa/__tests__/createMethodRequestBodyIsRequestSuffixedObject.test.js @@ -31,6 +31,14 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ $ref: '#/components/schemas/SchemaRequest', }, }, + 'application/vnd.atlas.2025-01-01+json': { + schema: { + type: 'array', + items: { + $ref: '#/components/schemas/SchemaRequest', + }, + }, + }, }, }, }, @@ -89,6 +97,14 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ $ref: '#/components/schemas/Schema', }, }, + 'application/vnd.atlas.2024-01-01+json': { + schema: { + type: 'array', + items: { + $ref: '#/components/schemas/Schema', + }, + }, + }, }, }, }, @@ -133,6 +149,12 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [ 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: '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.2024-01-01+json'], + severity: DiagnosticSeverity.Warning, + }, { code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object', message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106', @@ -170,6 +192,17 @@ 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: { + type: 'array', + items: { + $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/functions/createMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js index 4f3944a4c9..d9eda6ead6 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodRequestBodyIsRequestSuffixedObject.js @@ -24,14 +24,24 @@ export default (input, _, { path, documentInventory }) => { if (contentPerMediaType.schema) { const schema = contentPerMediaType.schema; - if (!schema.$ref) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_REF); + if (schema.type === 'array' && schema.items) { + let schemaItems = schema.items; + if (!schemaItems.$ref) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_REF); + } + if (!schemaItems.$ref.endsWith('Request')) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_NAME); + } + } else { + if (!schema.$ref) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_REF); + } + + if (!schema.$ref.endsWith('Request')) { + return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_NAME); + } } - if (!schema.$ref.endsWith('Request')) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE_SCHEMA_NAME); - } + collectAdoption(path, RULE_NAME); } - - collectAdoption(path, RULE_NAME); };