Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wordnik/swagger-js
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Nov 7, 2013
2 parents ff34f7a + ecaee69 commit e22c84f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/swagger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/swagger.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ class SwaggerResource

new SwaggerHttp().execute obj

# Constructs an absolute resource's basePath from relative one, using the @api basePath
# eg. if the @api.basePath = http://myhost.com:8090/mywebapp/v0/api-docs
# and the resource response contains a relative basePath='v0'
# then the function will return 'http://myhost.com:8090/mywebapp/v0'
getAbsoluteBasePath: (relativeBasePath) ->
url = @api.basePath
# first check if the base is a part of given url
pos = url.lastIndexOf(relativeBasePath)
if pos is -1
# take the protocol, host and port parts only and glue the 'relativeBasePath'
parts = url.split("/")
url = parts[0] + "//" + parts[2]
if relativeBasePath.indexOf("/") is 0
url + relativeBasePath
else
url + "/" + relativeBasePath
else if (relativeBasePath is "/")
url.substring(0, pos)
else
url.substring(0, pos) + relativeBasePath

addApiDeclaration: (response) ->
if response.produces?
@produces = response.produces
Expand All @@ -260,7 +281,7 @@ class SwaggerResource
# If there is a basePath in response, use that or else use
# the one from the api object
if response.basePath? and response.basePath.replace(/\s/g,'').length > 0
@basePath = response.basePath
@basePath = if response.basePath.indexOf("http") is -1 then @getAbsoluteBasePath(response.basePath) else response.basePath

@addModels(response.models)

Expand Down

0 comments on commit e22c84f

Please sign in to comment.