@@ -465,6 +465,54 @@ describe('Authorization - OpenAPI Specification 3.0', () => {
465465 } ) ;
466466 } ) ;
467467 test ( 'should add apiKey credentials as a cookie' , ( ) => {
468+ const spec = {
469+ openapi : '3.0.0' ,
470+ components : {
471+ securitySchemes : {
472+ myApiKey : {
473+ type : 'apiKey' ,
474+ name : 'MyApiKeyCookie' ,
475+ in : 'cookie' ,
476+ } ,
477+ } ,
478+ } ,
479+ paths : {
480+ '/' : {
481+ get : {
482+ operationId : 'myOperation' ,
483+ security : [
484+ {
485+ myApiKey : [ ] ,
486+ } ,
487+ ] ,
488+ } ,
489+ } ,
490+ } ,
491+ } ;
492+
493+ // when
494+ const req = buildRequest ( {
495+ spec,
496+ operationId : 'myOperation' ,
497+ securities : {
498+ authorized : {
499+ myApiKey : {
500+ value : 'MyToken' ,
501+ } ,
502+ } ,
503+ } ,
504+ } ) ;
505+
506+ expect ( req ) . toEqual ( {
507+ method : 'GET' ,
508+ url : '/' ,
509+ credentials : 'same-origin' ,
510+ headers : {
511+ Cookie : 'MyApiKeyCookie=MyToken' ,
512+ } ,
513+ } ) ;
514+ } ) ;
515+ test ( 'should add multiple apiKey credentials as a cookie' , ( ) => {
468516 const spec = {
469517 openapi : '3.0.0' ,
470518 components : {
@@ -521,6 +569,68 @@ describe('Authorization - OpenAPI Specification 3.0', () => {
521569 } ,
522570 } ) ;
523571 } ) ;
572+ test ( 'should append apiKey credentials to a cookie' , ( ) => {
573+ const spec = {
574+ openapi : '3.0.0' ,
575+ components : {
576+ securitySchemes : {
577+ myApiKey : {
578+ type : 'apiKey' ,
579+ name : 'MyApiKeyCookie' ,
580+ in : 'cookie' ,
581+ } ,
582+ } ,
583+ } ,
584+ paths : {
585+ '/' : {
586+ get : {
587+ operationId : 'myOperation' ,
588+ parameters : [
589+ {
590+ name : 'id' ,
591+ in : 'cookie' ,
592+ style : 'form' ,
593+ explode : true ,
594+ } ,
595+ ] ,
596+ security : [
597+ {
598+ myApiKey : [ ] ,
599+ } ,
600+ ] ,
601+ } ,
602+ } ,
603+ } ,
604+ } ;
605+
606+ // when
607+ const req = buildRequest ( {
608+ spec,
609+ operationId : 'myOperation' ,
610+ parameters : {
611+ id : [ 1 , 2 , 3 ] ,
612+ } ,
613+ securities : {
614+ authorized : {
615+ myApiKey : {
616+ value : 'MyToken' ,
617+ } ,
618+ myApiKey1 : {
619+ value : 'MyToken1' ,
620+ } ,
621+ } ,
622+ } ,
623+ } ) ;
624+
625+ expect ( req ) . toEqual ( {
626+ method : 'GET' ,
627+ url : '/' ,
628+ credentials : 'same-origin' ,
629+ headers : {
630+ Cookie : 'id=1&id=2&id=3; MyApiKeyCookie=MyToken' ,
631+ } ,
632+ } ) ;
633+ } ) ;
524634 test ( 'should not add credentials if operation does not call for security' , ( ) => {
525635 const spec = {
526636 openapi : '3.0.0' ,
0 commit comments