persona-community-5/.pnpm-store/v3/files/d9/10258e856f161330ce51d997ab7af018d657877c1369718dcdbb54c202340056bdc242582a108b606e9ed99101866721a934d0369f819b789a588a65c7b12f
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

34 lines
1.1 KiB
Plaintext

import * as pluralize from 'pluralize';
import { isPathParameter } from '../../utils';
import type { Oas3Rule, Oas2Rule } from '../../visitors';
import type { UserContext } from '../../walk';
export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
const { ignoreLastPathSegment, exceptions } = opts;
return {
PathItem: {
leave(_path: any, { report, key, location }: UserContext) {
const pathKey = key.toString();
if (pathKey.startsWith('/')) {
const pathSegments = pathKey.split('/');
pathSegments.shift();
if (ignoreLastPathSegment && pathSegments.length > 1) {
pathSegments.pop();
}
for (const pathSegment of pathSegments) {
if (exceptions && exceptions.includes(pathSegment)) continue;
if (!isPathParameter(pathSegment) && pluralize.isSingular(pathSegment)) {
report({
message: `path segment \`${pathSegment}\` should be plural.`,
location: location.key(),
});
}
}
}
},
},
};
};