[我在asp.core wep-api项目中配置了摇摇欲坠,它的工作正常。现在,当swagger-ui出现如下图时,我正在寻找解决方案
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.Versioning
和Microsoft.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;
});