Fix #1040 : add options to be able to sort APIs and operations
This commit is contained in:
@@ -91,7 +91,8 @@ validatorUrl | By default, Swagger-UI attempts to validate specs against swagger
|
||||
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
|
||||
booleanValues | SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1).
|
||||
docExpansion | Controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details).
|
||||
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.
|
||||
apisSorter | Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
||||
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
||||
onComplete | This is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
|
||||
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
|
||||
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.
|
||||
|
||||
@@ -1,21 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
SwaggerUi.Views.MainView = Backbone.View.extend({
|
||||
|
||||
// TODO: sorters were not used in any place, do we need them?
|
||||
// sorters = {
|
||||
// alpha : function(a,b){ return a.path.localeCompare(b.path); },
|
||||
// method : function(a,b){ return a.method.localeCompare(b.method); },
|
||||
// },
|
||||
|
||||
apisSorters : {
|
||||
alpha : function(a,b){ return a.name.localeCompare(b.name); }
|
||||
},
|
||||
operationsSorters : {
|
||||
alpha : function(a,b){ return a.path.localeCompare(b.path); },
|
||||
method : function(a,b){ return a.method.localeCompare(b.method); }
|
||||
},
|
||||
initialize: function(opts){
|
||||
var sorterOption, sorterFn, key, value;
|
||||
opts = opts || {};
|
||||
|
||||
this.router = opts.router;
|
||||
|
||||
// Sort APIs
|
||||
if (opts.swaggerOptions.apisSorter) {
|
||||
sorterOption = opts.swaggerOptions.apisSorter;
|
||||
if (_.isFunction(sorterOption)) {
|
||||
sorterFn = sorterOption;
|
||||
} else {
|
||||
sorterFn = this.apisSorters[sorterOption];
|
||||
}
|
||||
if (_.isFunction(sorterFn)) {
|
||||
this.model.apisArray.sort(sorterFn);
|
||||
}
|
||||
}
|
||||
// Sort operations of each API
|
||||
if (opts.swaggerOptions.operationsSorter) {
|
||||
sorterOption = opts.swaggerOptions.operationsSorter;
|
||||
if (_.isFunction(sorterOption)) {
|
||||
sorterFn = sorterOption;
|
||||
} else {
|
||||
sorterFn = this.operationsSorters[sorterOption];
|
||||
}
|
||||
if (_.isFunction(sorterFn)) {
|
||||
for (key in this.model.apisArray) {
|
||||
this.model.apisArray[key].operationsArray.sort(sorterFn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set up the UI for input
|
||||
this.model.auths = [];
|
||||
var key, value;
|
||||
|
||||
for (key in this.model.securityDefinitions) {
|
||||
value = this.model.securityDefinitions[key];
|
||||
|
||||
Reference in New Issue
Block a user