@@ -14,7 +14,8 @@ import {
1414 type BaseContentType ,
1515 type ZodFormSchema ,
1616 type FormDataContentType ,
17- type ContentTypesThatSupportInputValidation
17+ type ContentTypesThatSupportInputValidation ,
18+ type BaseHeaders
1819} from '../types' ;
1920import { NextResponse , type NextRequest } from 'next/server' ;
2021import { type ZodSchema , type z } from 'zod' ;
@@ -168,6 +169,7 @@ type TypedRouteHandler<
168169 Body = unknown ,
169170 Query extends BaseQuery = BaseQuery ,
170171 Params extends BaseParams = BaseParams ,
172+ Headers extends BaseHeaders = BaseHeaders ,
171173 Options extends BaseOptions = BaseOptions ,
172174 ResponseBody = unknown ,
173175 Status extends BaseStatus = BaseStatus ,
@@ -185,15 +187,16 @@ type TypedRouteHandler<
185187 | void
186188> = (
187189 req : TypedNextRequest < Method , ContentType , Body , Query > ,
188- context : { params : Params } ,
190+ context : { params : Params ; headers : Headers } ,
189191 options : Options
190192) => Promise < TypedResponse > | TypedResponse ;
191193
192194interface InputObject <
193195 ContentType = BaseContentType ,
194196 Body = unknown ,
195197 Query = BaseQuery ,
196- Params = BaseParams
198+ Params = BaseParams ,
199+ Headers = BaseHeaders
197200> {
198201 contentType ?: ContentType ;
199202 /*! Body schema is supported only for certain content types that support input validation. */
@@ -210,6 +213,7 @@ interface InputObject<
210213 params ?: ZodSchema < Params > ;
211214 /*! If defined, this will override the params schema for the OpenAPI spec. */
212215 paramsSchema ?: OpenAPIV3_1 . SchemaObject | OpenAPIV3_1 . ReferenceObject ;
216+ headers ?: ZodSchema < Headers > ;
213217}
214218
215219export interface RouteOperationDefinition <
@@ -246,7 +250,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
246250 middleware1 ?: RouteMiddleware < any , any > ;
247251 middleware2 ?: RouteMiddleware < any , any > ;
248252 middleware3 ?: RouteMiddleware < any , any > ;
249- handler ?: TypedRouteHandler < any , any , any , any , any , any > ;
253+ handler ?: TypedRouteHandler < any , any , any , any , any , any , any > ;
250254 } ) : RouteOperationDefinition < Method > => ( {
251255 openApiOperation,
252256 method,
@@ -263,9 +267,10 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
263267 ContentType extends BaseContentType ,
264268 Body ,
265269 Query extends BaseQuery ,
266- Params extends BaseParams
270+ Params extends BaseParams ,
271+ Headers extends BaseHeaders
267272 > (
268- input : InputObject < ContentType , Body , Query , Params >
273+ input : InputObject < ContentType , Body , Query , Params , Headers >
269274 ) => ( {
270275 outputs : <
271276 ResponseBody ,
@@ -314,6 +319,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
314319 Body ,
315320 Query ,
316321 Params ,
322+ Headers ,
317323 Options3 ,
318324 ResponseBody ,
319325 Status ,
@@ -337,6 +343,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
337343 Body ,
338344 Query ,
339345 Params ,
346+ Headers ,
340347 Options2 ,
341348 ResponseBody ,
342349 Status ,
@@ -359,6 +366,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
359366 Body ,
360367 Query ,
361368 Params ,
369+ Headers ,
362370 Options1 ,
363371 ResponseBody ,
364372 Status ,
@@ -374,6 +382,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
374382 Body ,
375383 Query ,
376384 Params ,
385+ Headers ,
377386 BaseOptions ,
378387 ResponseBody ,
379388 Status ,
@@ -408,6 +417,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
408417 Body ,
409418 Query ,
410419 Params ,
420+ Headers ,
411421 Options3 ,
412422 ResponseBody ,
413423 Status ,
@@ -431,6 +441,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
431441 Body ,
432442 Query ,
433443 Params ,
444+ Headers ,
434445 Options2
435446 >
436447 ) => createOperation ( { input, middleware1, middleware2, handler } )
@@ -452,6 +463,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
452463 Body ,
453464 Query ,
454465 Params ,
466+ Headers ,
455467 Options2 ,
456468 ResponseBody ,
457469 Status ,
@@ -473,6 +485,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
473485 ContentType ,
474486 Body ,
475487 Query ,
488+ Headers ,
476489 Params ,
477490 Options2
478491 >
@@ -495,6 +508,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
495508 Body ,
496509 Query ,
497510 Params ,
511+ Headers ,
498512 Options1 ,
499513 ResponseBody ,
500514 Status ,
@@ -510,6 +524,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
510524 Body ,
511525 Query ,
512526 Params ,
527+ Headers ,
513528 Options1
514529 >
515530 ) => createOperation ( { input, middleware1, handler } )
@@ -565,6 +580,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
565580 unknown ,
566581 BaseQuery ,
567582 BaseParams ,
583+ BaseHeaders ,
568584 Options3 ,
569585 ResponseBody ,
570586 Status ,
@@ -587,6 +603,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
587603 unknown ,
588604 BaseQuery ,
589605 BaseParams ,
606+ BaseHeaders ,
590607 Options2 ,
591608 ResponseBody ,
592609 Status ,
@@ -602,6 +619,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
602619 unknown ,
603620 BaseQuery ,
604621 BaseParams ,
622+ BaseHeaders ,
605623 Options1 ,
606624 ResponseBody ,
607625 Status ,
@@ -617,6 +635,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
617635 unknown ,
618636 BaseQuery ,
619637 BaseParams ,
638+ BaseHeaders ,
620639 BaseOptions ,
621640 ResponseBody ,
622641 Status ,
@@ -641,6 +660,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
641660 unknown ,
642661 BaseQuery ,
643662 BaseParams ,
663+ BaseHeaders ,
644664 Options3
645665 >
646666 ) =>
@@ -653,6 +673,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
653673 unknown ,
654674 BaseQuery ,
655675 BaseParams ,
676+ BaseHeaders ,
656677 Options2
657678 >
658679 ) => createOperation ( { middleware1, middleware2, handler } )
@@ -664,6 +685,7 @@ export const routeOperation = <Method extends keyof typeof ValidMethod>({
664685 unknown ,
665686 BaseQuery ,
666687 BaseParams ,
688+ BaseHeaders ,
667689 Options1
668690 >
669691 ) => createOperation ( { middleware1, handler } )
0 commit comments