Skip to content

Commit db64194

Browse files
author
Chris Hatch
committed
swagger-api#254 alphabetical sort of apis and operations under apis
new option sortAlphabetical=true|false
1 parent 9b9b5b4 commit db64194

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/main/coffeescript/SwaggerUi.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SwaggerUi extends Backbone.Router
5555
# so it gets called when SwaggerApi completes loading
5656
render:() ->
5757
@showMessage('Finished Loading Resource Information. Rendering Swagger UI...')
58-
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
58+
@mainView = new MainView({model: @api, el: $('#' + @dom_id), swaggerOptions: @options}).render()
5959
@showMessage()
6060
switch @options.docExpansion
6161
when "full" then Docs.expandOperationsForResource('')

src/main/coffeescript/view/MainView.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
class MainView extends Backbone.View
2-
initialize: ->
2+
initialize: (opts={}) ->
3+
if opts.swaggerOptions.sortAlphabetically == true
4+
pathSorter = (a,b) -> return a.path.localeCompare(b.path)
5+
# sort apis
6+
@model.apisArray.sort pathSorter
7+
# sort operations
8+
for route in @model.apisArray
9+
route.operationsArray.sort pathSorter
310

411
render: ->
512
# Render the outer container for resources
@@ -10,6 +17,7 @@ class MainView extends Backbone.View
1017
resources = {}
1118
counter = 0
1219
for resource in @model.apisArray
20+
console.info(resource);
1321
id = resource.name
1422
while typeof resources[id] isnt 'undefined'
1523
id = id + "_" + counter
@@ -25,4 +33,4 @@ class MainView extends Backbone.View
2533
$('#resources').append resourceView.render().el
2634

2735
clear: ->
28-
$(@el).html ''
36+
$(@el).html ''

src/main/html/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
onFailure: function(data) {
4848
log("Unable to Load SwaggerUI");
4949
},
50-
docExpansion: "none"
50+
docExpansion: "none",
51+
sortAlphabetically: true
5152
});
5253

5354
$('#input_apiKey').change(function() {

0 commit comments

Comments
 (0)