2

I have made api documention with the help of swagger-editor. Now I want see it graphically with the help of swagger-ui. I have deployed my json here https://powerful-escarpment-92284.herokuapp.com/swagger.json

Now When I am trying to access it then I am getting an error

Failed to load spec.

enter image description here

N Sharma
  • 33,489
  • 95
  • 256
  • 444

4 Answers4

2

I solved this by setting this header in the response of swagger.json file.

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);
});
N Sharma
  • 33,489
  • 95
  • 256
  • 444
1

I was getting this error in a c# project, due to a problem with a controller I added. I could get more information by trying to browse to the swagger.json It turned out I was missing the routing attribute on a controller action.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
0

After many exercises for me apparently, it helped just to serve a file with flask server [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?

Datalker
  • 356
  • 3
  • 8
0

The URL is not shown, so I assume if you access the swagger directly via "index.html" or any other way, the URL format must be like this.

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

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

I hope, it helps :)