1- import { OperationObject , ParameterObject } from "../types" ;
1+ import { OperationObject , ParameterObject , RequestBody } from "../types" ;
22import { comment , isRef , transformRef } from "../utils" ;
33import { transformParametersArray } from "./parameters" ;
44import { transformResponsesObj } from "./responses" ;
@@ -22,21 +22,31 @@ export function transformOperationObj(
2222 if ( isRef ( operation . requestBody ) ) {
2323 output += ` requestBody: ${ transformRef ( operation . requestBody . $ref ) } ;\n` ;
2424 } else {
25- const { description, content } = operation . requestBody ;
25+ if ( operation . requestBody . description ) output += comment ( operation . requestBody . description ) ;
2626
27- if ( description ) output += comment ( description ) ;
27+ output += ` requestBody: {\n` ; // open requestBody
28+ output += ` ${ transformRequestBodyObj ( operation . requestBody ) } ` ;
29+ output += ` }\n` ; // close requestBody
30+ }
31+ }
2832
29- if ( content && Object . keys ( content ) . length ) {
30- output += ` requestBody: {\n content: {\n` ; // open requestBody
33+ return output ;
34+ }
3135
32- Object . entries ( content ) . forEach ( ( [ k , v ] ) => {
33- output += ` "${ k } ": ${ transformSchemaObj ( v . schema ) } ;\n` ;
34- } ) ;
35- output += ` }\n }\n` ; // close requestBody
36- } else {
37- output += ` requestBody: unknown;\n` ;
38- }
39- }
36+ export function transformRequestBodyObj ( requestBody : RequestBody ) {
37+ let output = "" ;
38+
39+ const { content } = requestBody ;
40+
41+ if ( content && Object . keys ( content ) . length ) {
42+ output += ` content: {\n` ; // open content
43+
44+ Object . entries ( content ) . forEach ( ( [ k , v ] ) => {
45+ output += ` "${ k } ": ${ transformSchemaObj ( v . schema ) } ;\n` ;
46+ } ) ;
47+ output += ` }\n` ; // close content
48+ } else {
49+ output += ` unknown;\n` ;
4050 }
4151
4252 return output ;
0 commit comments