Base document

The document through which the specification can be seen.

Let's go to the main file and, before the app.listen() call, create the document for the specification. Here, we'll first set the config of the document.

const config = new DocumentBuilder()
  .setTitle('The Conrod Shop')
  .setDescription('Documentation for the shop API')
  .setVersion('1.0')
  .build();

Then, let's actually create the document, using the config and the app.

const document = SwaggerModule.createDocument(app, config);

Finally, let's expose the document and define a path for accessing it.

SwaggerModule.setup('api', app, document);

With just this, it is already available through the Swagger UI. We can then see it by accessing in the browser's URL, the root route followed by "api". If you give it a look, you'll notice that the routes and DTOs have been automatically detected and shown here. However, most information is missing. Let's then begin to fix this.

Commit - Creating a swagger base document

Last updated