Skip to content

Changes to support swagger 1.2 #1661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"swagger-client": "2.0.36",
"handlebars": "~1.0.10",
"less": "~1.4.2"
}
},
"main": "dist/swagger-ui.js"
}
5 changes: 3 additions & 2 deletions src/main/coffeescript/view/MainView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class MainView extends Backbone.View
}

initialize: (opts={}) ->
@options = opts
if opts.swaggerOptions.sorter
sorterName = opts.swaggerOptions.sorter
sorter = sorters[sorterName]
for route in @model.apisArray
route.operationsArray.sort sorter
if (sorterName == "alpha") # sort top level paths if alpha
if (sorterName == "alpha") # sort top level paths if alpha
@model.apisArray.sort sorter

render: ->
# Render the outer container for resources
$(@el).html(Handlebars.templates.main(@model))
Expand Down
31 changes: 16 additions & 15 deletions src/main/coffeescript/view/OperationView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class OperationView extends Backbone.View
'mouseout .api-ic' : 'mouseExit'
}

initialize: ->
initialize: (opts={}) ->
@options = opts

mouseEnter: (e) ->
elem = $(e.currentTarget.parentNode).find('#api_information_panel')
Expand Down Expand Up @@ -41,7 +42,7 @@ class OperationView extends Backbone.View
$(e.currentTarget.parentNode).find('#api_information_panel').hide()

render: ->
isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0
isMethodSubmissionSupported = jQuery.inArray(@model.method, @options.swaggerOptions.supportedSubmitMethods) >= 0
@model.isReadOnly = true unless isMethodSubmissionSupported

@model.oauth = null
Expand All @@ -62,7 +63,7 @@ class OperationView extends Backbone.View
sampleJSON: @model.responseSampleJSON
isParam: false
signature: @model.responseClassSignature

responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
Expand Down Expand Up @@ -102,7 +103,7 @@ class OperationView extends Backbone.View
# Render status codes
statusCodeView = new StatusCodeView({model: statusCode, tagName: 'tr'})
$('.operation-status', $(@el)).append statusCodeView.render().el

submitOperation: (e) ->
e?.preventDefault()
# Check for errors
Expand Down Expand Up @@ -133,7 +134,7 @@ class OperationView extends Backbone.View
if(o.value? && jQuery.trim(o.value).length > 0)
map["body"] = o.value

for o in form.find("select")
for o in form.find("select")
val = this.getSelectedValue o
if(val? && jQuery.trim(val).length > 0)
map[o.name] = val
Expand Down Expand Up @@ -179,17 +180,17 @@ class OperationView extends Backbone.View
bodyParam.append($(el).attr('name'), el.files[0])
params += 1

@invocationUrl =
@invocationUrl =
if @model.supportHeaderParams()
headerParams = @model.getHeaderParams(map)
@model.urlify(map, false)
else
@model.urlify(map, true)

$(".request_url", $(@el)).html("<pre></pre>")
$(".request_url", $(@el)).html("<pre></pre>")
$(".request_url pre", $(@el)).text(@invocationUrl);
obj =

obj =
type: @model.method
url: @invocationUrl
headers: headerParams
Expand Down Expand Up @@ -235,12 +236,12 @@ class OperationView extends Backbone.View
o

getSelectedValue: (select) ->
if !select.multiple
if !select.multiple
select.value
else
options = []
options.push opt.value for opt in select.options when opt.selected
if options.length > 0
if options.length > 0
options.join ","
else
null
Expand Down Expand Up @@ -276,7 +277,7 @@ class OperationView extends Backbone.View
lines = xml.split('\n')
indent = 0
lastType = 'other'
# 4 types of tags - single, closing, opening, other (text, doctype, comment) - 4*4 = 16 transitions
# 4 types of tags - single, closing, opening, other (text, doctype, comment) - 4*4 = 16 transitions
transitions =
'single->single': 0
'single->closing': -1
Expand Down Expand Up @@ -320,9 +321,9 @@ class OperationView extends Backbone.View
formatted = formatted.substr(0, formatted.length - 1) + ln + '\n'
else
formatted += padding + ln + '\n'

formatted


# puts the response data in UI
showStatus: (response) ->
Expand Down Expand Up @@ -357,7 +358,7 @@ class OperationView extends Backbone.View
pre = $('<pre class="json" />').append(code)

response_body = pre
$(".request_url", $(@el)).html("<pre></pre>")
$(".request_url", $(@el)).html("<pre></pre>")
$(".request_url pre", $(@el)).text(url);
$(".response_code", $(@el)).html "<pre>" + response.status + "</pre>"
$(".response_body", $(@el)).html response_body
Expand Down
5 changes: 3 additions & 2 deletions src/main/coffeescript/view/ParameterView.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class ParameterView extends Backbone.View
initialize: ->
initialize: (opts={}) ->
@options = opts
Handlebars.registerHelper 'isArray',
(param, opts) ->
if param.type.toLowerCase() == 'array' || param.allowMultiple
opts.fn(@)
else
opts.inverse(@)

render: ->
type = @model.type || @model.dataType
@model.isBody = true if @model.paramType == 'body'
Expand Down
7 changes: 4 additions & 3 deletions src/main/coffeescript/view/ResourceView.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ResourceView extends Backbone.View
initialize: ->
initialize: (opts={}) ->
@options = opts

render: ->
$(@el).html(Handlebars.templates.resource(@model))
Expand All @@ -19,12 +20,12 @@ class ResourceView extends Backbone.View

operation.nickname = id
operation.parentId = @model.id
@addOperation operation
@addOperation operation

$('.toggleEndpointList', @el).click(this.callDocs.bind(this, 'toggleEndpointListForResource'))
$('.collapseResource', @el).click(this.callDocs.bind(this, 'collapseOperationsForResource'))
$('.expandResource', @el).click(this.callDocs.bind(this, 'expandOperationsForResoruce'))

return @

addOperation: (operation) ->
Expand Down