@@ -104,7 +104,7 @@ export function buildRequest(options) {
104104
105105 // Base Template
106106 let req = {
107- url : baseUrl ( { spec , scheme , contextUrl , server , serverVariables } ) ,
107+ url : '' ,
108108 credentials : 'same-origin' ,
109109 headers : {
110110 // This breaks CORSs... removing this line... probably breaks oAuth. Need to address that
@@ -124,6 +124,15 @@ export function buildRequest(options) {
124124 req . userFetch = userFetch
125125 }
126126
127+ const operationRaw = getOperationRaw ( spec , operationId )
128+ if ( ! operationRaw ) {
129+ throw new OperationNotFoundError ( `Operation ${ operationId } not found` )
130+ }
131+
132+ const { operation = { } , method, pathName} = operationRaw
133+
134+ req . url += baseUrl ( { spec, scheme, contextUrl, server, serverVariables, pathName, method} )
135+
127136 // Mostly for testing
128137 if ( ! operationId ) {
129138 // Not removing req.cookies causes testing issues and would
@@ -134,13 +143,6 @@ export function buildRequest(options) {
134143 return req
135144 }
136145
137- const operationRaw = getOperationRaw ( spec , operationId )
138- if ( ! operationRaw ) {
139- throw new OperationNotFoundError ( `Operation ${ operationId } not found` )
140- }
141-
142- const { operation = { } , method, pathName} = operationRaw
143-
144146 req . url += pathName // Have not yet replaced the path parameters
145147 req . method = ( `${ method } ` ) . toUpperCase ( )
146148
@@ -240,8 +242,11 @@ export function baseUrl(obj) {
240242 return specIsOAS3 ? oas3BaseUrl ( obj ) : swagger2BaseUrl ( obj )
241243}
242244
243- function oas3BaseUrl ( { spec, server, contextUrl, serverVariables = { } } ) {
244- const servers = spec . servers
245+ function oas3BaseUrl ( { spec, pathName, method, server, contextUrl, serverVariables = { } } ) {
246+ const servers =
247+ getIn ( spec , [ 'paths' , pathName , ( method || '' ) . toLowerCase ( ) , 'servers' ] ) ||
248+ getIn ( spec , [ 'paths' , pathName , 'servers' ] ) ||
249+ getIn ( spec , [ 'servers' ] )
245250
246251 let selectedServerUrl = ''
247252 let selectedServerObj = null
0 commit comments