File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 11import { createSchemaRef } from "~/utils/openapi-components" ;
2+ import createMediaType from "./createMediaType" ;
23import convertToOpenAPI from "./zod-to-openapi" ;
34import type { RequestBodyObject } from "@omer-x/openapi-types/request-body" ;
45import type { ZodType } from "zod" ;
56
6- export function resolveContent ( source ?: ZodType < unknown > | string , isArray : boolean = false , isFormData : boolean = false ) {
7+ export function resolveContent (
8+ source ?: ZodType < unknown > | string ,
9+ isArray : boolean = false ,
10+ isFormData : boolean = false ,
11+ customExample ?: unknown ,
12+ ) {
713 if ( ! source ) return undefined ;
814
915 const schema = typeof source === "string" ? createSchemaRef ( source , isArray ) : convertToOpenAPI ( source , isArray ) ;
1016
1117 return {
12- [ isFormData ? "multipart/form-data" : "application/json" ] : {
13- schema,
14- } ,
18+ [ isFormData ? "multipart/form-data" : "application/json" ] : createMediaType ( schema , customExample ) ,
1519 } as RequestBodyObject [ "content" ] ;
1620}
Original file line number Diff line number Diff line change 1+ import type { Entry } from "~/types/entry" ;
2+ import type { MediaTypeObject } from "@omer-x/openapi-types/media-type" ;
3+ import type { SchemaObject } from "@omer-x/openapi-types/schema" ;
4+
5+ export default function createMediaType ( schema : SchemaObject , example ?: MediaTypeObject [ "example" ] ) {
6+ const mediaTypeEntries = [ ] as Entry < MediaTypeObject > [ ] ;
7+ mediaTypeEntries . push ( [ "schema" , schema ] ) ;
8+ if ( example ) {
9+ mediaTypeEntries . push ( [ "example" , example ] ) ;
10+ }
11+ return Object . fromEntries ( mediaTypeEntries ) as MediaTypeObject ;
12+ }
Original file line number Diff line number Diff line change 1+ export type Entry < T > = [ keyof T , T [ keyof T ] ] ;
You can’t perform that action at this time.
0 commit comments