From db6419414c5fe9984282662b9c7fbefba593179b Mon Sep 17 00:00:00 2001 From: Chris Hatch Date: Sun, 20 Jul 2014 20:18:19 +0800 Subject: [PATCH] #254 alphabetical sort of apis and operations under apis new option sortAlphabetical=true|false --- src/main/coffeescript/SwaggerUi.coffee | 2 +- src/main/coffeescript/view/MainView.coffee | 12 ++++++++++-- src/main/html/index.html | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/coffeescript/SwaggerUi.coffee b/src/main/coffeescript/SwaggerUi.coffee index fc0474fd..909cd6d7 100644 --- a/src/main/coffeescript/SwaggerUi.coffee +++ b/src/main/coffeescript/SwaggerUi.coffee @@ -55,7 +55,7 @@ class SwaggerUi extends Backbone.Router # so it gets called when SwaggerApi completes loading render:() -> @showMessage('Finished Loading Resource Information. Rendering Swagger UI...') - @mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render() + @mainView = new MainView({model: @api, el: $('#' + @dom_id), swaggerOptions: @options}).render() @showMessage() switch @options.docExpansion when "full" then Docs.expandOperationsForResource('') diff --git a/src/main/coffeescript/view/MainView.coffee b/src/main/coffeescript/view/MainView.coffee index ae03f663..3237fd86 100644 --- a/src/main/coffeescript/view/MainView.coffee +++ b/src/main/coffeescript/view/MainView.coffee @@ -1,5 +1,12 @@ class MainView extends Backbone.View - initialize: -> + initialize: (opts={}) -> + if opts.swaggerOptions.sortAlphabetically == true + pathSorter = (a,b) -> return a.path.localeCompare(b.path) + # sort apis + @model.apisArray.sort pathSorter + # sort operations + for route in @model.apisArray + route.operationsArray.sort pathSorter render: -> # Render the outer container for resources @@ -10,6 +17,7 @@ class MainView extends Backbone.View resources = {} counter = 0 for resource in @model.apisArray + console.info(resource); id = resource.name while typeof resources[id] isnt 'undefined' id = id + "_" + counter @@ -25,4 +33,4 @@ class MainView extends Backbone.View $('#resources').append resourceView.render().el clear: -> - $(@el).html '' \ No newline at end of file + $(@el).html '' diff --git a/src/main/html/index.html b/src/main/html/index.html index 5af095a0..0de90936 100644 --- a/src/main/html/index.html +++ b/src/main/html/index.html @@ -47,7 +47,8 @@ onFailure: function(data) { log("Unable to Load SwaggerUI"); }, - docExpansion: "none" + docExpansion: "none", + sortAlphabetically: true }); $('#input_apiKey').change(function() {