persona-community-5/.pnpm-store/v3/files/18/d9b9305fba6a7f80162f018fd19aad4eaaea575d8845c9e5e2ad9737cdb67c92bded90706270bd8ecc82fccdbc2cd2aa878928f3af95e11b7ae19dddc5d2c5
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

38 lines
1.3 KiB
Plaintext

import { isPathParameter, splitCamelCaseIntoWords } from '../../utils';
import type { Oas3Rule, Oas2Rule } from '../../visitors';
import type { Oas2PathItem } from '../../typings/swagger';
import type { Oas3PathItem } from '../../typings/openapi';
import type { UserContext } from '../../walk';
const httpMethods = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace'];
export const NoHttpVerbsInPaths: Oas3Rule | Oas2Rule = ({ splitIntoWords }) => {
return {
PathItem(_path: Oas2PathItem | Oas3PathItem, { key, report, location }: UserContext) {
const pathKey = key.toString();
if (!pathKey.startsWith('/')) return;
const pathSegments = pathKey.split('/');
for (const pathSegment of pathSegments) {
if (!pathSegment || isPathParameter(pathSegment)) continue;
const isHttpMethodIncluded = (method: string) => {
return splitIntoWords
? splitCamelCaseIntoWords(pathSegment).has(method)
: pathSegment.toLocaleLowerCase().includes(method);
};
for (const method of httpMethods) {
if (isHttpMethodIncluded(method)) {
report({
message: `path \`${pathKey}\` should not contain http verb ${method}`,
location: location.key(),
});
}
}
}
},
};
};