【问题标题】:Is there a way to render Loopback 4 "/explorer" in collapsed mode by default有没有办法在默认情况下以折叠模式呈现 Loopback 4“/explorer”
【发布时间】:2021-07-17 14:11:03
【问题描述】:

我已经安装了 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);

有没有人能够做到这一点?论坛上似乎有很多这样的要求。

【问题讨论】:

    标签: node.js swagger-ui loopbackjs strongloop loopback4


    【解决方案1】:

    你可以试试这个。

    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'
        }) 
    

    【讨论】:

    • 好的,谢谢 - 我今晚会检查并报告
    • 它工作得很好——当你知道在哪里看时就这么简单——谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多