File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,45 @@ describe('#getContentType', () => {
6666 } ) . getContentType ( )
6767 ) . toBe ( 'text/xml' ) ;
6868 } ) ;
69+
70+ it ( 'should handle cases where the requestBody is a $ref' , ( ) => {
71+ const op = new Operation (
72+ {
73+ ...petstore ,
74+ ...{
75+ components : {
76+ requestBodies : {
77+ payload : {
78+ required : true ,
79+ content : {
80+ 'multipart/form-data' : {
81+ schema : {
82+ type : 'object' ,
83+ properties : {
84+ 'Document file' : {
85+ type : 'string' ,
86+ format : 'binary' ,
87+ } ,
88+ } ,
89+ } ,
90+ } ,
91+ } ,
92+ } ,
93+ } ,
94+ } ,
95+ } ,
96+ } ,
97+ '/body' ,
98+ 'post' ,
99+ {
100+ requestBody : {
101+ $ref : '#/components/requestBodies/payload' ,
102+ } ,
103+ }
104+ ) ;
105+
106+ expect ( op . getContentType ( ) ) . toBe ( 'multipart/form-data' ) ;
107+ } ) ;
69108} ) ;
70109
71110describe ( '#getSecurity()' , ( ) => {
Original file line number Diff line number Diff line change @@ -10,7 +10,16 @@ class Operation {
1010 }
1111
1212 getContentType ( ) {
13- const types = ( this . requestBody && this . requestBody . content && Object . keys ( this . requestBody . content ) ) || [ ] ;
13+ let types = [ ] ;
14+ if ( this . requestBody ) {
15+ if ( '$ref' in this . requestBody ) {
16+ this . requestBody = findSchemaDefinition ( this . requestBody . $ref , this . oas ) ;
17+ }
18+
19+ if ( 'content' in this . requestBody ) {
20+ types = Object . keys ( this . requestBody . content ) ;
21+ }
22+ }
1423
1524 let type = 'application/json' ;
1625 if ( types && types . length ) {
You can’t perform that action at this time.
0 commit comments