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

48 lines
1.3 KiB
Plaintext

import { isRef } from '../../ref-utils';
import type { Oas3Rule, Oas3Visitor } from '../../visitors';
import type { Oas3_1Schema, Oas3Parameter } from '../../typings/openapi';
export type ArrayParameterSerializationOptions = {
in?: string[];
};
export const ArrayParameterSerialization: Oas3Rule = (
options: ArrayParameterSerializationOptions
): Oas3Visitor => {
return {
Parameter: {
leave(node, ctx) {
if (!node.schema) {
return;
}
const schema = (
isRef(node.schema) ? ctx.resolve(node.schema).node : node.schema
) as Oas3_1Schema;
if (
schema &&
shouldReportMissingStyleAndExplode(node as Oas3Parameter<Oas3_1Schema>, schema, options)
) {
ctx.report({
message: `Parameter \`${node.name}\` should have \`style\` and \`explode \` fields`,
location: ctx.location,
});
}
},
},
};
};
function shouldReportMissingStyleAndExplode(
node: Oas3Parameter<Oas3_1Schema>,
schema: Oas3_1Schema,
options: ArrayParameterSerializationOptions
) {
return (
(schema.type === 'array' || schema.items || schema.prefixItems) &&
(node.style === undefined || node.explode === undefined) &&
(!options.in || (node.in && options.in?.includes(node.in)))
);
}