Swagger-无法渲染此组件,请参阅控制台

发布于 2025-02-04 20:31:22 字数 1125 浏览 0 评论 0 原文

我正在尝试为Swagger设置 SecurityDefinition 。不幸的是,当我运行应用程序时,我会遇到一个错误,说它“无法渲染此组件,请参阅控制台”,“授权”按钮应该在哪里。

关于这个问题有很多帖子,但是我还没有找到任何解决问题的信息。奇怪的部分是它似乎已连接到 SecuritySchemeType 。因为此代码实际上渲染了按钮(但由于错误的类型,它实际上无法授权):

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
    Type = SecuritySchemeType.Http,
    In = ParameterLocation.Header,
    Scheme = "Bearer"
});

这正确呈现“授权”按钮:

png“ rel =” nofollow noreferrer“> oauth2 虽然...

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
    Type = SecuritySchemeType.OAuth2, // Now the button does not render anymore
    In = ParameterLocation.Header,
    Scheme = "Bearer"
});

...现在给出以下错误:

< img src =“ https://i.sstatic.net/hypru.png” alt =“错误消息的屏幕截图“无法渲染此组件,请参见console&quort&quort&quort&quort;>

SecuritySchemeType 会影响“身份验证”按钮的渲染?我该怎么做才能解决?

I am trying to set up a SecurityDefinition for Swagger. Unfortunately, when I run my app, I get an error, saying that it "Could no render this component, see the console", where the "Authorize" button should be.

There are quite a few posts on this issue, but I haven't found any which solved the problem for me. The odd part is that it seems to be connected to the SecuritySchemeType. Because this code actually renders the button (but it won't actually authorize, due to being the wrong type):

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
    Type = SecuritySchemeType.Http,
    In = ParameterLocation.Header,
    Scheme = "Bearer"
});

This correctly renders the "Authorize" button:

Screenshot of the "Authorize" button.

If I change it to OAuth2 though...

options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
    Type = SecuritySchemeType.OAuth2, // Now the button does not render anymore
    In = ParameterLocation.Header,
    Scheme = "Bearer"
});

...now it gives the following error:

Screenshot of the error message "Could no render this component, see the console".

How does the SecuritySchemeType affect the rendering of the "Authenticate" button? And what can I do to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文