gpt4 book ai didi

c# - swagger-ui 中默认的 api 版本值

转载 作者:行者123 更新时间:2023-12-01 23:51:06 24 4
gpt4 key购买 nike

我在我们的 asp.core wep-api 中配置了 swagger项目及其工作完美。现在我正在寻找解决方案 swagger-ui出现如下图所示

/image/WFVxw.jpg

api版本部分应该根据代码端的配置自动填充。

        services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "My API",
Contact = new Contact
{
Name = "My Api",
Url = "https://109.com/"
}
});
var security = new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
};
c.AddSecurityDefinition("Bearer", new ApiKeyScheme
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = "header",
Type = "apiKey"
});
c.AddSecurityRequirement(security);
});

最佳答案

您需要安装 Microsoft.AspNetCore.Mvc.VersioningMicrosoft.AspNetCore.Mvc.Versioning.ApiExplorer 软件包才能在 Swagger 中启用 API 版本控制。

您可以在 here 查看更多详细信息.

ConfigureServices方法中将版本控制方案定义为

 services.AddVersionedApiExplorer(o =>
{
o.GroupNameFormat = "'v'VVV";
o.SubstituteApiVersionInUrl = true;
});
services.AddApiVersioning(config =>
{
config.DefaultApiVersion = new ApiVersion(1, 0);
config.AssumeDefaultVersionWhenUnspecified = true;
config.ReportApiVersions = true;
});

关于c# - swagger-ui 中默认的 api 版本值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58601931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com