Skip to content

Commit e04b756

Browse files
committed
Merge pull request swagger-api#507 from jbryson3/master
Provide option highlightSizeThreshold
2 parents 9955bcc + 28c7597 commit e04b756

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
6262
* *sorter* apply a sort to the API list. It can be 'alpha' (sort paths alphanumerically) or 'method' (sort operations by HTTP method). Default is the order returned by the server unchanged.
6363
* *onComplete* is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
6464
* *onFailure* is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
65+
* *highlightSizeThreshold* any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses
6566
* All other parameters are explained in greater detail below
6667

6768

src/main/coffeescript/view/MainView.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MainView extends Backbone.View
3333

3434
addResource: (resource) ->
3535
# Render a resource and add it to resources li
36-
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource'})
36+
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource', swaggerOptions: @options.swaggerOptions})
3737
$('#resources').append resourceView.render().el
3838

3939
clear: ->

src/main/coffeescript/view/OperationView.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ class OperationView extends Backbone.View
363363
$(".response", $(@el)).slideDown()
364364
$(".response_hider", $(@el)).show()
365365
$(".response_throbber", $(@el)).hide()
366-
hljs.highlightBlock($('.response_body', $(@el))[0])
366+
response_body_el = $('.response_body', $(@el))[0]
367+
# only highlight the response if response is less than threshold, default state is highlight response
368+
opts = @options.swaggerOptions
369+
if opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold then response_body_el else hljs.highlightBlock(response_body_el)
367370

368371
toggleOperationContent: ->
369372
elem = $('#' + Docs.escapeResourceName(@model.parentId) + "_" + @model.nickname + "_content")

src/main/coffeescript/view/ResourceView.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ResourceView extends Backbone.View
2727
operation.number = @number
2828

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

3333
@number++

0 commit comments

Comments
 (0)