Browse Source

Merge pull request #21541 from abpframework/auto-merge/rel-9-0/3268

Merge branch dev with rel-9.0
pull/21543/head
maliming 1 year ago
committed by GitHub
parent
commit
b598c16f9a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      framework/src/Volo.Abp.Swashbuckle/Microsoft/AspNetCore/Builder/AbpSwaggerUIBuilderExtensions.cs
  2. 4
      framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/SwaggerHtmlResolver.cs
  3. 12
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js
  4. 75
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/index.js

1
framework/src/Volo.Abp.Swashbuckle/Microsoft/AspNetCore/Builder/AbpSwaggerUIBuilderExtensions.cs

@ -16,7 +16,6 @@ public static class AbpSwaggerUIBuilderExtensions
return app.UseSwaggerUI(options =>
{
options.InjectJavascript("ui/abp.js");
options.InjectJavascript("ui/abp.swagger.js");
options.IndexStream = () => resolver?.Resolver();
setupAction?.Invoke(options);

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

@ -10,12 +10,14 @@ public class SwaggerHtmlResolver : ISwaggerHtmlResolver, ITransientDependency
{
public virtual Stream Resolver()
{
var scriptBundleScript = "<script src=\"%(ScriptBundlePath)\" charset=\"utf-8\"></script>";
var abpSwaggerScript = "<script src=\"ui/abp.swagger.js\" charset=\"utf-8\"></script>";
var stream = typeof(SwaggerUIOptions).GetTypeInfo().Assembly
.GetManifestResourceStream("Swashbuckle.AspNetCore.SwaggerUI.index.html");
var html = new StreamReader(stream!)
.ReadToEnd()
.Replace("src=\"index.js\"", "src=\"ui/index.js\"");
.Replace(scriptBundleScript, $"{scriptBundleScript}\n{abpSwaggerScript}");
return new MemoryStream(Encoding.UTF8.GetBytes(html));
}

12
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

@ -1,9 +1,10 @@
var abp = abp || {};
(function () {
abp.SwaggerUIBundle = function (configObject) {
var oldSwaggerUIBundle = SwaggerUIBundle;
SwaggerUIBundle = function (configObject) {
var excludeUrl = ["swagger.json", "connect/token"]
var firstRequest = true;
var oidcSupportedFlows = configObject.oidcSupportedFlows || [];
@ -109,6 +110,9 @@ var abp = abp || {};
});
}
return SwaggerUIBundle(configObject);
return oldSwaggerUIBundle(configObject);
}
SwaggerUIBundle = Object.assign(SwaggerUIBundle, oldSwaggerUIBundle);
})();

75
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/index.js

@ -1,75 +0,0 @@
//Copy from https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerUI/index.js
/* 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();
}
window.onload = function () {
var configObject = JSON.parse('%(ConfigObject)');
var oauthConfigObject = JSON.parse('%(OAuthConfigObject)');
// 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 = (new URL("oauth2-redirect.html", window.location.href)).href;
// Apply mandatory parameters
configObject.dom_id = "#swagger-ui";
configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
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);
if (configObject.plugins) {
configObject.plugins = configObject.plugins.map(eval);
}
// Begin Swagger UI call region
const ui = abp.SwaggerUIBundle(configObject);
ui.initOAuth(oauthConfigObject);
// End Swagger UI call region
window.ui = ui
}
Loading…
Cancel
Save