@@ -31,6 +31,7 @@ export class RouteHandlerBuilder<
3131 // eslint-disable-next-line @typescript-eslint/ban-types
3232 TContext = { } ,
3333 TMetadata extends z . Schema = z . Schema ,
34+ TResponse extends z . Schema = z . Schema ,
3435> {
3536 readonly config : {
3637 paramsSchema : TParams ;
@@ -49,6 +50,7 @@ export class RouteHandlerBuilder<
4950 querySchema : undefined as unknown as TQuery ,
5051 bodySchema : undefined as unknown as TBody ,
5152 metadataSchema : undefined as unknown as TMetadata ,
53+ responseSchema : undefined as unknown as TResponse ,
5254 } ,
5355 middlewares = [ ] ,
5456 handleServerError,
@@ -60,11 +62,13 @@ export class RouteHandlerBuilder<
6062 querySchema : TQuery ;
6163 bodySchema : TBody ;
6264 metadataSchema ?: TMetadata ;
65+ responseSchema ?: TResponse ;
6366 } ;
6467 middlewares ?: Array < MiddlewareFunction < TContext , Record < string , unknown > , z . infer < TMetadata > > > ;
6568 handleServerError ?: HandlerServerErrorFn ;
6669 contextType : TContext ;
6770 metadataValue ?: z . infer < TMetadata > ;
71+ responseSchema ?: TResponse ;
6872 } ) {
6973 this . config = config ;
7074 this . middlewares = middlewares ;
@@ -109,6 +113,18 @@ export class RouteHandlerBuilder<
109113 } ) ;
110114 }
111115
116+ /**
117+ * Define the schema for the response
118+ * @param schema - The schema for the response
119+ * @returns A new instance of the RouteHandlerBuilder
120+ */
121+ response < T extends z . Schema > ( schema : T ) {
122+ return new RouteHandlerBuilder < TParams , TQuery , TBody , TContext , TMetadata , T > ( {
123+ ...this ,
124+ config : { ...this . config , responseSchema : schema } ,
125+ } ) ;
126+ }
127+
112128 /**
113129 * Define the schema for the metadata
114130 * @param schema - The schema for the metadata
0 commit comments