1- import { OperationObject , ParameterObject } from "../types" ;
2- import { comment } from "../utils" ;
1+ import { OperationObject , ParameterObject , ReferenceObject } from "../types" ;
2+ import { comment , transformRef } from "../utils" ;
33import { transformParametersArray } from "./parameters" ;
44import { transformResponsesObj } from "./responses" ;
55import { transformSchemaObj } from "./schema" ;
@@ -18,20 +18,31 @@ export function transformOperationObj(
1818 output += ` responses: {\n ${ transformResponsesObj ( operation . responses ) } \n }\n` ;
1919 }
2020
21- if ( operation . requestBody && operation . requestBody . content ) {
22- if ( operation . requestBody . description ) output += comment ( operation . requestBody . description ) ;
21+ if ( operation . requestBody ) {
22+ if ( isRef ( operation . requestBody ) ) {
23+ output += ` requestBody: ${ transformRef ( operation . requestBody . $ref ) } ;\n` ;
24+ } else {
25+ const { description, content} = operation . requestBody
2326
24- if ( Object . keys ( operation . requestBody . content ) . length ) {
25- output += ` requestBody: {\n content: {\n` ; // open requestBody
27+ if ( description ) output += comment ( description ) ;
28+
29+ if ( content && Object . keys ( content ) . length ) {
30+ output += ` requestBody: {\n content: {\n` ; // open requestBody
31+
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+ }
2639
27- Object . entries ( operation . requestBody . content ) . forEach ( ( [ k , v ] ) => {
28- output += ` "${ k } ": ${ transformSchemaObj ( v . schema ) } ;\n` ;
29- } ) ;
30- output += ` }\n }\n` ; // close requestBody
31- } else {
32- output += ` requestBody: unknown;\n` ;
3340 }
3441 }
3542
3643 return output ;
3744}
45+
46+ export function isRef ( obj : any ) : obj is ReferenceObject {
47+ return ! ! obj . $ref
48+ }
0 commit comments