From a8dff8cc44f439aadc5c75ed8d68cb29432dd8df Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Thu, 6 Mar 2025 17:39:33 +0000 Subject: [PATCH] CLOUDP-271994: IPA-106: Validate Create methods accepts no query params (ignore envelope and pretty query params) --- ...reateMethodShouldNotHaveQueryParameters.test.js | 14 ++++++++++++++ .../createMethodShouldNotHaveQueryParameters.js | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/spectral/ipa/__tests__/createMethodShouldNotHaveQueryParameters.test.js b/tools/spectral/ipa/__tests__/createMethodShouldNotHaveQueryParameters.test.js index 2976a6534d..cb02e27347 100644 --- a/tools/spectral/ipa/__tests__/createMethodShouldNotHaveQueryParameters.test.js +++ b/tools/spectral/ipa/__tests__/createMethodShouldNotHaveQueryParameters.test.js @@ -22,6 +22,14 @@ const componentSchemas = { type: 'string', }, }, + envelope: { + name: 'envelope', + in: 'query', + }, + pretty: { + name: 'pretty', + in: 'query', + }, }, }; @@ -49,6 +57,12 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [ { $ref: '#/components/parameters/PathParam', }, + { + $ref: '#/components/parameters/envelope', + }, + { + $ref: '#/components/parameters/pretty', + }, ], }, }, diff --git a/tools/spectral/ipa/rulesets/functions/createMethodShouldNotHaveQueryParameters.js b/tools/spectral/ipa/rulesets/functions/createMethodShouldNotHaveQueryParameters.js index 5b45886df4..b1a910a553 100644 --- a/tools/spectral/ipa/rulesets/functions/createMethodShouldNotHaveQueryParameters.js +++ b/tools/spectral/ipa/rulesets/functions/createMethodShouldNotHaveQueryParameters.js @@ -5,6 +5,8 @@ import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js'; const RULE_NAME = 'xgen-IPA-106-create-method-should-not-have-query-parameters'; const ERROR_MESSAGE = 'Create operations should not have query parameters.'; +const ignoredParameters = ['envelope', 'pretty']; + export default (input, _, { path }) => { const resourcePath = path[1]; @@ -23,7 +25,7 @@ export default (input, _, { path }) => { } for (const parameter of postMethod.parameters) { - if (parameter.in === 'query') { + if (parameter.in === 'query' && !ignoredParameters.includes(parameter.name)) { return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); } }