|
1 | 1 | import { createSchemaRef } from "~/utils/openapi-components"; |
2 | 2 | import createMediaType from "./createMediaType"; |
3 | 3 | import convertToOpenAPI from "./zod-to-openapi"; |
| 4 | +import type { ExampleObject } from "@omer-x/openapi-types/example"; |
4 | 5 | import type { RequestBodyObject } from "@omer-x/openapi-types/request-body"; |
5 | | -import type { ZodType } from "zod"; |
| 6 | +import type { ZodType, ZodTypeDef } from "zod"; |
6 | 7 |
|
7 | | -export function resolveContent( |
8 | | - source?: ZodType<unknown> | string, |
| 8 | +export function resolveContent<I, O>( |
| 9 | + source?: ZodType<O, ZodTypeDef, I> | string, |
9 | 10 | isArray: boolean = false, |
10 | 11 | isFormData: boolean = false, |
11 | | - customExample?: unknown, |
| 12 | + customExample?: NoInfer<O>, |
| 13 | + customExamples?: Record<string, ExampleObject<NoInfer<O>>>, |
12 | 14 | ) { |
13 | 15 | if (!source) return undefined; |
14 | 16 |
|
15 | 17 | const schema = typeof source === "string" ? createSchemaRef(source, isArray) : convertToOpenAPI(source, isArray); |
16 | 18 |
|
17 | 19 | return { |
18 | | - [isFormData ? "multipart/form-data" : "application/json"]: createMediaType(schema, customExample), |
| 20 | + [isFormData ? "multipart/form-data" : "application/json"]: createMediaType(schema, customExample, customExamples), |
19 | 21 | } as RequestBodyObject["content"]; |
20 | 22 | } |
0 commit comments