英文:
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
答案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();
英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论