nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The fields of DTO do not appear in Swagger UI when using CLI.

Alivers opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

With the following codes, the swagger docs don't work as expected.

--- user.dto.ts ---
export class GetUserDto {
  /**
   * The unique id of the user.
   * @example "1234"
   */
  userId: string;
}

--- user.controller.ts ---
@Controller('user')
export class UserController {
  @Post('get')
  async getUser(@Body() param: GetUserDto) {
    return { userId: 'test' };
  }
}

--- nest-cli.json ---
{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "generateOptions": {
    "spec": false
  },
  "compilerOptions": {
    "plugins": [
      {
        "name": "@nestjs/swagger",
        "options": {
          "classValidatorShim": true,
          "introspectComments": true
        }
      }
    ]
  }
}
image

Minimum reproduction code

https://github.com/Alivers/nestjs-template

Steps to reproduce

  1. pnpm install
  2. pnpm start:dev

Expected behavior

Show correct fields and descriptions based on the comments on Swagger UI

Package version

7.3.1

NestJS version

10.3.2

Node.js version

20.11.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

After changing the repo to standard(non-monorepo), It works as expected.