Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/ruleset/src/functions/operationid-naming-convention.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +222 to +223

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diatrcz Quick question: what happens if the major version is a double digit, like v12? :) Probably nothing bad and I know this would probably never be the case, but we should try to make the code be prepared for such a scenario. Could you look into this?

@pyrooka pyrooka Oct 22, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the changes are looking good, this is my only - somewhat theoretical - question.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern /^v\d+$/ matches to double, triple, quadruple, etc. digit versions as well 😄 so the logic stays the same. But I did test it locally as well, just to make sure!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I could change it to /^v\d*+$/, just to be safe.


const isPlural = pluralVerbs.some(verb => verbs.includes(verb));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down Expand Up @@ -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;

Expand All @@ -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'
);
});
});
Expand Down