When starting blank key keys in swagger. Local works

I use swagger-jsdoc. Everything seems fine, and I get json until I use it localhost, when I use a live URL, it gives me nothing in the path keys, i.e.

{
    "info": {
        "title": "App API",
        "version":"0.0.0",
        "description":"Server API documentation"
    },
    "host":"something.com",
    "basePath":"/",
    "schemes":["https"],
    "swagger":"2.0",
    "paths":{},
    "definitions":{},
    "responses":{},
    "parameters":{},
    "securityDefinitions":{},
    "tags":[]
}

This is what I get live. The same code works with localhost/swagger.json, but not withhttps://something.com/swagger.json

var swaggerJSDoc = require('swagger-jsdoc');

var swaggerOptions = {
    swaggerDefinition: config.swaggerDefinition || {
        info: { // API informations (required)
            title: 'Hello World', // Title (required)
            version: '1.0.0', // Version (required)
            description: 'A sample API', // Description (optional)
        },
        host: 'localhost:3000', // Host (optional)
        basePath: '/', // Base path (optional)
    },
    apis: ['./routes/*.js'], // Path to the API docs
};

var swaggerSpec = swaggerJSDoc(swaggerOptions);

router.get('/swagger.json', function(req, res) {
  res.setHeader('Content-Type', 'application/json');
  res.send(swaggerSpec);
});
+4
source share
2 answers

The problem may be the problem with your host option config.swaggerDefinition. Is it installed in the correct domain?

+1
source

I had the same problem before. If you use pm2, you may have the same problem as mine.

, paths apis

apis: [ './routes/*.js' ]

apis: [ __dirname + 'routes/*.js' ]

, __dirname .

!

0

Source: https://habr.com/ru/post/1685472/


All Articles