swagger调用路径临时修复
This commit is contained in:
parent
951c2caa05
commit
6d497109f5
@ -17,5 +17,9 @@ namespace Infrastructure
|
||||
/// 管理员角色
|
||||
/// </summary>
|
||||
public static string AdminRole = "admin";
|
||||
/// <summary>
|
||||
/// 开发版本API映射路径
|
||||
/// </summary>
|
||||
public static string DevApiProxy = "/dev-api/";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
@ -7,13 +8,40 @@ using Swashbuckle.AspNetCore.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
public static class SwaggerExtension
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
public static void UseSwagger(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseSwagger(c =>
|
||||
{
|
||||
c.RouteTemplate = "swagger/{documentName}/swagger.json";
|
||||
c.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
|
||||
{
|
||||
var url = $"{httpReq.Scheme}://{httpReq.Host.Value}";
|
||||
var referer = httpReq.Headers["Referer"].ToString();
|
||||
if (referer.Contains(GlobalConstant.DevApiProxy))
|
||||
url = referer.Substring(0,
|
||||
referer.IndexOf(GlobalConstant.DevApiProxy, StringComparison.InvariantCulture) + GlobalConstant.DevApiProxy.Length - 1);
|
||||
swaggerDoc.Servers =
|
||||
new List<OpenApiServer>
|
||||
{
|
||||
new OpenApiServer
|
||||
{
|
||||
Url = url
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "ZrAdmin v1"));
|
||||
}
|
||||
|
||||
public static void AddSwaggerConfig(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
@ -14,6 +14,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Framework;
|
||||
@ -93,9 +94,8 @@ namespace ZR.Admin.WebApi
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "ZrAdmin v1"));
|
||||
|
||||
app.UseSwagger();
|
||||
//使可以多次多去body内容
|
||||
app.Use((context, next) =>
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user