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 a document of 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 create a documentFactory, using the config and the app.

const documentFactory = () => SwaggerModule.createDocument(app, config);

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

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

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 are shown here. However, most information is missing. Let's then begin to fix this.

Commit - Creating a swagger base document

Last updated