簡體   English   中英

有沒有辦法在默認情況下以折疊模式呈現 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'
    }) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM