From d1bffc8fb4a390414b89e681174ad5cb0f32e438 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sun, 25 Nov 2012 21:52:30 -0800 Subject: [PATCH] manual merge of #97 --- Cakefile | 1 + lib/swagger.js | 5 +++-- .../coffeescript/view/OperationView.coffee | 18 ++++++++++++++++-- .../coffeescript/view/ParameterView.coffee | 19 +++++++++++++------ .../coffeescript/view/ResourceView.coffee | 7 ------- src/main/html/css/screen.css | 9 +++++++++ src/main/template/operation.handlebars | 12 +++++++----- src/main/template/param.handlebars | 8 +++++--- src/main/template/param_required.handlebars | 10 ++++++---- 9 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Cakefile b/Cakefile index 2640d69b..0a492f5a 100644 --- a/Cakefile +++ b/Cakefile @@ -11,6 +11,7 @@ sourceFiles = [ 'view/StatusCodeView' 'view/ParameterView' 'view/SignatureView' + 'view/ContentTypeView' ] diff --git a/lib/swagger.js b/lib/swagger.js index c4ee5ed3..9fb9fcb2 100644 --- a/lib/swagger.js +++ b/lib/swagger.js @@ -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) { diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index 4cc3da60..5de4f1c5 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -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) diff --git a/src/main/coffeescript/view/ParameterView.coffee b/src/main/coffeescript/view/ParameterView.coffee index c4d75d87..fd67a952 100644 --- a/src/main/coffeescript/view/ParameterView.coffee +++ b/src/main/coffeescript/view/ParameterView.coffee @@ -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 @ diff --git a/src/main/coffeescript/view/ResourceView.coffee b/src/main/coffeescript/view/ResourceView.coffee index 1ec80f79..993a07eb 100644 --- a/src/main/coffeescript/view/ResourceView.coffee +++ b/src/main/coffeescript/view/ResourceView.coffee @@ -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++ diff --git a/src/main/html/css/screen.css b/src/main/html/css/screen.css index 94815fd7..d6525749 100644 --- a/src/main/html/css/screen.css +++ b/src/main/html/css/screen.css @@ -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; +} diff --git a/src/main/template/operation.handlebars b/src/main/template/operation.handlebars index e623dc2a..0f9a65a1 100644 --- a/src/main/template/operation.handlebars +++ b/src/main/template/operation.handlebars @@ -1,22 +1,22 @@