1+ import { hasFormData } from "~/core/form-data" ;
12import type { Operation , OperationParameter } from "~/core/openapi" ;
23import { resolveSchema } from "~/core/resolvers/schema-definition" ;
34import getContentSchema from "./content" ;
@@ -12,6 +13,11 @@ function resolveRequestBody(body: Exclude<Operation["requestBody"], undefined>,
1213 return `requestBody${ body . required ? "" : "?" } : ${ resolveSchema ( getContentSchema ( body . content ) ) } ` ;
1314}
1415
16+ function resolveFormData ( body : Exclude < Operation [ "requestBody" ] , undefined > , typescript : boolean ) {
17+ if ( ! typescript ) return "formBody" ;
18+ return `formBody${ body . required ? "" : "?" } : ${ resolveSchema ( getContentSchema ( body . content ) ) } ` ;
19+ }
20+
1521function sortRequiredParamsFirst ( paramA : OperationParameter , paramB : OperationParameter ) {
1622 if ( paramA . required === paramB . required ) return 0 ;
1723 return paramA . required ? - 1 : 1 ;
@@ -25,6 +31,13 @@ export function resolveOperationParams(operation: Operation, typescript: boolean
2531 const collection = [
2632 ...resolvedParams ,
2733 ] ;
28- if ( operation . requestBody ) collection . push ( resolveRequestBody ( operation . requestBody , typescript ) ) ;
34+ if ( operation . requestBody ) {
35+ operation . requestBody . content ;
36+ if ( hasFormData ( operation ) ) {
37+ collection . push ( resolveFormData ( operation . requestBody , typescript ) ) ;
38+ } else {
39+ collection . push ( resolveRequestBody ( operation . requestBody , typescript ) ) ;
40+ }
41+ }
2942 return collection ;
3043}
0 commit comments