我正在尝试将安全方案添加到我的招摇UI页面,并且成功添加了该安全方案,但是,我的描述没有呈现或完全不在UI页面上显示。我希望它能成功显示,因为我会将这段代码切换为IOperationFilter,并且描述因端点而异。但是,现在,这是我的AddSwaggerGen代码:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "MyAPI",
Version = "v1"
});
options.EnableAnnotations(true);
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Description = "This is my description that's not showing", // I want this to display on the UI
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
ClientCredentials = new OpenApiOAuthFlow
{
TokenUrl = new Uri("/token", UriKind.Relative)
}
}
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
Scheme = "oauth2",
Name = "Bearer",
In = ParameterLocation.Header
},
new List<string>()
}
});
});
我以为我的描述应该像JWT那样去描述范围。我是否缺少配置?我正在使用Swashbuckle.AspNetCore 5.0.0
这是Swagger UI的已知问题: