Search code examples
javanode.jsswaggerswagger-uiswagger-editor

Swagger ui is not loading swagger api json


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


Solution

  • 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);
    });