UNPKG

@tsed/schema

Version:
22 lines (21 loc) 602 B
import { matchGroups } from "../../utils/matchGroups.js"; import { JsonEntityFn } from "./jsonEntityFn.js"; /** * Apply groups validation strategy for required property. * * @decorator * @validation * @swagger * @schema * @input */ export function RequiredGroups(...groups) { return JsonEntityFn((entity) => { entity.parent.schema.$hooks.on("requiredGroups", (required, givenGroups) => { if (matchGroups(groups, givenGroups)) { return required.filter((key) => key !== entity.propertyKey); } return required; }); }); }