File name suffixes

File extensions that are detected by Swagger.

Let's now open, in the Swagger UI, the route to find all users. In schema, we can notice that the registryDates was not automatically detected, or at least not its fields. This happened because the Swagger plugin, by default, only detects files that end with .dto or .entity. To fix this, we should override the plugin's default behavior.

So, back in the nest-cli.json file, we can replace the simplified definition of the plugin:

"plugins": ["@nestjs/swagger"]

With the complete definition, which receives both the name and the options.

"plugins": [
  {
    "name": "@nestjs/swagger",
    "options": {
      "dtoFileNameSuffix": [
        ".dto.ts",
        ".entity.ts",
        ".embedded.ts",
        ".schema.ts"
      ]
    }
  }
]

Through the option dtoFileNameSuffix, we define what file types Swagger should analyse. We use the default extensions already mentioned, plus .embedded: the extension of the RegistryDates. The .schema extension that was also added will be used in the future.

After restarting the application and refreshing the Swagger UI, we can then see that the registryDates was correctly detected now.

Commit - Enabling additional file suffixes

Last updated