Nodejs, Express + Swagger

Asked

Viewed 251 times

0

Hello, folks I was tasked with a mission to implement Swagger in an express application, with the purpose of generating Swagger.json for the AWS apigateway deploy.

I have tried using swaggerJSDoc, Swagger-ui-Node... among others.

The closest I came to my goal with the swaggerJSDoc, only for it to work I need to add several Annotations on the routes, like this:

  /**
 * @swagger
 * /add:
 *   post:
 *     summary: Add more animal
 *     description: Add animals to the list
 *     tags:
 *       - animals
  *     requestBody:
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               animals:
 *                 type: array
 *                 items:
 *                   type: string
 *     responses:
 *       200:
 *         description: Adds the animals in body
 *         schema:
 *           type: object
 *           properties:
 *             message:
 *               type: string
 *               default: 'Added'
 */
     app.post('/add', (req, res) => {
      // ...
     });

Is there any way to generate these Annotations automatically, so you don’t have to do everything in the nail? Or some other way to create this Swagger.json from the Routes, without having to write these Annotations?

{
"swagger": "2.0",
"info": {
    "version": "2018-09-25T20:57:59Z",
    "title": "swagger.json"
},
"host": "localhost",
"basePath": "/",
"schemes": [
    "https"
],
"paths": { }
}
  • There is an extension for vscode whose name I don’t remember now. But that exists, exists, I’ve used.

  • Codewind Openapi Tools ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.