UNPKG

tsoa-zod-validator

Version:
57 lines (56 loc) 1.47 kB
import type { Request } from 'express'; import type { z } from 'zod'; import type { FileValidationOptions } from './FileValidationOptions'; /** * Error format options for validation errors */ export type ErrorFormat = 'simple' | 'detailed' | 'custom'; /** * Custom error handler function type */ export type CustomErrorHandler = (error: any, req: Request) => any; /** * Options for ZodValidate decorator */ export interface ZodValidationOptions { /** * The error format to use for validation errors * @default 'simple' */ errorFormat?: ErrorFormat; /** * Custom error handler function */ customErrorHandler?: CustomErrorHandler; /** * Function to determine if validation should be skipped * @param req The Express request object * @returns True if validation should be skipped, false otherwise */ skipValidation?: (req: Request) => boolean; } /** * Validation targets for ZodValidate decorator */ export interface ZodValidationTargets { /** * Zod schema for validating the request body */ body?: z.ZodTypeAny; /** * Zod schema for validating query parameters */ query?: z.ZodTypeAny; /** * Zod schema for validating route parameters */ params?: z.ZodTypeAny; /** * Zod schema for validating request headers */ headers?: z.ZodTypeAny; /** * File validation options */ files?: FileValidationOptions; }