Skip to content

Commit e165924

Browse files
committed
refactor: resolveContent with examples
1 parent cbd5bb9 commit e165924

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/core/content.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { createSchemaRef } from "~/utils/openapi-components";
22
import createMediaType from "./createMediaType";
33
import convertToOpenAPI from "./zod-to-openapi";
4+
import type { ExampleObject } from "@omer-x/openapi-types/example";
45
import type { RequestBodyObject } from "@omer-x/openapi-types/request-body";
5-
import type { ZodType } from "zod";
6+
import type { ZodType, ZodTypeDef } from "zod";
67

7-
export function resolveContent(
8-
source?: ZodType<unknown> | string,
8+
export function resolveContent<I, O>(
9+
source?: ZodType<O, ZodTypeDef, I> | string,
910
isArray: boolean = false,
1011
isFormData: boolean = false,
11-
customExample?: unknown,
12+
customExample?: NoInfer<O>,
13+
customExamples?: Record<string, ExampleObject<NoInfer<O>>>,
1214
) {
1315
if (!source) return undefined;
1416

1517
const schema = typeof source === "string" ? createSchemaRef(source, isArray) : convertToOpenAPI(source, isArray);
1618

1719
return {
18-
[isFormData ? "multipart/form-data" : "application/json"]: createMediaType(schema, customExample),
20+
[isFormData ? "multipart/form-data" : "application/json"]: createMediaType(schema, customExample, customExamples),
1921
} as RequestBodyObject["content"];
2022
}

0 commit comments

Comments
 (0)