function createValidationMiddleware
createValidationMiddleware(
schema: unknown,
target: ValidationTarget,
service: IValidationService,
): MiddlewareFunction

Create a validation middleware function.

The middleware extracts data from the specified request target, validates it via the provided validation service, and either stores the validated value in ctx.state and continues the pipeline, or short-circuits with a 400 response containing the formatted validation errors.

Parameters

schema: unknown

The schema (must expose safeParse)

target: ValidationTarget

Which request part to validate ('body', 'query', etc.)

service: IValidationService

The validation service to use

Error formatter (resolved once at registration time)

Return Type

MiddlewareFunction

A middleware function

Usage

import { createValidationMiddleware } from "validation-plugin/src/index.ts";