1
|
$(function() {
|
2
|
var springfox = {
|
3
|
"baseUrl": function() {
|
4
|
var urlMatches = /(.*)\/doc\/.*/.exec(window.location.href);
|
5
|
return urlMatches[1];
|
6
|
},
|
7
|
"securityConfig": function(cb) {
|
8
|
$.getJSON(this.baseUrl() + "/configuration/security", function(data) {
|
9
|
cb(data);
|
10
|
});
|
11
|
},
|
12
|
"uiConfig": function(cb) {
|
13
|
$.getJSON(this.baseUrl() + "/configuration/ui", function(data) {
|
14
|
cb(data);
|
15
|
});
|
16
|
}
|
17
|
};
|
18
|
window.springfox = springfox;
|
19
|
window.oAuthRedirectUrl = springfox.baseUrl() + 'doc//webjars/springfox-swagger-ui/o2c.html'
|
20
|
|
21
|
function maybePrefix(location, withRelativePath) {
|
22
|
var pat = /^https?:\/\//i;
|
23
|
if (pat.test(location)) {
|
24
|
return location;
|
25
|
}
|
26
|
return withRelativePath + location;
|
27
|
}
|
28
|
|
29
|
function getUrlParam(key){
|
30
|
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
|
31
|
var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
|
32
|
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
|
33
|
}
|
34
|
|
35
|
function menuItemId(groupName){
|
36
|
return 'menu_' + groupName.replace(/\s/g, "_");
|
37
|
}
|
38
|
|
39
|
$(document).ready(function() {
|
40
|
var relativeLocation = springfox.baseUrl();
|
41
|
|
42
|
$('#input_baseUrl').hide();
|
43
|
|
44
|
$.getJSON(relativeLocation + "/swagger-resources", function(data) {
|
45
|
|
46
|
var $menulist = $('#select_baseUrl');
|
47
|
$menulist.empty();
|
48
|
$.each(data, function(i, resource) {
|
49
|
// <li id="menu_Generic_REST_API"><a href="?group=Generic+REST+API">Generic REST API</a></li>
|
50
|
var id = menuItemId(resource.name);
|
51
|
var link = $('<a></a>')
|
52
|
.attr("href", maybePrefix(resource.location, relativeLocation))
|
53
|
.text(resource.name);
|
54
|
var option = $('<li></li>').attr("id", id).append(link);
|
55
|
$menulist.append(option);
|
56
|
});
|
57
|
$('#select_baseUrl a').click(function(event) {
|
58
|
event.preventDefault()
|
59
|
window.swaggerUi.headerView.trigger(
|
60
|
'update-swagger-ui',
|
61
|
{url: $(event.target).attr('href')}
|
62
|
);
|
63
|
});
|
64
|
|
65
|
var initialGroup = getUrlParam('group');
|
66
|
if(initialGroup) {
|
67
|
$('#' + menuItemId(initialGroup) + " a").click();
|
68
|
}
|
69
|
});
|
70
|
|
71
|
});
|
72
|
|
73
|
});
|
74
|
|
75
|
|