簡體   English   中英

Swagger ui 無法在服務器中加載 json 規范文件

[英]Swagger ui is unable to load the json specification file in server

我有 swagger ui 和一個開放的 api 規范 3.0 json 文件。 當我從本地 iis 運行 index.html 文件時,它會顯示帶有文檔的 swagger ui。 但是當我從服務器運行它時,它拋出無法讀取文件錯誤。 index.html 有 json 文件的相對路徑。

window.onload = function() {

  // Build a system
    const ui = SwaggerUIBundle({
        urls: [
            {
                url: "../OASDoc/v1_apidoc.json",
                name:"Version 1.0.0"
            }
              ],
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}

在此處輸入圖片說明

我試圖從 URL (xxxx.xxxx.com/appFolder/OASDoc/v1_apidoc.json) 訪問 api JSON 文檔文件,但它無法訪問,但所有其他文件(如文本文件)都可以訪問。 我認為這是因為文件擴展名。 為了覆蓋限制,我將下面的 mime 類型映射添加到 web.config 文件並且它起作用了。

<system.webServer> 
  <staticContent> 
    <mimeMap fileExtension=".json" mimeType="application/json"/> 
  </staticContent> 
</system.webServer>

暫無
暫無

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

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