How do you configure a login form to the swagger-ui with Node/Expressjs

Viewed 873

I have integrated swagger to my Node.js app and it can be accessed by the route http://localhost:3000/api-docs but How can I make like a login form on the beginning of the page to authenticate the user and then make them see their request

Basically a login form kind of like this image below: enter image description here

I have searched the web but could not find an example for node.js but for .NET and spring

This is my swagger configuration file below:

const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('../swagger.json');

const options = {
    apis: ['../routes/index.js'],
    swaggerDefinition: swaggerDocument    
}
const specs = swaggerJsDoc(options);
module.exports = (app) => {
  // Serves Swagger API documentation to /api-docs url
  app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs, {
      explorer: true
  }));
}

And here is the inital setup inside my swagger.json file right before the paths

{
    "openapi": "3.0.0",
    "info": {
        "title": "REST API",
        "version": "1.0.0",
        "description": "Desc. REST API",
        "license": {
            "name": "MIT",
            "url": "https://choosealicense.com/licenses/mit/"
        }
    },
    "schema": [
        "http",
        "https"
    ],
    "servers": [
        {
            "url": "http://localhost:3000/"
        }
    ],
    "paths": {
    //rest of the paths...
    }
}
0 Answers
Related