我正在使用swagger-jsdoc.一切似乎很好,我得到了json,直到我使用localhost,当我使用实时网址时,它在路径键中没有给我任何东西,即.
{
"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":[]
}
这就是我的现场直播.相同的代码正在使用localhost / swagger.json,但不适用于https://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);
});
最佳答案 问题可能是config.swaggerDefinition中的主机选项出现问题.它是否设置为正确的域?