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。但是当我从服务器 运行 它抛出 can't read the file 错误。 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>