Try out option with Bearer token authorization

used the following swagger config with packages

  1. “swagger-autogen”: “^2.16.0”,
  2. “swagger-ui-express”: “^4.2.0”

did this in API project of the tadafuq

const options = { openapi: '3.0.0' };

const swaggerAutogen = require('swagger-autogen')(options)

const outputFile = './swagger.json'

// const endpointsFiles = [
//     "./routes/auth.js",
//     "./routes/categories.js",
//     "./routes/comments.js",
//     "./routes/docs.js",
//     "./routes/feelings.js",
//     "./routes/histories.js",
//     "./routes/replies.js",
//     "./routes/search.js",
//     "./routes/subscriptions.js",
//     "./routes/users.js",
//     "./routes/videos.js",
// ]

const endpointsFiles = ["./app.js"]

const doc = {
  info: {
    version: '',      // by default: '1.0.0'
    title: '',        // by default: 'REST API'
    description: '',  // by default: ''
  },
  host: 'localhost:3001',      // by default: 'localhost:3000'
  basePath: '',  // by default: '/'
  schemes: [],   // by default: ['http']
  consumes: [],  // by default: ['application/json']
  produces: [],  // by default: ['application/json']
  tags: [        // by default: empty Array
    {
      name: '',         // Tag name
      description: '',  // Tag description
    },
    // { ... }
  ],
  security: [{ bearerAuth: [] }],
  securityDefinitions: {
    bearerAuth: {
      type: 'http',
      scheme: 'bearer',
      bearerFormat: 'JWT'
    }
  },  // by default: empty object (Swagger 2.0)

  definitions: {},          // by default: empty object
  components: {}            // by default: empty object (OpenAPI 3.x)
};

swaggerAutogen(outputFile, endpointsFiles, doc).then(() => {
  require('./app')           // Your project's root file
})

This answer stackoverflow helped

Versions

Version 3 is renamed as ‘OpenAPI’, earlier versions were called ‘Swagger 1.0, 2.0’