Swagger ui 未加载 Swagger api json

Swagger ui is not loading swagger api json

我在 swagger-editor 的帮助下制作了 api 文档。现在我想在 swagger-ui 的帮助下以图形方式查看它。我已经在 https://powerful-escarpment-92284.herokuapp.com/swagger.json

部署了我的 json

现在,当我尝试访问它时出现错误

Failed to load spec.

我通过在 swagger.json 文件的响应中设置这个 header 解决了这个问题。

app.get('/:file(*)', function(req, res, next){
    var file = req.params.file, path = __dirname + '/' + file;

    console.log('.');
    res.header('Access-Control-Allow-Origin', '*');

    res.download(path);
});

显然,经过对我的多次练习后,仅使用 flask 服务器提供文件就很有帮助 [How to serve static files in Flask. and (important) add "?" to the end of the url, i.e. http://127.0.0.1/js/swagger.json?

由于我添加的控制器出现问题,我在 C# 项目中遇到了这个错误。 我可以尝试浏览 swagger.json 以获得更多信息 原来我在控制器操作上缺少路由属性。

没有显示URL,所以我假设如果您直接通过"index.html"或任何其他方式访问swagger,URL格式必须是这样的。

http://<host>:<port>/<project_name>/_swagger-ui/index.html?url=http://<host>:<port>/<project_name>/<path>/swagger.json

喜欢: http://localhost:8080/counter/_swagger-ui/index.html?url=http://localhost:8080/counter/webapi/swagger.json

希望对你有所帮助:)