How to generate openapi doc in express

I’m making a REST service using javascript and express. I have some endpoints and I wanna create a swagger file to serve along with it. I’m using swagger-autogen to generate the swagger file. Even though it does a decent job, the schemas part is the main problem.

I have various models in my service and I wanna autogenerate the schemas part of the swagger file. I’m also using JSDoc and have documented with Types every model and their properties.

From my understanding I will have to create the schemas part by using JSDoc and then use that in order to have the schemas part. The problem is that if I have to go and create “by hand” the swagger definition of each model, might as well create the file myself.

Here is the current swagger.js file that I use to create the swagger file.

const swaggerAutogen = require('swagger-autogen')({openapi: '3.0.0'});

const doc = {
  info: {
    version: '1.0.0',
    title: 'Bookstore REST API',
    description: 'REST API documentation for bookstore app.'
  },
  servers: [
    {
      url: 'http://localhost:3000'
    },
  ],
  consumes: ['application/json'],
  produces: ['application/json'],
  tags: [
    {
      name: 'Bookstore', 
      description: ''
    },
  ],
  components: {}
};


const outputFile = './swagger-output.json';

// I only have one route file.
const routes = ['../routes/routes.js'];

swaggerAutogen(outputFile, routes, doc);

I have also tried swagger-jsdoc but I have the same problem there too. Does anyone know how to auto generate the entire swagger file?