[英]Swagger Authorization Header not visible in ASP.NET Core project
I have included the swagger package( Swashbuckle.AspNetCore ) for my asp.net core project. 我为我的asp.net核心项目包括了swagger软件包( Swashbuckle.AspNetCore )。 The swagger package is of latest 4.0.1 version.
swagger软件包是最新的4.0.1版本。 I tried to enable the Authorize button in the swagger ui using below code:
我尝试使用以下代码在swagger ui中启用“授权”按钮:
// Register the Swagger generator
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Sample API", Description = "Swagger Sample API", Version = "v1" });
c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please Enter Authentication Token", Name = "Authorization", Type = "SampleApiKey" });
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> {
{ "Bearer", Enumerable.Empty<string>() },
});
});
The button can be visible in the swagger ui but when i clicked the button, it shows below error: 该按钮在swagger ui中可见,但是当我单击该按钮时,它显示以下错误:
Can anyone point me out what's the problem here? 谁能指出我的问题在哪里?
Your line should be: 您的行应为:
c.AddSecurityDefinition("Bearer", new ApiKeyScheme {
In = "header",
Description = "Please Enter Authentication Token",
Name = "Authorization", Type = "apiKey"
});
as Type is being transformed inside Swashbuckle as strategy pattern. 因为Type正在Swashbuckle内部转换为策略模式。 Possible values are:
可能的值为:
Possibly you can file a bug inside Swashbuckle repo , cos unless it can be overriden it could be for instance an enum, to not bring confusion. 可能您可以在Swashbuckle repo内提交错误,因为除非可以覆盖它,否则它可以是例如enum,以免引起混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.