Swagger JWT 定义失败
当我为 .Net Core 6 配置 swagger 时,我遇到了问题。
我收到下一条错误消息:
“SwaggerUIOptions”不包含“AddSecurityDefinition”的定义,并且扩展方法“SwaggerGenOptionsExtensions.AddSecurityDefinition(SwaggerGenOptions, string, OpenApiSecurityScheme)”的最佳重载需要“SwaggerGenOptions”类型的接收器
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My service");
c.RoutePrefix = string.Empty;
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header
});
});
我将第二个参数添加为 null 并失败反正。
怎么了?
I am having problems in swagger when I configure it for .Net Core 6.
I am getting next error message:
'SwaggerUIOptions' does not contain a definition for 'AddSecurityDefinition' and the best overload of the extension method 'SwaggerGenOptionsExtensions.AddSecurityDefinition(SwaggerGenOptions, string, OpenApiSecurityScheme)' requires a receiver of type 'SwaggerGenOptions'
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My service");
c.RoutePrefix = string.Empty;
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header
});
});
I am adding the second parameter as null and fails anyway.
What is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AddSecurityDefinition 应该在 AddSwaggerGen 中完成
AddSecurityDefinition is should be done in AddSwaggerGen