已被标记为已弃用。 Aspnetcore中的API贬值是描述的。 我的期望是有一个图标或标签,该标记在API组名称旁边显示“过时”或“弃用”。 在旁注:
swashbuckle swagger aspnet.core github项目问题跟踪器建议在So.上打开功能请求。 Edit:
使用apiversion属性将整个控制器标记为弃用。如果将控制器标记为[已过时],则所有方法都是灰色的,并且文本被击中。但是,这不是我想要的。我不想标记我的代码库[过时]。我想将特定的API版本标记为弃用,以便人们知道他们应该切换到较新的版本。 [ApiVersion("1", Deprecated = true)]
[Route("v{version:apiVersion}/[controller]")]
[Authorize("my.auth.policy")]
[ApiController]
public class MyApiController
{
// do stuff
}
app.UseSwagger();
app.UseSwaggerUI(options =>
{
foreach (ApiVersionDescription apiVersionDescription in apiVersionDescriptionProvider.ApiVersionDescriptions.OrderByDescending(a => a.ApiVersion))
{
string isDeprecated = apiVersionDescription.IsDeprecated ? " (DEPRECATED)" : string.Empty;
options.SwaggerEndpoint($"{Configuration["PathBase"]}/swagger/{apiVersionDescription.GroupName}/swagger.json",
$"{apiVersionDescription.GroupName.ToUpperInvariant()}{isDeprecated}");
}
});
@helen定义
builder.Services.AddSwaggerGen(g =>
{
g.OperationFilter<CustomHeaderFilter>();
}).AddSwaggerGenNewtonsoftSupport();
[ApiVersion("1.0", Deprecated = true)]
public class WeatherForecastController : ControllerBase