Swagger UI:HTTP Content-type "application/json" 导致 "Unable to Load SwaggerUI"

Swagger UI: HTTP Content-type "application/json" causes "Unable to Load SwaggerUI"

我对 Swagger UI v2.1.4 有一个非常奇怪的行为:

当我 return,从我的服务器,我的 JSON 文档与 HTTP Content-type header "text/html",在 Swagger 中一切正常 UI.

但是当我 return 与 HTTP Content-type header "application/json" 相同的 JSON 文档时,我得到一个 "Unable to Load SwaggerUI" 控制台错误。

(然后在 Swagger UI 中出现常见错误消息:"Can't read from server. It may not have the appropriate access-control-origin settings."。)

我已经仔细检查了两个 HTTP 响应(工作响应和失败响应)的所有详细信息,这是唯一的区别。

很遗憾,因为设置此 "application/json" Content-type 有助于我调试我的 Swagger 文件(因为当直接访问时它会在浏览器中正确显示)。

有没有人知道如何使这个 "application/json" Content-type 与 Swagger UI 一起工作?

我通过简单地 删除 Content-type HTTP header 解决了我的问题:它让我的浏览器和我的 Swagger UI 都很开心。但是我不知道这是不是解决这个问题最正确的方法...