merged from develop

This commit is contained in:
Tony Tam
2014-09-18 21:26:04 -07:00
13 changed files with 5862 additions and 3115 deletions

View File

@@ -22,9 +22,16 @@ class SwaggerUi extends Backbone.Router
@options = options
# Set the callbacks
@options.success = => @render()
@options.success = =>
@render()
@options.progress = (d) => @showMessage(d)
@options.failure = (d) => @onLoadFailure(d)
@options.failure = (d) =>
if @api and @api.isValid is false
log "not a valid 2.0 spec, loading legacy client"
@api = new SwaggerApi(@options)
@api.build()
else
@onLoadFailure(d)
# Create view to handle the header inputs
@headerView = new HeaderView({el: $('#header')})
@@ -47,9 +54,9 @@ class SwaggerUi extends Backbone.Router
@options.url = url
@headerView.update(url)
@api = new SwaggerApi(@options)
@api.build()
@api
@api = new SwaggerClient(@options)
@api.build()
# This is bound to success handler for SwaggerApi
# so it gets called when SwaggerApi completes loading

View File

@@ -8,10 +8,19 @@ class MainView extends Backbone.View
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
@model.apisArray.sort sorter
if @model.apisArray
for route in @model.apisArray
route.operationsArray.sort sorter
if (sorterName == "alpha") # sort top level paths if alpha
@model.apisArray.sort sorter
log @model
if @model.info.license and typeof @model.info.license is 'string'
name = @model.info.license
url = @model.info.licenseUrl
@model.info.license = {}
@model.info.license.name = name
@model.info.license.url = url
render: ->
# Render the outer container for resources
@@ -33,6 +42,7 @@ class MainView extends Backbone.View
addResource: (resource) ->
# Render a resource and add it to resources li
resource.id = resource.id.replace(/\s/g, '_')
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource', swaggerOptions: @options.swaggerOptions})
$('#resources').append resourceView.render().el

View File

@@ -66,6 +66,7 @@ class OperationView extends Backbone.View
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
$('.model-signature', $(@el)).append responseSignatureView.render().el
else
@model.responseClassSignature = 'string'
$('.model-signature', $(@el)).html(@model.type)
contentTypeModel =
@@ -76,10 +77,18 @@ class OperationView extends Backbone.View
for param in @model.parameters
type = param.type || param.dataType
if type.toLowerCase() == 'file'
if typeof type is 'undefined'
schema = param.schema
if schema['$ref']
ref = schema['$ref']
if ref.indexOf('#/definitions/') is 0
type = ref.substring('#/definitions/'.length)
else
type = ref
if type and type.toLowerCase() == 'file'
if !contentTypeModel.consumes
log "set content type "
contentTypeModel.consumes = 'multipart/form-data'
param.type = type
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
@@ -88,6 +97,8 @@ class OperationView extends Backbone.View
@addParameter param, contentTypeModel.consumes for param in @model.parameters
# Render each response code
if typeof @model.responseMessages is 'undefined'
@model.responseMessages = []
@addStatusCode statusCode for statusCode in @model.responseMessages
@
@@ -171,8 +182,6 @@ class OperationView extends Backbone.View
if param.paramType is 'header'
headerParams[param.name] = map[param.name]
log headerParams
# add files
for el in form.find('input[type~="file"]')
if typeof el.files[0] isnt 'undefined'

View File

@@ -9,8 +9,21 @@ class ParameterView extends Backbone.View
render: ->
type = @model.type || @model.dataType
if typeof type is 'undefined'
schema = @model.schema
if schema['$ref']
ref = schema['$ref']
if ref.indexOf('#/definitions/') is 0
type = ref.substring('#/definitions/'.length)
else
type = ref
@model.type = type
@model.paramType = @model.in || @model.paramType
@model.isBody = true if @model.paramType == 'body'
@model.isFile = true if type.toLowerCase() == 'file'
@model.isFile = true if type and type.toLowerCase() == 'file'
#@model.signature = type
template = @template()
$(@el).html(template(@model))

View File

@@ -1,5 +1,7 @@
class ResourceView extends Backbone.View
initialize: ->
if "" is @model.description
@model.description = null
render: ->
$(@el).html(Handlebars.templates.resource(@model))