UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

31 lines 1.4 kB
import { isPathParameter } from '../../utils/is-path-parameter.js'; import { splitCamelCaseIntoWords } from '../../utils/split-camel-case-into-words.js'; const httpMethods = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace']; export const NoHttpVerbsInPaths = ({ splitIntoWords }) => { return { PathItem(_path, { key, report, location }) { 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) => { 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(), }); } } } }, }; }; //# sourceMappingURL=no-http-verbs-in-paths.js.map