Skip to content

Commit ed303db

Browse files
authored
Merge pull request #21452 from abpframework/auto-merge/rel-9-0/3240
Merge branch dev with rel-9.0
2 parents 1994a26 + f367b6a commit ed303db

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/SwaggerHtmlResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public virtual Stream Resolver()
1515

1616
var html = new StreamReader(stream!)
1717
.ReadToEnd()
18-
.Replace("SwaggerUIBundle(configObject)", "abp.SwaggerUIBundle(configObject)");
18+
.Replace("src=\"index.js\"", "src=\"ui/index.js\"");
1919

2020
return new MemoryStream(Encoding.UTF8.GetBytes(html));
2121
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//Copy from https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerUI/index.js
2+
3+
/* Source: https://gist.github.com/lamberta/3768814
4+
* Parse a string function definition and return a function object. Does not use eval.
5+
* @param {string} str
6+
* @return {function}
7+
*
8+
* Example:
9+
* var f = function (x, y) { return x * y; };
10+
* var g = parseFunction(f.toString());
11+
* g(33, 3); //=> 99
12+
*/
13+
function parseFunction(str) {
14+
if (!str) return void (0);
15+
16+
var fn_body_idx = str.indexOf('{'),
17+
fn_body = str.substring(fn_body_idx + 1, str.lastIndexOf('}')),
18+
fn_declare = str.substring(0, fn_body_idx),
19+
fn_params = fn_declare.substring(fn_declare.indexOf('(') + 1, fn_declare.lastIndexOf(')')),
20+
args = fn_params.split(',');
21+
22+
args.push(fn_body);
23+
24+
function Fn() {
25+
return Function.apply(this, args);
26+
}
27+
Fn.prototype = Function.prototype;
28+
29+
return new Fn();
30+
}
31+
32+
window.onload = function () {
33+
var configObject = JSON.parse('%(ConfigObject)');
34+
var oauthConfigObject = JSON.parse('%(OAuthConfigObject)');
35+
36+
// Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
37+
configObject.urls.forEach(function (item) {
38+
if (item.url.startsWith("http") || item.url.startsWith("/")) return;
39+
item.url = window.location.href.replace("index.html", item.url).split('#')[0];
40+
});
41+
42+
// If validatorUrl is not explicitly provided, disable the feature by setting to null
43+
if (!configObject.hasOwnProperty("validatorUrl"))
44+
configObject.validatorUrl = null
45+
46+
// If oauth2RedirectUrl isn't specified, use the built-in default
47+
if (!configObject.hasOwnProperty("oauth2RedirectUrl"))
48+
configObject.oauth2RedirectUrl = (new URL("oauth2-redirect.html", window.location.href)).href;
49+
50+
// Apply mandatory parameters
51+
configObject.dom_id = "#swagger-ui";
52+
configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
53+
configObject.layout = "StandaloneLayout";
54+
55+
// Parse and add interceptor functions
56+
var interceptors = JSON.parse('%(Interceptors)');
57+
if (interceptors.RequestInterceptorFunction)
58+
configObject.requestInterceptor = parseFunction(interceptors.RequestInterceptorFunction);
59+
if (interceptors.ResponseInterceptorFunction)
60+
configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction);
61+
62+
if (configObject.plugins) {
63+
configObject.plugins = configObject.plugins.map(eval);
64+
}
65+
66+
// Begin Swagger UI call region
67+
68+
const ui = abp.SwaggerUIBundle(configObject);
69+
70+
ui.initOAuth(oauthConfigObject);
71+
72+
// End Swagger UI call region
73+
74+
window.ui = ui
75+
}

0 commit comments

Comments
 (0)