Skip to content

Instantly share code, notes, and snippets.

@bombadillo
Created June 10, 2020 12:59
Show Gist options
  • Save bombadillo/c272c52af7ace6305d146b13b3322f22 to your computer and use it in GitHub Desktop.
Save bombadillo/c272c52af7ace6305d146b13b3322f22 to your computer and use it in GitHub Desktop.
Add swagger to a Nest.js app

Required Packages

  • @nestjs/swagger
  • swagger-ui-express

Setup

Import the following:

import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

Add the following to the bootstrap function in main.ts:

  const options = new DocumentBuilder()
    .setTitle('My API')
    .setDescription('The My API description')
    .setVersion('1.0')
    .addTag('myApi')
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup(`api`, app, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment