support for non GET methods. Closes #15
This commit is contained in:
@@ -8,6 +8,9 @@ class OperationView extends Backbone.View
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
isMethodSubmissionSupported = jQuery.inArray(@model.httpMethod, @model.supportedSubmitMethods()) >= 0
|
||||
@model.isReadOnly = true unless isMethodSubmissionSupported
|
||||
|
||||
$(@el).html(Handlebars.templates.operation(@model))
|
||||
|
||||
# Render each parameter
|
||||
@@ -16,9 +19,10 @@ class OperationView extends Backbone.View
|
||||
|
||||
addParameter: (param) ->
|
||||
# Render a parameter
|
||||
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: !@model.isGetMethod})
|
||||
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly})
|
||||
$('.operation-params', $(@el)).append paramView.render().el
|
||||
|
||||
|
||||
submitOperation: ->
|
||||
# Check for errors
|
||||
form = $('.sandbox', $(@el))
|
||||
@@ -38,6 +42,13 @@ class OperationView extends Backbone.View
|
||||
if(o.value? && jQuery.trim(o.value).length > 0)
|
||||
map[o.name] = o.value
|
||||
|
||||
bodyParam = null
|
||||
for param in @model.parameters
|
||||
if param.paramType is 'body'
|
||||
bodyParam = map[param.name]
|
||||
|
||||
log "bodyParam = " + bodyParam
|
||||
|
||||
headerParams = null
|
||||
invocationUrl =
|
||||
if @model.supportHeaderParams()
|
||||
@@ -56,7 +67,7 @@ class OperationView extends Backbone.View
|
||||
type: @model.httpMethod
|
||||
url: invocationUrl
|
||||
headers: headerParams
|
||||
# data: JSON.stringify(@body)
|
||||
data: bodyParam
|
||||
dataType: 'json'
|
||||
error: (xhr, textStatus, error) =>
|
||||
@showErrorStatus(xhr, textStatus, error)
|
||||
|
||||
@@ -2,6 +2,8 @@ class ParameterView extends Backbone.View
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
@model.isBody = true if @model.paramType == 'body'
|
||||
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
@
|
||||
|
||||
@@ -104,6 +104,11 @@ div.heading_with_menu {
|
||||
box-sizing: border-box;
|
||||
margin-top: 10px; }
|
||||
|
||||
.body-textarea {
|
||||
width: 300px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.4em;
|
||||
padding: 0 0 10px 0;
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
discoveryUrl:"http://petstore.swagger.wordnik.com/api/resources.json",
|
||||
apiKey:"special-key",
|
||||
dom_id:"swagger-ui-container",
|
||||
supportHeaderParams: false
|
||||
supportHeaderParams: false,
|
||||
supportedSubmitMethods: ['get', 'post', 'put']
|
||||
});
|
||||
|
||||
window.swaggerUi.load();
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
{{#if isGetMethod}}
|
||||
{{#if isReadOnly}}
|
||||
{{else}}
|
||||
<div class='sandbox_header'>
|
||||
<input class='submit' name='commit' type='button' value='Try it out!' />
|
||||
<a href='#' class='response_hider' style='display:none'>Hide Response</a>
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
<td class='code'>{{name}}</td>
|
||||
<td>
|
||||
{{#if defaultValue}}
|
||||
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
|
||||
|
||||
{{#if isBody}}
|
||||
{{#if defaultValue}}
|
||||
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
|
||||
{{else}}
|
||||
<textarea class='body-textarea' name='{{name}}'></textarea>
|
||||
{{/if}}
|
||||
|
||||
{{else}}
|
||||
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
|
||||
{{#if defaultValue}}
|
||||
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
|
||||
{{else}}
|
||||
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
</td>
|
||||
<td width='500'>{{description}}</td>
|
||||
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
<td class='code required'>{{name}}</td>
|
||||
<td>
|
||||
{{#if defaultValue}}
|
||||
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
|
||||
{{#if isBody}}
|
||||
{{#if defaultValue}}
|
||||
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea>
|
||||
{{else}}
|
||||
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
|
||||
{{/if}}
|
||||
|
||||
{{else}}
|
||||
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
|
||||
{{#if defaultValue}}
|
||||
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
|
||||
{{else}}
|
||||
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td width='500'>
|
||||
|
||||
Reference in New Issue
Block a user