Skip to content

Commit ab71bad

Browse files
committed
feat: requestBodyExample
1 parent ae902bc commit ab71bad

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/core/body.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { safeParse } from "./zod-error-handler";
55
import type { RequestBodyObject } from "@omer-x/openapi-types/request-body";
66
import type { ZodError, ZodType, ZodTypeDef } from "zod";
77

8-
export function resolveRequestBody<I, O>(source?: ZodType<O, ZodTypeDef, I> | string, isFormData: boolean = false) {
8+
export function resolveRequestBody<I, O>(
9+
source?: ZodType<O, ZodTypeDef, I> | string,
10+
isFormData: boolean = false,
11+
customExample?: O,
12+
) {
913
if (!source) return undefined;
1014
return {
1115
// description: "", // how to fill this?
1216
required: true,
13-
content: resolveContent(source, false, isFormData),
17+
content: resolveContent(source, false, isFormData, customExample),
1418
} as RequestBodyObject;
1519
}
1620

src/core/definer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ type ActionSource<PathParams, QueryParams, RequestBody> = {
1919
type RouteWithoutBody = {
2020
method: Extract<HttpMethod, "GET" | "DELETE" | "HEAD">,
2121
requestBody?: null,
22+
requestBodyExample?: undefined,
2223
hasFormData?: boolean,
2324
};
2425

2526
type RouteWithBody<I, O> = {
2627
method: Exclude<HttpMethod, "GET" | "DELETE" | "HEAD">,
2728
requestBody?: ZodType<O, ZodTypeDef, I> | string,
29+
requestBodyExample?: NoInfer<O>,
2830
hasFormData?: boolean,
2931
};
3032

@@ -125,7 +127,7 @@ function defineRoute<
125127
description: input.description,
126128
tags: input.tags,
127129
parameters: parameters.length ? parameters : undefined,
128-
requestBody: resolveRequestBody(input.requestBody ?? undefined, input.hasFormData),
130+
requestBody: resolveRequestBody(input.requestBody ?? undefined, input.hasFormData, input.requestBodyExample),
129131
responses: responses,
130132
security: input.security,
131133
};

0 commit comments

Comments
 (0)