@piggly/fastify-chassis
Version:
An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.
25 lines (24 loc) • 1.46 kB
text/typescript
import { z } from 'zod';
import type { HookHandlerDoneFunction, FastifyRequest, FastifyReply } from 'fastify';
/**
* SchemaValidationMiddleware is a middleware that validates the request
* body, headers, params and querystring against the provided Zod schemas.
*
* It will replace the request body, headers, params and querystring with
* the validated data.
*
* @param {Object} schemas - The schemas to validate the request against.
* @param {z.ZodType} schemas.body - The schema to validate the request body against.
* @param {z.ZodType} schemas.headers - The schema to validate the request headers against.
* @param {z.ZodType} schemas.params - The schema to validate the request params against.
* @param {z.ZodType} schemas.querystring - The schema to validate the request querystring against.
* @returns The middleware function.
* @since 1.0.0
* @author Caique Araujo <caique@piggly.com.br>
*/
export declare const SchemaValidationMiddleware: (schemas: {
body?: z.ZodType<any>;
headers?: z.ZodType<any>;
params?: z.ZodType<any>;
querystring?: z.ZodType<any>;
}) => (request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply<any, import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown> | undefined;