diff --git a/packages/ruleset/src/functions/operationid-naming-convention.js b/packages/ruleset/src/functions/operationid-naming-convention.js index e8785e56..faa4ad59 100644 --- a/packages/ruleset/src/functions/operationid-naming-convention.js +++ b/packages/ruleset/src/functions/operationid-naming-convention.js @@ -212,11 +212,15 @@ function operationIdPassedConventionCheck( // and that the rest of the operation id matches // the path according to the naming conventions if (fullNamingCheck) { - const convertedPath = fullPath + const tempPath = fullPath .replace(/^\/+/, '') .split('/') - .filter(part => !part.startsWith('{') && !part.endsWith('}')) - .filter(part => !/^v\d+$/.test(part)); + .filter(part => !part.startsWith('{') && !part.endsWith('}')); + + const versionIndex = tempPath.findIndex(part => /^v\d+$/.test(part)); + + const convertedPath = + versionIndex >= 0 ? tempPath.slice(versionIndex + 1) : tempPath; const isPlural = pluralVerbs.some(verb => verbs.includes(verb)); diff --git a/packages/ruleset/test/rules/operationid-naming-convention.test.js b/packages/ruleset/test/rules/operationid-naming-convention.test.js index 10ab2c9a..e7808680 100644 --- a/packages/ruleset/test/rules/operationid-naming-convention.test.js +++ b/packages/ruleset/test/rules/operationid-naming-convention.test.js @@ -128,7 +128,7 @@ describe(`Spectral rule: ${ruleId}`, () => { it('path has multiple path params, put', async () => { const testDocument = makeCopy(rootDocument); - testDocument.paths['/v1/drinks/{drink_id}/glasses/{glass_id}'] = { + testDocument.paths['metadata/v1/drinks/{drink_id}/glasses/{glass_id}'] = { put: { operationId: 'add_drink_glass', }, @@ -468,11 +468,12 @@ describe(`Spectral rule: ${ruleId}`, () => { it('path has multiple path params, delete, not strict', async () => { const testDocument = makeCopy(rootDocument); - testDocument.paths['/v1/drinks/{drink_id}/glasses/{glass_id}'] = { - delete: { - operationId: 'smash_drink_glass', - }, - }; + testDocument.paths['/metadata/v1/drinks/{drink_id}/glasses/{glass_id}'] = + { + delete: { + operationId: 'smash_drink_glass', + }, + }; rule.then.functionOptions.strict = false; @@ -484,7 +485,7 @@ describe(`Spectral rule: ${ruleId}`, () => { expect(r.message).toMatch(/^.*delete or remove*/); expect(r.severity).toBe(expectedSeverity); expect(r.path.join('.')).toBe( - 'paths./v1/drinks/{drink_id}/glasses/{glass_id}.delete.operationId' + 'paths./metadata/v1/drinks/{drink_id}/glasses/{glass_id}.delete.operationId' ); }); });