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 1
1
import { createSchemaRef } from "~/utils/openapi-components" ;
2
+ import createMediaType from "./createMediaType" ;
2
3
import convertToOpenAPI from "./zod-to-openapi" ;
3
4
import type { RequestBodyObject } from "@omer-x/openapi-types/request-body" ;
4
5
import type { ZodType } from "zod" ;
5
6
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
+ ) {
7
13
if ( ! source ) return undefined ;
8
14
9
15
const schema = typeof source === "string" ? createSchemaRef ( source , isArray ) : convertToOpenAPI ( source , isArray ) ;
10
16
11
17
return {
12
- [ isFormData ? "multipart/form-data" : "application/json" ] : {
13
- schema,
14
- } ,
18
+ [ isFormData ? "multipart/form-data" : "application/json" ] : createMediaType ( schema , customExample ) ,
15
19
} as RequestBodyObject [ "content" ] ;
16
20
}
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