Setup

Installation

To start using it, we first need to install the following dependencies:

npm i @nestjs/swagger
npm i swagger-ui-express

In the src/main.ts file you need to add the following configuration:

const appName = process.env.APP_NAME || 'Backend API';
const options = new DocumentBuilder()
  .setTitle(appName)
  .setVersion('1.0')
  .addBearerAuth({ in: 'header', type: 'http' })
  .build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('/', app, document, { customSiteTitle: appName });

In this configuration you can change the name of the application, the version of the API, and you can indicate what type of authentication you will use.

Last updated