diff --git a/tools/spectral/ipa/__tests__/IPA117PlaintextResponseMustHaveExample.test.js b/tools/spectral/ipa/__tests__/IPA117PlaintextResponseMustHaveExample.test.js index 718360132e..2e9ac504ce 100644 --- a/tools/spectral/ipa/__tests__/IPA117PlaintextResponseMustHaveExample.test.js +++ b/tools/spectral/ipa/__tests__/IPA117PlaintextResponseMustHaveExample.test.js @@ -34,7 +34,7 @@ testRule('xgen-IPA-117-plaintext-response-must-have-example', [ }, }, }, - // Ignores JSON/YAML + // Ignores JSON/YAML/gzip '/resourceTwo': { get: { responses: { @@ -46,6 +46,16 @@ testRule('xgen-IPA-117-plaintext-response-must-have-example', [ 'application/vnd.atlas.2024-08-05+yaml': { type: 'string', }, + 'application/vnd.atlas.2024-08-05+gzip': { + type: 'string', + format: 'binary', + }, + 'application/vnd.atlas.2023-08-05+gzip': { + schema: { + type: 'string', + format: 'binary', + }, + }, }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-117.yaml b/tools/spectral/ipa/rulesets/IPA-117.yaml index 5ed56c16cb..15f6d428eb 100644 --- a/tools/spectral/ipa/rulesets/IPA-117.yaml +++ b/tools/spectral/ipa/rulesets/IPA-117.yaml @@ -167,6 +167,7 @@ rules: ##### Implementation details - The rule only applies to 2xx responses - The rule ignores JSON and YAML responses (passed as `allowedTypes`) + - The rule ignores responses with `format: 'binary'` (i.e. file types) - The rule checks for the presence of the example property as a sibling to the `schema` property, or inside the `schema` object message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-117-plaintext-response-must-have-example' severity: warn diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 62281e04bd..8f1c4a791f 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -729,6 +729,7 @@ For APIs that respond with plain text, for example CSV, API producers must provi ##### Implementation details - The rule only applies to 2xx responses - The rule ignores JSON and YAML responses (passed as `allowedTypes`) + - The rule ignores responses with `format: 'binary'` (i.e. file types) - The rule checks for the presence of the example property as a sibling to the `schema` property, or inside the `schema` object #### xgen-IPA-117-objects-must-be-well-defined diff --git a/tools/spectral/ipa/rulesets/functions/IPA117PlaintextResponseMustHaveExample.js b/tools/spectral/ipa/rulesets/functions/IPA117PlaintextResponseMustHaveExample.js index 449ee7e842..0257909627 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA117PlaintextResponseMustHaveExample.js +++ b/tools/spectral/ipa/rulesets/functions/IPA117PlaintextResponseMustHaveExample.js @@ -32,6 +32,14 @@ export default (input, { allowedTypes }, { documentInventory, path }) => { const response = resolveObject(documentInventory.resolved, path); + // Ignore binary formats, i.e. files + if ( + (response['type'] && response['format'] === 'binary') || + (response['schema'] && response['schema']['format'] === 'binary') + ) { + return; + } + if (hasException(response, RULE_NAME)) { collectException(response, RULE_NAME, path); return;