Browse Source

manual merge of #97

bubble
Tony Tam 11 years ago
parent
commit
d1bffc8fb4
9 changed files with 60 additions and 29 deletions
  1. +1
    -0
      Cakefile
  2. +3
    -2
      lib/swagger.js
  3. +16
    -2
      src/main/coffeescript/view/OperationView.coffee
  4. +13
    -6
      src/main/coffeescript/view/ParameterView.coffee
  5. +0
    -7
      src/main/coffeescript/view/ResourceView.coffee
  6. +9
    -0
      src/main/html/css/screen.css
  7. +7
    -5
      src/main/template/operation.handlebars
  8. +5
    -3
      src/main/template/param.handlebars
  9. +6
    -4
      src/main/template/param_required.handlebars

+ 1
- 0
Cakefile View File

@@ -11,6 +11,7 @@ sourceFiles = [
'view/StatusCodeView'
'view/ParameterView'
'view/SignatureView'
'view/ContentTypeView'
]




+ 3
- 2
lib/swagger.js View File

@@ -255,7 +255,7 @@
_results = [];
for (_i = 0, _len = ops.length; _i < _len; _i++) {
o = ops[_i];
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this);
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this, o.supportedContentTypes);
this.operations[op.nickname] = op;
_results.push(this.operationsArray.push(op));
}
@@ -413,7 +413,7 @@

SwaggerOperation = (function() {

function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource) {
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, supportedContentTypes) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
_this = this;
this.nickname = nickname;
@@ -425,6 +425,7 @@
this.responseClass = responseClass;
this.errorResponses = errorResponses;
this.resource = resource;
this.supportedContentTypes = supportedContentTypes;
this["do"] = __bind(this["do"], this);

if (this.nickname == null) {


+ 16
- 2
src/main/coffeescript/view/OperationView.coffee View File

@@ -24,7 +24,13 @@ class OperationView extends Backbone.View
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
$('.model-signature', $(@el)).html(@model.responseClass)

contentTypeModel =
isParam: false
supportedContentTypes: @model.supportedContentTypes

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

# Render each parameter
@addParameter param for param in @model.parameters
@@ -118,6 +124,14 @@ class OperationView extends Backbone.View

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

responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(@el)).val()
if responseContentTypeField
obj.headers.accept = responseContentTypeField
jQuery.ajax(obj)
false
# $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r)
@@ -158,5 +172,5 @@ class OperationView extends Backbone.View
hljs.highlightBlock($('.response_body', $(@el))[0])

toggleOperationContent: ->
elem = $('#' + @model.resourceName + "_" + @model.nickname + "_" + @model.httpMethod + "_" + @model.number + "_content");
elem = $('#' + @model.resourceName + "_" + @model.nickname + "_" + @model.httpMethod + "_content");
if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem)

+ 13
- 6
src/main/coffeescript/view/ParameterView.coffee View File

@@ -9,15 +9,22 @@ class ParameterView extends Backbone.View
$(@el).html(template(@model))

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

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

contentTypeModel =
isParam: true
supportedContentTypes: @model.supportedContentTypes

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

@



+ 0
- 7
src/main/coffeescript/view/ResourceView.coffee View File

@@ -4,18 +4,11 @@ class ResourceView extends Backbone.View
render: ->
$(@el).html(Handlebars.templates.resource(@model))

@number = 0

# Render each operation
@addOperation operation for operation in @model.operationsArray
@

addOperation: (operation) ->

operation.number = @number

# Render an operation and add it to operations li
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint'})
$('.endpoints', $(@el)).append operationView.render().el

@number++

+ 9
- 0
src/main/html/css/screen.css View File

@@ -1579,3 +1579,12 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio
pre code {
background: none;
}

.content > .content-type > div > label {
clear: both;
display: block;
color: #0F6AB4;
font-size: 1.1em;
margin: 0;
padding: 15px 0 5px 0px;
}

+ 7
- 5
src/main/template/operation.handlebars View File

@@ -1,22 +1,22 @@

<ul class='operations' >
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}'>
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}'>
<div class='heading'>
<h3>
<span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{httpMethod}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{httpMethod}}</a>
</span>
<span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{path}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{path}}</a>
</span>
</h3>
<ul class='options'>
<li>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}' class="toggleOperation">{{{summary}}}</a>
</li>
</ul>
</div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}_content' style='display:none'>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_content' style='display:none'>
{{#if notes}}
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
@@ -25,6 +25,8 @@
<h4>Response Model</h4>
<span class="model-signature"></span>
{{/if}}
<br/>
<div class="content-type" />
<form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div>
<h4>Parameters</h4>


+ 5
- 3
src/main/template/param.handlebars View File

@@ -8,20 +8,22 @@
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' name='{{name}}'></textarea>
<textarea class='body-textarea' name='{{name}}'></textarea>
<br />
<div class="content-type" />
{{/if}}
{{/if}}
{{else}}
{{#if defaultValue}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
{{else}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
<input minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
{{/if}}
{{/if}}

</td>
<td>{{{description}}}</td>
<td>
<span class="model-signature"></span>
<span class="model-signature"></span>
</td>


+ 6
- 4
src/main/template/param_required.handlebars View File

@@ -7,7 +7,9 @@
{{#if defaultValue}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<br />
<div class="content-type" />
{{/if}}
{{/if}}
{{else}}
@@ -15,14 +17,14 @@
<input class='required' type='file' name='{{name}}'/>
{{else}}
{{#if defaultValue}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{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=''/>
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
{{/if}}
{{/if}}
{{/if}}
</td>
<td>
<strong>{{{description}}}</strong>
<strong>{{{description}}}</strong>
</td>
<td><span class="model-signature"></span></td>

Loading…
Cancel
Save