mirror of https://github.com/abpframework/abp.git
18 changed files with 156 additions and 25 deletions
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Swashbuckle.AspNetCore.SwaggerUI; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Swashbuckle; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Builder |
||||
|
{ |
||||
|
public static class AbpSwaggerUIBuilderExtensions |
||||
|
{ |
||||
|
public static IApplicationBuilder UseAbpSwaggerUI( |
||||
|
this IApplicationBuilder app, |
||||
|
Action<SwaggerUIOptions> setupAction = null) |
||||
|
{ |
||||
|
var resolver = app.ApplicationServices.GetService<ISwaggerHtmlResolver>(); |
||||
|
|
||||
|
return app.UseSwaggerUI(options => |
||||
|
{ |
||||
|
options.InjectJavascript("/libs/abp/core/abp.js"); |
||||
|
options.InjectJavascript("/swagger/ui/abp.swagger.js"); |
||||
|
options.IndexStream = () => resolver.Resolver(); |
||||
|
|
||||
|
setupAction?.Invoke(options); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Swashbuckle</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Swashbuckle</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.VirtualFileSystem\Volo.Abp.VirtualFileSystem.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Remove="wwwroot\swagger\ui\abp.swagger.js" /> |
||||
|
<EmbeddedResource Include="wwwroot\swagger\ui\abp.swagger.js" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,17 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace Volo.Abp.Swashbuckle |
||||
|
{ |
||||
|
[DependsOn(typeof(AbpVirtualFileSystemModule))] |
||||
|
public class AbpSwashbuckleModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpSwashbuckleModule>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System.IO; |
||||
|
|
||||
|
namespace Volo.Abp.Swashbuckle |
||||
|
{ |
||||
|
public interface ISwaggerHtmlResolver |
||||
|
{ |
||||
|
Stream Resolver(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System.IO; |
||||
|
using System.Reflection; |
||||
|
using System.Text; |
||||
|
using Swashbuckle.AspNetCore.SwaggerUI; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Swashbuckle |
||||
|
{ |
||||
|
public class SwaggerHtmlResolver : ISwaggerHtmlResolver, ITransientDependency |
||||
|
{ |
||||
|
public virtual Stream Resolver() |
||||
|
{ |
||||
|
var stream = typeof(SwaggerUIOptions).GetTypeInfo().Assembly |
||||
|
.GetManifestResourceStream("Swashbuckle.AspNetCore.SwaggerUI.index.html"); |
||||
|
|
||||
|
var html = new StreamReader(stream) |
||||
|
.ReadToEnd() |
||||
|
.Replace("SwaggerUIBundle(configObject)", "abp.SwaggerUIBundle(configObject)"); |
||||
|
|
||||
|
return new MemoryStream(Encoding.UTF8.GetBytes(html)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
var abp = abp || {}; |
||||
|
|
||||
|
(function () { |
||||
|
abp.SwaggerUIBundle = function (configObject) { |
||||
|
configObject.requestInterceptor = function (request) { |
||||
|
var token = abp.auth.getToken(); |
||||
|
request.headers.Authorization = token ? "Bearer " + token : null; |
||||
|
var antiForgeryToken = abp.security.antiForgery.getToken(); |
||||
|
if (antiForgeryToken) { |
||||
|
request.headers[abp.security.antiForgery.tokenHeaderName] = antiForgeryToken; |
||||
|
} |
||||
|
return request; |
||||
|
}; |
||||
|
|
||||
|
return SwaggerUIBundle(configObject); |
||||
|
} |
||||
|
})(); |
||||
Loading…
Reference in new issue