index.html
8.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>%(DocumentTitle)</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css">
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}
</style>
%(HeadContent)
</head>
<body>
<div id="swagger-ui"></div>
<!-- Workaround for https://github.com/swagger-api/swagger-editor/issues/1371 -->
<script>
if (window.navigator.userAgent.indexOf("Edge") > -1) {
console.log("Removing native Edge fetch in favor of swagger-ui's polyfill")
window.fetch = undefined;
}
</script>
<script src="./swagger-ui-bundle.js"></script>
<script src="./swagger-ui-standalone-preset.js"></script>
<script>
/* Source: https://gist.github.com/lamberta/3768814
* Parse a string function definition and return a function object. Does not use eval.
* @param {string} str
* @return {function}
*
* Example:
* var f = function (x, y) { return x * y; };
* var g = parseFunction(f.toString());
* g(33, 3); //=> 99
*/
function parseFunction(str) {
if (!str) return void (0);
var fn_body_idx = str.indexOf('{'),
fn_body = str.substring(fn_body_idx + 1, str.lastIndexOf('}')),
fn_declare = str.substring(0, fn_body_idx),
fn_params = fn_declare.substring(fn_declare.indexOf('(') + 1, fn_declare.lastIndexOf(')')),
args = fn_params.split(',');
args.push(fn_body);
function Fn() {
return Function.apply(this, args);
}
Fn.prototype = Function.prototype;
return new Fn();
}
// get uri all query variables
function getQueryVariables(uri) {
var searchArgs = window.location.search;
if (uri) {
var s = uri.indexOf('?');
searchArgs = s > -1 ? uri.substring(s) : '';
}
var query = searchArgs.substring(1);
var vars = query.split('&');
var varObj = {};
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
varObj[pair[0]] = pair[1];
}
return varObj;
}
// get uri query variable
function getQueryVariable(variable, uri) {
var vars = getQueryVariables(uri);
for (var key in vars) {
if (key === variable) return vars[key];
}
return (false);
}
// if value is null or undefined than execute delete operate, else execute update
function updateQueryVariable(uri, key, value) {
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
if (uri.match(re)) {
return uri.replace(re, !value ? '' : ('$1' + key + '=' + value + '$2'));
}
else {
return !value ? '' : (uri + separator + key + '=' + value);
}
}
// get uri template
function getUrlTemplate(uri) {
var reg = /\{(.+?)\}/g;
return uri.match(reg);
}
// hide empty tags
var HideEmptyTagsPlugin = function HideEmptyTagsPlugin() {
return {
statePlugins: {
spec: {
wrapSelectors: {
taggedOperations: function taggedOperations(ori) {
return function () {
return ori.apply(void 0, arguments).filter(function (tagMeta) {
return tagMeta.get("operations") && tagMeta.get("operations").size > 0;
});
};
}
}
}
}
};
};
var tokenKey = "access-token";
var cultureKey = "culture";
// default response interceptor
function defaultResponseInterceptor(response) {
// handle jwt token
var accessToken = response.headers[tokenKey];
if (accessToken && accessToken != "invalid_token") {
window.localStorage.setItem(tokenKey, accessToken);
ui.preauthorizeApiKey("Bearer", accessToken);
}
else if (accessToken == "invalid_token") {
window.localStorage.removeItem(tokenKey);
}
return response;
}
// default request interceptor
function defaultRequestInterceptor(request) {
var url = request.url;
// add swagger header
request.headers["request-from"] = "swagger";
// handle template
var temps = getUrlTemplate(url);
if (temps && temps.length > 0) {
for (var i = 0; i < temps.length; i++) {
var temp = temps[i];
var key = temp.substring(1, temp.length - 1);
var queryKey = getQueryVariable(key, url);
if (queryKey) {
url = updateQueryVariable(url.replace(temp, queryKey), key);
}
else url = url.replace(temp, '');
}
request.url = url;
}
// handle culture lang
var culture = getQueryVariable(cultureKey);
if (culture && culture.length > 0) {
request.url = updateQueryVariable(url, cultureKey, culture);
}
return request;
}
window.onload = function () {
var configObject = JSON.parse('%(ConfigObject)');
var oauthConfigObject = JSON.parse('%(OAuthConfigObject)');
configObject.onComplete = function () {
var accessToken = window.localStorage.getItem(tokenKey);
if (accessToken) {
ui.preauthorizeApiKey("Bearer", accessToken);
}
};
// Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
configObject.urls.forEach(function (item) {
if (item.url.startsWith("http") || item.url.startsWith("/")) return;
item.url = window.location.href.replace("index.html", item.url).split('#')[0];
});
// If validatorUrl is not explicitly provided, disable the feature by setting to null
if (!configObject.hasOwnProperty("validatorUrl"))
configObject.validatorUrl = null
// If oauth2RedirectUrl isn't specified, use the built-in default
if (!configObject.hasOwnProperty("oauth2RedirectUrl"))
configObject.oauth2RedirectUrl = window.location.href.replace("index.html", "oauth2-redirect.html").split('#')[0];
// Apply mandatory parameters
configObject.dom_id = "#swagger-ui";
configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset, HideEmptyTagsPlugin];
configObject.layout = "StandaloneLayout";
// Parse and add interceptor functions
var interceptors = JSON.parse('%(Interceptors)');
if (interceptors.RequestInterceptorFunction)
configObject.requestInterceptor = parseFunction(interceptors.RequestInterceptorFunction);
if (interceptors.ResponseInterceptorFunction)
configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction);
// Begin Swagger UI call region
const ui = SwaggerUIBundle(configObject);
ui.initOAuth(oauthConfigObject);
// End Swagger UI call region
window.ui = ui
}
</script>
</body>
</html>