如何在 Swagger UI 中隐藏模型部分?

020*_*402 15 swagger-ui

我使用Swagger UI来显示 API 文档。默认情况下,它会在底部显示“模型”部分:

在此处输入图片说明

如何隐藏它?

Hel*_*len 17

要隐藏“模型”部分,请添加defaultModelsExpandDepth: -1index.html.

请注意,选项名称使用复数Model*s*not Model

// index.html

<script>
window.onload = function() {
  // Begin Swagger UI call region
  const ui = SwaggerUIBundle({
    url: "https://petstore.swagger.io/v2/swagger.json",
    dom_id: '#swagger-ui',
    defaultModelsExpandDepth: -1,   // <-------
Run Code Online (Sandbox Code Playgroud)

Swagger UI 还具有许多其他配置选项,用于控制 API 文档呈现。


小智 6

对于 .Net Core 3.0 只需添加 c.DefaultModelsExpandDepth(-1); 在您的 Startup.cs 上

// Startup.cs

app.UseSwaggerUI(c =>
{
    c.DefaultModelsExpandDepth(-1); // Disable swagger schemas at bottom
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Your API V1");
});
Run Code Online (Sandbox Code Playgroud)


小智 5

在 Docket bean 中添加新的

Docket(DocumentationType.SWAGGER_2).ignoredParameterTypes(YourClass.class,YourAnother.class)

我希望它有帮助