Swagger / Swashbuckle – 隐藏下拉菜单中可用值的预览

huangapple go评论82阅读模式
英文:

Swagger / Swashbucle - Hide Preview of Available Values of Dropdown

问题

I'm currently working with a webapi scenario where we're exposing a growing list of enum values for input. In the swagger these are displayed as a dropdown, which is perfect for selection.

然而,在Swagger中,下拉列表的值在按下“尝试”按钮之前会被“预览”为“可用值”。我想要移除这个预览,因为列表已经增长到一个让人不舒服的程度,但是我还没有找到任何设置来实现这个目标。

有没有人知道如何做到这一点,或者是否可能?我们正在使用标准的Swashbuckle/OpenAPI nugets来进行.NET5/6/7的开发。

英文:

I'm currently working with a webapi scenario where we're exposing a growing list of enum values for input. In the swagger these are displayed as a dropdown, which is perfect for selection.

However, in swagger the values of the dropdown are "previewed" before pressing the "Try it out"-button as "Available values:". I would like to remove this preview, as the list has grown to the point where it's jarring, but I haven't found any setting to do so.

Does anyone know how, or if, this is possible? We're using the standard Swashbuckle/OpenAPI nugets for .NET5/6/7

Swagger / Swashbuckle – 隐藏下拉菜单中可用值的预览

答案1

得分: 1

I'm not sure if this is the best option, but at least it can be a workaround. My idea is setting custom css for swagger UI. We can see the previewed values has class parameter__enum, so in my .net 6 web api project, I created wwwroot/swagger/Custom.css and used it in the API with

app.UseSwagger();
app.UseSwaggerUI(opts => {
opts.InjectStylesheet("/swagger/Custom.css");
});

...

app.UseStaticFiles();

Swagger / Swashbuckle – 隐藏下拉菜单中可用值的预览

英文:

I'm not sure if this is the best option, but at least it can be a workaround. My idea is setting custom css for swagger UI. We can see the previewed values has class parameter__enum, so in my .net 6 web api project, I created wwwroot/swagger/Custom.css and used it in the API with

app.UseSwagger();
app.UseSwaggerUI(opts => {
    opts.InjectStylesheet("/swagger/Custom.css");
});

...

app.UseStaticFiles();

Swagger / Swashbuckle – 隐藏下拉菜单中可用值的预览

huangapple
  • 本文由 发表于 2023年4月13日 16:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定