Kaynağa Gözat

Merge pull request #95 from pose/json-response-pretty-print

Adding JSON sample UI to response
bubble
Tony Tam 11 yıl önce
ebeveyn
işleme
55f0c1a2f8
6 değiştirilmiş dosya ile 33 ekleme ve 11 silme
  1. +1
    -0
      lib/swagger.js
  2. +12
    -0
      src/main/coffeescript/view/OperationView.coffee
  3. +6
    -1
      src/main/coffeescript/view/ParameterView.coffee
  4. +11
    -3
      src/main/coffeescript/view/SignatureView.coffee
  5. +2
    -6
      src/main/template/operation.handlebars
  6. +1
    -1
      src/main/template/signature.handlebars

+ 1
- 0
lib/swagger.js Dosyayı Görüntüle

@@ -445,6 +445,7 @@
}
if (this.responseClass != null) {
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
}
this.errorResponses = this.errorResponses || [];
_ref1 = this.parameters;


+ 12
- 0
src/main/coffeescript/view/OperationView.coffee Dosyayı Görüntüle

@@ -14,6 +14,18 @@ class OperationView extends Backbone.View

$(@el).html(Handlebars.templates.operation(@model))

if @model.responseClassSignature and @model.responseClassSignature != 'string'
signatureModel =
sampleJSON: @model.responseSampleJSON
isParam: false
signature: @model.responseClassSignature
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
$('.model-signature', $(@el)).html(@model.responseClass)

# Render each parameter
@addParameter param for param in @model.parameters



+ 6
- 1
src/main/coffeescript/view/ParameterView.coffee Dosyayı Görüntüle

@@ -8,8 +8,13 @@ class ParameterView extends Backbone.View
template = @template()
$(@el).html(template(@model))

signatureModel =
sampleJSON: @model.sampleJSON
isParam: true
signature: @model.signature

if @model.sampleJSON
signatureView = new SignatureView({model: @model, tagName: 'div'})
signatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append signatureView.render().el
else
$('.model-signature', $(@el)).html(@model.signature)


+ 11
- 3
src/main/coffeescript/view/SignatureView.coffee Dosyayı Görüntüle

@@ -13,6 +13,11 @@ class SignatureView extends Backbone.View

@switchToDescription()

@isParam = @model.isParam

if @isParam
$('.notice', $(@el)).text('Click to set as parameter value')

@

template: ->
@@ -36,8 +41,11 @@ class SignatureView extends Backbone.View

# handler for snippet to text area
snippetToTextArea: (e) ->
e?.preventDefault()
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
if $.trim(textArea.val()) == ''
if @isParam
e?.preventDefault()
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
if $.trim(textArea.val()) == ''
textArea.val(@model.sampleJSON)



+ 2
- 6
src/main/template/operation.handlebars Dosyayı Görüntüle

@@ -22,12 +22,8 @@
<p>{{{notes}}}</p>
{{/if}}
{{#if responseClass}}
<h4>Response Class</h4>
{{#if responseClassSignature}}
<p><span class="model-signature">{{{responseClassSignature}}}</span></p>
{{else}}
<p>{{{responseClass}}}</p>
{{/if}}
<h4>Response Model</h4>
<span class="model-signature"></span>
{{/if}}
<form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div>


+ 1
- 1
src/main/template/signature.handlebars Dosyayı Görüntüle

@@ -12,7 +12,7 @@

<div class="snippet">
<pre><code>{{sampleJSON}}</code></pre>
<small>Click to set as parameter value</small>
<small class="notice"></small>
</div>
</div>


Yükleniyor…
İptal
Kaydet