I have defined the swagger.ts as below:
import swaggerJSDoc from "swagger-jsdoc";
import { version } from '../package.json';
const options: swaggerJSDoc.Options = {
definition: {
openapi: "3.0.0",
info: {
title: "abc project",
version
}
},
apis: ["./routes/rootRouter.ts"]
};
export default options;
and i'm trying to document the api is below:
/**
* @openapi
* /isAlive:
* get:
* tags:
* - Healthcheck
* description: Responds if the app is up and running
* responses:
* 200:
* description: App is up and running
*/
router.get('/abc.json', (req, res) => {
res.send({
'name' : 'sdf',
'org' : 'sdf',
'rev': 'local'
});
});
I have done the necessary coding in app.ts. But when the server starts it displays the swagger page but doesn't display the apis documented. Anybody have faced the same issues?
I had the same issue, just change the apis array to be like this:
Source: https://github.com/Surnet/swagger-jsdoc/issues/150
BONUS:
With this fix you can probably have some issues on the prod environment since once the project is delivered to prod, it goes without
*.ts
files and swagger will not find any endpoint.A solution for this problem could be to use something like this: