File tree Expand file tree Collapse file tree 2 files changed +54
-5
lines changed Expand file tree Collapse file tree 2 files changed +54
-5
lines changed Original file line number Diff line number Diff line change 1
- import cloneDeep from 'lodash/cloneDeep'
2
1
import assign from 'lodash/assign'
3
2
import startsWith from 'lodash/startsWith'
4
3
import Url from 'url'
@@ -54,7 +53,7 @@ Swagger.prototype = {
54
53
55
54
http : Http ,
56
55
57
- execute ( argHash ) {
56
+ execute ( options ) {
58
57
this . applyDefaults ( )
59
58
60
59
return Swagger . execute ( {
@@ -64,18 +63,20 @@ Swagger.prototype = {
64
63
contextUrl : typeof this . url === 'string' ? this . url : undefined ,
65
64
requestInterceptor : this . requestInterceptor || null ,
66
65
responseInterceptor : this . responseInterceptor || null ,
67
- ...argHash
66
+ ...options
68
67
} )
69
68
} ,
70
69
71
- resolve ( ) {
70
+ resolve ( options = { } ) {
72
71
return Swagger . resolve ( {
73
72
spec : this . spec ,
74
73
url : this . url ,
74
+ http : this . http ,
75
75
allowMetaPatches : this . allowMetaPatches ,
76
76
useCircularStructures : this . useCircularStructures ,
77
77
requestInterceptor : this . requestInterceptor || null ,
78
- responseInterceptor : this . responseInterceptor || null
78
+ responseInterceptor : this . responseInterceptor || null ,
79
+ ...options ,
79
80
} ) . then ( ( obj ) => {
80
81
this . originalSpec = this . spec
81
82
this . spec = obj . spec
Original file line number Diff line number Diff line change @@ -588,6 +588,54 @@ describe('constructor', () => {
588
588
} )
589
589
} )
590
590
591
+ describe ( '#resolve' , ( ) => {
592
+ let originalResolveFn
593
+
594
+ beforeEach ( ( ) => {
595
+ originalResolveFn = Swagger . resolve
596
+ Swagger . resolve = jest . fn ( async obj => obj )
597
+ } )
598
+
599
+ afterEach ( ( ) => {
600
+ Swagger . resolve = originalResolveFn
601
+ } )
602
+
603
+ test ( 'should use global http option' , async ( ) => {
604
+ const spec = {
605
+ paths : {
606
+ '/pet' : {
607
+ get : {
608
+ operationId : 'getPets' ,
609
+ }
610
+ }
611
+ }
612
+ }
613
+ const http = jest . fn ( )
614
+ const client = await Swagger ( { spec, http} )
615
+ await client . resolve ( )
616
+
617
+ expect ( Swagger . resolve . mock . calls [ 0 ] [ 0 ] . http ) . toStrictEqual ( http )
618
+ } )
619
+
620
+ test ( 'should support passing additional options' , async ( ) => {
621
+ const spec = {
622
+ paths : {
623
+ '/pet' : {
624
+ get : {
625
+ operationId : 'getPets' ,
626
+ }
627
+ }
628
+ }
629
+ }
630
+ const http = jest . fn ( )
631
+ const requestInterceptor = jest . fn ( )
632
+ const client = await Swagger ( { spec, http} )
633
+ await client . resolve ( { requestInterceptor} )
634
+
635
+ expect ( Swagger . resolve . mock . calls [ 1 ] [ 0 ] . requestInterceptor ) . toStrictEqual ( requestInterceptor )
636
+ } )
637
+ } )
638
+
591
639
describe ( 'interceptor' , ( ) => {
592
640
beforeEach ( ( ) => {
593
641
Swagger . clearCache ( )
You can’t perform that action at this time.
0 commit comments