问题描述
作为迁移的一部分,我已经安装了 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'
})