有没有办法在默认情况下以折叠模式呈现 Loopback 4“/explorer”

Is there a way to render Loopback 4 "/explorer" in collapsed mode by default

我已经安装了 Loopback 4,并将我的旧版 Loopback 3 应用安装到其中作为迁移的一部分 - 到目前为止一切正常。

但是我的(swagger-ui 形)资源管理器在默认情况下呈现扩展 - 并且有很多端点和服务 - 很难找到我正在寻找的东西。

我的直觉告诉我,我应该可以在我的 application.ts 中添加配置 - 但我找不到任何东西。

    this.configure(RestExplorerBindings.COMPONENT).to({
      path: '/explorer',
      docExpansion:'none'    <<<<< this is what I would expect/like
    });
    this.component(RestExplorerComponent);

有没有人能做到这一点?从论坛上看好像有很多这样的请求。

你可以试试这个。

https://www.npmjs.com/package/@loopback/rest-explorer

超越 Swagger UI index.html 为了获得更大的灵活性,indexTemplatePath 属性 可用于允许完全自定义 Swagger UI 配置选项。

indexTemplatePath 应该是 html.ejs 模板的绝对路径。

要开始,请下载默认 index.html.ejs, 将 /explorer/index.html.ejs 添加到您的项目,并更新配置:

this.configure(RestExplorerBindings.COMPONENT).to({
    // For example, create a directory "explorer" at the same level
    // as "src" and "node_modules" in your applciation structure
    indexTemplatePath: path.resolve(__dirname, '../explorer/index.html.ejs'),
});

然后您可以添加

docExpansion: 'none',

在 index.html.ejs 文件中。

const ui = SwaggerUIBundle({
    url: '<%- openApiSpecUrl %>',
    dom_id: '#swagger-ui',
    deepLinking: true,
    filter: true,
    docExpansion: 'none',
    defaultModelsExpandDepth: 0,
    defaultModelExpandDepth: 0,
    presets: [
        SwaggerUIBundle.presets.apis,
        // SwaggerUIStandalonePreset
        SwaggerUIStandalonePreset.slice(1) // Disable the top bar
    ],
    plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: 'StandaloneLayout'
    })