Comments introspection

Automatic documentation through comments.

As was already explained before, it is a nice practice to use good naming conventions in order to avoid unnecessary comments. However, it would be adequate to explain that the user password should follow the rules defined previously. Due to this, let's add a description to it in the CreateUserDto through a JSDoc, which we are already familiar with.

/**
 * Requires:
 * 1. 8 to 20 characters
 * 2. At least one
 * - Lowercase letter
 * - Uppercase letter
 * - Number
 * - Special character
 */

There are two interesting options available in the Swagger plugin, they are:

  • classValidatorShim - class validator decorators are used to enrich the documentation

  • introspectComments - descriptions and examples are generated from comments

The first option is enabled by default, but not the second one. So, let's enable it now.

"introspectComments": true

After restarting the application and refreshing the Swagger UI, we can notice the changes.

Commit - Using comment to describe a field in swagger

Last updated