@@ -251,6 +251,27 @@ class SwaggerResource
251251
252252 new SwaggerHttp ().execute obj
253253
254+ # Constructs an absolute resource's basePath from relative one, using the @api basePath
255+ # eg. if the @api.basePath = http://myhost.com:8090/mywebapp/v0/api-docs
256+ # and the resource response contains a relative basePath='v0'
257+ # then the function will return 'http://myhost.com:8090/mywebapp/v0'
258+ getAbsoluteBasePath : (relativeBasePath ) ->
259+ url = @api .basePath
260+ # first check if the base is a part of given url
261+ pos = url .lastIndexOf (relativeBasePath)
262+ if pos is - 1
263+ # take the protocol, host and port parts only and glue the 'relativeBasePath'
264+ parts = url .split (" /" )
265+ url = parts[0 ] + " //" + parts[2 ]
266+ if relativeBasePath .indexOf (" /" ) is 0
267+ url + relativeBasePath
268+ else
269+ url + " /" + relativeBasePath
270+ else if (relativeBasePath is " /" )
271+ url .substring (0 , pos)
272+ else
273+ url .substring (0 , pos) + relativeBasePath
274+
254275 addApiDeclaration : (response ) ->
255276 if response .produces ?
256277 @produces = response .produces
@@ -260,7 +281,7 @@ class SwaggerResource
260281 # If there is a basePath in response, use that or else use
261282 # the one from the api object
262283 if response .basePath ? and response .basePath .replace (/ \s / g ,' ' ).length > 0
263- @basePath = response .basePath
284+ @basePath = if response . basePath . indexOf ( " http " ) is - 1 then @ getAbsoluteBasePath ( response . basePath ) else response .basePath
264285
265286 @ addModels (response .models )
266287
0 commit comments