@@ -7,6 +7,7 @@ import { resolveParams } from "./params";
77import parsePathParams from "./path-params" ;
88import { addBadRequest , bundleResponses } from "./responses" ;
99import parseSearchParams from "./search-params" ;
10+ import type { ExampleObject } from "@omer-x/openapi-types/example" ;
1011import type { OperationObject } from "@omer-x/openapi-types/operation" ;
1112import type { ZodIssue , ZodType , ZodTypeDef } from "zod" ;
1213
@@ -18,15 +19,17 @@ type ActionSource<PathParams, QueryParams, RequestBody> = {
1819
1920type RouteWithoutBody = {
2021 method : Extract < HttpMethod , "GET" | "DELETE" | "HEAD" > ,
21- requestBody ?: null ,
22+ requestBody ?: undefined ,
2223 requestBodyExample ?: undefined ,
24+ requestBodyExamples ?: undefined ,
2325 hasFormData ?: boolean ,
2426} ;
2527
2628type RouteWithBody < I , O > = {
2729 method : Exclude < HttpMethod , "GET" | "DELETE" | "HEAD" > ,
2830 requestBody ?: ZodType < O , ZodTypeDef , I > | string ,
2931 requestBodyExample ?: NoInfer < O > ,
32+ requestBodyExamples ?: Record < string , ExampleObject < NoInfer < O > > > ,
3033 hasFormData ?: boolean ,
3134} ;
3235
@@ -83,7 +86,7 @@ function defineRoute<
8386 const { searchParams } = new URL ( request . url ) ;
8487 const pathParams = parsePathParams ( context ?. params , input . pathParams ) as PPO ;
8588 const queryParams = parseSearchParams ( searchParams , input . queryParams ) as QPO ;
86- const body = await parseRequestBody ( request , input . method , input . requestBody ?? undefined , input . hasFormData ) as RBO ;
89+ const body = await parseRequestBody ( request , input . method , input . requestBody , input . hasFormData ) as RBO ;
8790 return await input . action ( { pathParams, queryParams, body } , request ) as MwRes ;
8891 } catch ( error ) {
8992 if ( input . handleErrors ) {
@@ -137,7 +140,7 @@ function defineRoute<
137140 description : input . description ,
138141 tags : input . tags ,
139142 parameters : parameters . length ? parameters : undefined ,
140- requestBody : resolveRequestBody ( input . requestBody ?? undefined , input . hasFormData , input . requestBodyExample ) ,
143+ requestBody : resolveRequestBody ( input . requestBody , input . hasFormData , input . requestBodyExample , input . requestBodyExamples ) ,
141144 responses : responses ,
142145 security : input . security ,
143146 } ;
0 commit comments