persona-community-5/.pnpm-store/v3/files/9b/e512fb214eb5c08226fcccabf5760a7713fd5cbb7240f87d9e4d0a8c49f96b2784ef8693797fdaa89847e311cadcf1c1bf2a28d902e87c89740f85a0616686
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

66 lines
2.4 KiB
Plaintext

import type { Oas3Rule, Oas2Rule } from '../../visitors';
import type { Oas2Parameter } from '../../typings/swagger';
import type { Oas3Parameter } from '../../typings/openapi';
import type { UserContext } from '../../walk';
const pathRegex = /\{([a-zA-Z0-9_.-]+)\}+/g;
export const PathParamsDefined: Oas3Rule | Oas2Rule = () => {
let pathTemplateParams: Set<string>;
let definedPathParams: Set<string>;
let currentPath: string;
let definedOperationParams: Set<string>;
return {
PathItem: {
enter(_: object, { key }: UserContext) {
definedPathParams = new Set();
currentPath = key as string;
pathTemplateParams = new Set(
Array.from(key!.toString().matchAll(pathRegex)).map((m) => m[1])
);
},
Parameter(parameter: Oas2Parameter | Oas3Parameter, { report, location }: UserContext) {
if (parameter.in === 'path' && parameter.name) {
definedPathParams.add(parameter.name);
if (!pathTemplateParams.has(parameter.name)) {
report({
message: `Path parameter \`${parameter.name}\` is not used in the path \`${currentPath}\`.`,
location: location.child(['name']),
});
}
}
},
Operation: {
enter() {
definedOperationParams = new Set();
},
leave(_op: object, { report, location }: UserContext) {
for (const templateParam of Array.from(pathTemplateParams.keys())) {
if (
!definedOperationParams.has(templateParam) &&
!definedPathParams.has(templateParam)
) {
report({
message: `The operation does not define the path parameter \`{${templateParam}}\` expected by path \`${currentPath}\`.`,
location: location.child(['parameters']).key(), // report on operation
});
}
}
},
Parameter(parameter: Oas2Parameter | Oas3Parameter, { report, location }: UserContext) {
if (parameter.in === 'path' && parameter.name) {
definedOperationParams.add(parameter.name);
if (!pathTemplateParams.has(parameter.name)) {
report({
message: `Path parameter \`${parameter.name}\` is not used in the path \`${currentPath}\`.`,
location: location.child(['name']),
});
}
}
},
},
},
};
};