Swagger UI:HTTP内容类型“ application / json”导致“无法加载SwaggerUI”。 [英] Swagger UI: HTTP Content-type "application/json" causes "Unable to Load SwaggerUI"

查看:124
本文介绍了Swagger UI:HTTP内容类型“ application / json”导致“无法加载SwaggerUI”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a very strange behaviour with Swagger UI v2.1.4:

当我从服务器返回带有HTTP Content-type标头的JSON文档时, text / html,在Swagger UI中一切正常。

When I return, from my server, my JSON document with the HTTP Content-type header "text/html", everything is fine in Swagger UI.

但是当我返回带有HTTP Content-type标头 application / json的JSON文档时, ,在控制台中收到无法加载SwaggerUI错误。

(然后在Swagger UI中,我遇到了常见的错误消息:可以 t从服务器读取。它可能没有适当的访问控制来源设置。。

(And then in Swagger UI I have the common error message: "Can't read from server. It may not have the appropriate access-control-origin settings.".)

我已经仔细检查了两个HTTP响应的所有详细信息(

I have carefully checked all the details of the two HTTP responses (the working one and the failing one), and that's the only difference.

遗憾的是,因为设置此 application / json内容类型有助于调试Swagger文件(因为它在直接访问时会正确显示在浏览器中。)

That's a pity since setting this "application/json" Content-type helps me debugging my Swagger file (because it is then displayed correctly in browsers when accessed directly).

有人对如何制作此 application / json续有想法吗? entagger类型与Swagger UI一起工作?

Does anyone have an idea about how to make this "application/json" Content-type work with Swagger UI?

推荐答案

我通过删除Content-type HTTP标头:这使我的浏览器和Swagger用户界面都感到高兴。但我不知道这是否是解决此问题的最正确方法……

I solved my issue by simply removing the Content-type HTTP header: it makes my browser and my Swagger UI both happy. But I don't know if this is the most correct way to solve this problem…

这篇关于Swagger UI:HTTP内容类型“ application / json”导致“无法加载SwaggerUI”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆