Swagger UI - "类型错误:无法获取"有效回应 [英] Swagger UI - " TypeError: Failed to fetch" on valid response
问题描述
我刚刚使用以下命令从 Git 存储库 (3.0.19) 中提取了最新的 Swagger:
以下是我对 403 响应的定义的一个片段:
"403": {"description": "禁止",标题":{访问控制允许来源":{类型":字符串"}}},
我也注意到它报告了
并且 400 按预期工作:
对于遇到此问题的任何人;
经过一天的故障排除和 Swagger 支持人员为我指出正确的方向后,事实证明这是目前由 AWS API Gateway 自定义授权方中的错误引起的.
我们目前使用 AWS API Gateway 来管理我们的 API,这包括通过自定义授权方管理我们的所有授权.问题是自定义授权方目前不支持在响应中传递标头,并且 Swagger UI 需要响应标头中的 Access-Control-Allow-Origin:*
以显示正确的 HTTP 状态代码.
请参阅有关此问题的 AWS 线程(已超过一年):
https://forums.aws.amazon.com/thread.jspa?messageID=728839
Swagger UI 讨论:https://github.com/swagger-api/swagger-ui/issues/3403
编辑/更新
此问题已通过使用网关响应解决.请参阅同一论坛(第 2 页):
https://forums.aws.amazon.com/thread.jspa?messageID=728839
I've just pulled down the latest Swagger from the Git repo (3.0.19) using: https://github.com/swagger-api/swagger-ui.git and updated my API to use the new version.
Ran git describe --tags
to confirm and my version is currently: v3.0.19-6-gaab1403
The problem I'm having is one described here, whereby my response is a 403 (I can see this in the inspector on the browser) and although I have a reponse for error 403, I still get the TypeError: Failed to fetch
message.
Here's a snippet from my definition regarding the 403 response:
"403": {
"description": "Forbidden",
"headers": {
"Access-Control-Allow-Origin": {
"type": "string"
}
}
},
I've also noticed it reported here however, I know it's not a CORS issue as I have tested the endpoints and the OPTIONS are returning correct, as are the endpoints if called with valid information (I force this 403).
Could anyone point me in the right direction please?
Update: I have since tested on a 401 response, with the same response.
And that a 400 is working as expected:
For anyone that runs into this problem;
After a day of troubleshooting and the Swagger support guys pointing me in the right direction, it turns out that this is currently caused by a bug within the AWS API Gateway custom authorizers.
We are currently using AWS API Gateway for managing our APIs, this includes managing all our authorization via a custom authorizer. The issue is that custom authorizers do not currently support passing through headers within the response and Swagger UI needs the Access-Control-Allow-Origin:*
within the response header(s) to display the correct HTTP status code.
See this AWS thread regarding the issue (which is older than a year already):
https://forums.aws.amazon.com/thread.jspa?messageID=728839
Swagger UI discussion on same: https://github.com/swagger-api/swagger-ui/issues/3403
EDIT / UPDATE
This has since been resolved with the use of Gateway Responses. See this same forum (page 2):
https://forums.aws.amazon.com/thread.jspa?messageID=728839
这篇关于Swagger UI - "类型错误:无法获取"有效回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!