@@ -441,7 +441,7 @@ describe('execute', () => {
441441 } )
442442 } )
443443
444- it ( 'should handle requestContentType ' , function ( ) {
444+ it ( 'should not add content-type with no form-data or body param ' , function ( ) {
445445 // Given
446446 const spec = {
447447 host : 'swagger.io' ,
@@ -454,14 +454,143 @@ describe('execute', () => {
454454 // Then
455455 expect ( req ) . toEqual ( {
456456 url : 'http://swagger.io/one' ,
457- headers : {
458- 'content-type' : 'application/josh' ,
459- } ,
457+ headers : { } ,
460458 credentials : 'same-origin' ,
461459 method : 'GET'
462460 } )
463461 } )
464462
463+ it ( 'should add content-type multipart/form-data when param type is file and no other sources of consumes' , function ( ) {
464+ // Given
465+ const spec = {
466+ host : 'swagger.io' ,
467+ paths : {
468+ '/one' : {
469+ post : {
470+ operationId : 'postMe' ,
471+ parameters : [ { name : 'file' , type : 'file' , 'in' : "formData" } ]
472+ }
473+ }
474+ }
475+ }
476+
477+ // When
478+ const req = buildRequest ( {
479+ spec,
480+ operationId : 'postMe' ,
481+ parameters : { file : 'test' } } )
482+
483+ // Then
484+ expect ( req ) . toEqual ( {
485+ method : "POST" ,
486+ "body" : "file=test" ,
487+ url : 'http://swagger.io/one' ,
488+ headers : {
489+ "content-type" : "multipart/form-data"
490+ } ,
491+ credentials : 'same-origin'
492+ } )
493+ } )
494+
495+ it ( 'should add content-type application/x-www-form-urlencoded when in: formData ' , function ( ) {
496+ // Given
497+ const spec = {
498+ host : 'swagger.io' ,
499+ paths : {
500+ '/one' : {
501+ post : {
502+ operationId : 'postMe' ,
503+ parameters : [ { name : 'file' , in : 'formData' } ]
504+ }
505+ }
506+ }
507+ }
508+
509+ // When
510+ const req = buildRequest ( {
511+ spec,
512+ operationId : 'postMe' ,
513+ parameters : { file : 'test' } } )
514+
515+ // Then
516+ expect ( req ) . toEqual ( {
517+ body : "file=test" ,
518+ method : "POST" ,
519+ url : 'http://swagger.io/one' ,
520+ headers : {
521+ "content-type" : "application/x-www-form-urlencoded"
522+ } ,
523+ credentials : 'same-origin'
524+ } )
525+ } )
526+
527+ it ( 'should add content-type from spec when no consumes in operation and no requestContentType passed' , function ( ) {
528+ // Given
529+ const spec = {
530+ host : 'swagger.io' ,
531+ consumes : [ "test" ] ,
532+ paths : {
533+ '/one' : {
534+ post : {
535+ operationId : 'postMe' ,
536+ parameters : [ { name : 'file' , in : 'formData' } ]
537+ }
538+ }
539+ }
540+ }
541+
542+ // When
543+ const req = buildRequest ( {
544+ spec,
545+ operationId : 'postMe' ,
546+ parameters : { file : 'test' } } )
547+
548+ // Then
549+ expect ( req ) . toEqual ( {
550+ body : "file=test" ,
551+ method : "POST" ,
552+ url : 'http://swagger.io/one' ,
553+ headers : {
554+ "content-type" : "test"
555+ } ,
556+ credentials : 'same-origin'
557+ } )
558+ } )
559+
560+ it ( 'should add content-type from operation when no requestContentType passed' , function ( ) {
561+ // Given
562+ const spec = {
563+ host : 'swagger.io' ,
564+ consumes : [ "no" ] ,
565+ paths : {
566+ '/one' : {
567+ post : {
568+ operationId : 'postMe' ,
569+ consumes : [ "test" ] ,
570+ parameters : [ { name : 'file' , in : 'formData' } ]
571+ }
572+ }
573+ }
574+ }
575+
576+ // When
577+ const req = buildRequest ( {
578+ spec,
579+ operationId : 'postMe' ,
580+ parameters : { file : 'test' } } )
581+
582+ // Then
583+ expect ( req ) . toEqual ( {
584+ body : "file=test" ,
585+ method : "POST" ,
586+ url : 'http://swagger.io/one' ,
587+ headers : {
588+ "content-type" : "test"
589+ } ,
590+ credentials : 'same-origin'
591+ } )
592+ } )
593+
465594 it ( 'should build a request for all given fields' , function ( ) {
466595 // Given
467596 const spec = {
0 commit comments