Skip to content

Commit

Permalink
fix for swagger-api#263
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Jul 17, 2013
1 parent 737a128 commit 95fea61
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/main/coffeescript/SwaggerUi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class SwaggerUi extends Backbone.Router
load: ->
# Initialize the API object
@mainView?.clear()
@headerView.update(@options.url)
url = @options.url
if url.indexOf("http") isnt 0
url = @buildUrl(window.location.href.toString(), url)

@options.url = url
@headerView.update(url)
@api = new SwaggerApi(@options)
@api.build()
@api
Expand All @@ -62,6 +67,16 @@ class SwaggerUi extends Backbone.Router
400
)

buildUrl: (base, url) ->
console.log "base is " + base
parts = base.split("/")
base = parts[0] + "//" + parts[2]
if url.indexOf("/") is 0
base + url
else
base + "/" + url


# Shows message on topbar of the ui
showMessage: (data = '') ->
$('#message-bar').removeClass 'message-fail'
Expand Down
9 changes: 8 additions & 1 deletion src/main/coffeescript/view/OperationView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class OperationView extends Backbone.View
contentTypeModel.consumes = @model.consumes
contentTypeModel.produces = @model.produces

for param in @model.parameters
console.log "looking at " + param.dataType
if param.dataType.toLowerCase() == 'file'
if !contentTypeModel.consumes
console.log "set content type "
contentTypeModel.consumes = 'multipart/form-data'

responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el

Expand Down Expand Up @@ -74,7 +81,7 @@ class OperationView extends Backbone.View
#if(o.value? && jQuery.trim(o.value).length > 0)
#map[o.name] = o.value

for o in form.find(".body-textarea,.parameter")
for o in form.find("input")
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = encodeURI(o.value)

Expand Down
2 changes: 1 addition & 1 deletion src/main/coffeescript/view/ParameterView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ParameterView extends Backbone.View

render: ->
@model.isBody = true if @model.paramType == 'body'
@model.isFile = true if @model.dataType == 'file'
@model.isFile = true if @model.dataType.toLowerCase() == 'file'

template = @template()
$(@el).html(template(@model))
Expand Down
1 change: 1 addition & 0 deletions src/main/template/param.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{#if isBody}}
{{#if isFile}}
<input type="file" name='{{name}}'/>
<div class="parameter-content-type" />
{{else}}
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
Expand Down

0 comments on commit 95fea61

Please sign in to comment.