首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在默认情况下以折叠模式呈现Loopback4“/explorer

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

Stack Overflow用户
提问于 2021-04-23 18:58:12
回答 1查看 116关注 0票数 1

作为迁移的一部分,我已经安装了Loopback4,并将遗留的Loopback3应用程序挂载到其中-到目前为止一切正常。

然而,我的(swagger-ui形状)浏览器的渲染默认是展开的--而且有很多端点和服务--这使得我很难找到我想要的东西。

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

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-01 18:27:34

你可以试试这个。

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添加到您的项目中,然后更新配置:

代码语言:javascript
复制
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'),
});

然后,您可以添加

代码语言:javascript
复制
docExpansion: 'none',

在index.html.ejs文件中。

代码语言:javascript
复制
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'
    }) 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67228756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档