forked from darosh/angular-swagger-ui-material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.js
36 lines (29 loc) · 1.27 KB
/
operations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
angular.module('sw.plugin.operations', ['sw.plugins'])
// List ungrouped operations
.factory('operations', function ($q) {
return {
execute: function (parseResult) {
var deferred = $q.defer();
parseResult.info.operations = [];
angular.forEach(parseResult.resources, function (resource) {
angular.forEach(resource.operations, function (operation) {
parseResult.info.operations.push(operation);
});
// TODO: allow configuration of minimum auto expanded endpoints
if (parseResult.resources.length <= 8) {
resource.open = true;
}
});
parseResult.info.operations.sort(function (a, b) {
return (a.path.toLowerCase().replace(/[^a-z]+/gi, '') + '-' + a.httpMethod)
.localeCompare(b.path.toLowerCase().replace(/[^a-z]+/gi, '') + '-' + b.httpMethod);
});
deferred.resolve();
return deferred.promise;
}
};
})
.run(function (plugins, operations) {
plugins.add(plugins.BEFORE_DISPLAY, operations);
});