代码拉取完成,页面将自动刷新
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.IO;
using zijian666.Core;
using zijian666.WebApi.SwaggerOptions;
namespace zijian666.WebApi
{
/// <summary>
/// WebApi选项组
/// </summary>
public partial class WebApiOptions
{
/// <summary>
/// 启用文档支持
/// </summary>
/// <param name="title">文档标题</param>
/// <param name="version">文档版本</param>
public void EnableSwaggerGen(string? title = null, string? version = "v1")
{
if (title is null)
{
title = AppDomain.CurrentDomain.FriendlyName;
}
if (version is null)
{
version = "v1";
}
_services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = title, Version = version });
options.OperationFilter<AuthorizeAttributeFilter>();
options.DocumentFilter<SupportMultipleMethodsFilter>();
foreach (var xml in Directory.EnumerateFiles(AppContext.BaseDirectory, "*.xml", SearchOption.AllDirectories))
{
try
{
options.IncludeXmlComments(xml, true);
}
catch (Exception ex)
{
ErrorReporter.Report(ex, this, xml);
}
}
foreach (var xml in Directory.EnumerateFiles(".", "*.xml", SearchOption.TopDirectoryOnly))
{
try
{
options.IncludeXmlComments(xml, true);
}
catch (Exception ex)
{
ErrorReporter.Report(ex, this, xml);
}
}
});
_services.ConfigureSwaggerGen(options => options.OperationFilter<SwaggerFormatResultFilter>());
AddConfigureHandler("swagger", app => {
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.DocumentTitle = $"{title} ApiDoc {version}";
c.SwaggerEndpoint("/swagger/v1/swagger.json", $"{title} {version}");
});
});
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。