update for swagger.js#14, #138, #139

This commit is contained in:
Tony Tam
2013-01-31 20:06:34 -05:00
parent 7a23876ce7
commit 1ec55a8829
9 changed files with 114 additions and 44 deletions

View File

@@ -15,5 +15,5 @@ class ContentTypeView extends Backbone.View
@
template: ->
Handlebars.templates.content_type
Handlebars.templates.content_type

View File

@@ -27,7 +27,13 @@ class OperationView extends Backbone.View
contentTypeModel =
isParam: false
supportedContentTypes: @model.supportedContentTypes
# support old syntax
if @model.supportedContentTypes
contentTypeModel.consumes = @model.supportedContentTypes
if @model.consumes
contentTypeModel.consumes = @model.consumes
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
@@ -70,7 +76,23 @@ class OperationView extends Backbone.View
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = o.value
isFileUpload = $('input[type~="file"]').size != 0
isFileUpload = form.children().find('input[type~="file"]').size() != 0
isFormPost = false
consumes = "application/json"
if @model.consumes and @model.consumes.length > 0
# honor the consumes setting above everything else
consumes = @model.consumes[0]
else
for o in @model.parameters
if o.paramType == 'form'
isFormPost = true
consumes = false
if isFileUpload
consumes = false
else if @model.httpMethod.toLowerCase() == "post" and isFormPost is false
consumes = "application/json"
if isFileUpload
# requires HTML5 compatible browser
@@ -82,10 +104,14 @@ class OperationView extends Backbone.View
bodyParam.append(param.name, map[param.name])
# add files
$.each $('input[type~="file"]'), (i, el) ->
$.each form.children().find('input[type~="file"]'), (i, el) ->
bodyParam.append($(el).attr('name'), el.files[0])
console.log(bodyParam)
else if isFormPost
bodyParam = new FormData()
for param in @model.parameters
bodyParam.append(param.name, map[param.name])
else
bodyParam = null
for param in @model.parameters
@@ -113,6 +139,7 @@ class OperationView extends Backbone.View
url: invocationUrl
headers: headerParams
data: bodyParam
contentType: consumes
dataType: 'json'
processData: false
error: (xhr, textStatus, error) =>
@@ -122,8 +149,6 @@ class OperationView extends Backbone.View
complete: (data) =>
@showCompleteStatus(data)
obj.contentType = "application/json" if (obj.type.toLowerCase() == "post" or obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch")
obj.contentType = false if isFileUpload
paramContentTypeField = $("td select[name=contentType]", $(@el)).val()
if paramContentTypeField
obj.contentType = paramContentTypeField

View File

@@ -20,8 +20,14 @@ class ParameterView extends Backbone.View
$('.model-signature', $(@el)).html(@model.signature)
contentTypeModel =
isParam: true
supportedContentTypes: @model.supportedContentTypes
isParam: false
# support old syntax
if @model.supportedContentTypes
contentTypeModel.consumes = @model.supportedContentTypes
if @model.consumes
contentTypeModel.consumes = @model.consumes
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el

View File

@@ -1,7 +1,7 @@
<label for="contentType"></label>
<select name="contentType">
{{#if supportedContentTypes}}
{{#each supportedContentTypes}}
{{#if consumes}}
{{#each consumes}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
{{else}}