persona-community-5/.pnpm-store/v3/files/80/3f4b721786ae4792e034d30d4f74dcd9e90539b2636db29b0442954130ab285f6cc6f9bf8c19c893f728f947db5f40da5c11539836f2b4eb3800ecbe0af7ae
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

29 lines
994 B
Plaintext

import type { Oas3Rule } from '../../visitors';
export type BooleanParameterPrefixesOptions = {
prefixes?: string[];
};
export const BooleanParameterPrefixes: Oas3Rule = (options: BooleanParameterPrefixesOptions) => {
const prefixes = options.prefixes || ['is', 'has'];
const regexp = new RegExp(`^(${prefixes.join('|')})[A-Z-_]`);
const wrappedPrefixes = prefixes.map((p) => `\`${p}\``);
const prefixesString =
wrappedPrefixes.length === 1
? wrappedPrefixes[0]
: wrappedPrefixes.slice(0, -1).join(', ') + ' or ' + wrappedPrefixes[prefixes.length - 1];
return {
Parameter: {
Schema(schema, { report, parentLocations }, parents) {
if (schema.type === 'boolean' && !regexp.test(parents.Parameter.name)) {
report({
message: `Boolean parameter \`${parents.Parameter.name}\` should have ${prefixesString} prefix.`,
location: parentLocations.Parameter.child(['name']),
});
}
},
},
};
};