Skip to content

Conversation

@hyeonss0417
Copy link
Contributor

Summary

Fixes #91

When using NestJS with @Query() decorator and a DTO class (without field name argument), the DTO properties are now properly expanded into individual OpenAPI query parameters with their JSDoc annotations.

Problem

Previously, when using @Query() with a DTO class like:

@Get()
async findAll(@Query() query: ListFoodQueryDto): Promise<PaginatedResponse<FoodDto>> {
  // ...
}

The generated OpenAPI spec would have a single query parameter with an empty schema:

{
  "parameters": [
    { "name": "query", "in": "query", "required": true, "schema": {} }
  ]
}

Solution

Now each DTO property is expanded into individual query parameters with proper types and JSDoc annotations:

{
  "parameters": [
    {
      "name": "nextToken",
      "in": "query",
      "required": false,
      "schema": { "type": "string" },
      "example": "eyJvZmZzZXQiOjAsImxpbWl0IjoyMH0="
    },
    {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": { "type": "number", "minimum": 1, "maximum": 100, "default": 20 }
    },
    {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": { "type": "number", "minimum": 0, "default": 0 }
    },
    {
      "name": "name",
      "in": "query",
      "required": false,
      "schema": { "type": "string" },
      "example": "홍길동"
    }
  ]
}

Changes

  • types.ts: Add isDto flag to NestParameterMetadata to identify DTO query parameters
  • parser.ts: Mark @Query() without field name argument as DTO (isDto: true)
  • openapiGenerator.ts: Add buildPropertySchema function and expand DTO properties into individual query parameters with JSDoc annotations (@example, @minimum, @maximum, @default, etc.)
  • Tests: Add test cases for @Query() DTO expansion

Testing

yarn test src/test/nestjs/schema.test.ts

All new tests pass:

  • ✅ should expand @query() DTO into individual query parameters
  • ✅ should not have a single "query" parameter for DTO

Fixes #91

When using NestJS with @query() decorator and a DTO class (without field name argument),
the DTO properties are now properly expanded into individual OpenAPI query parameters
with their JSDoc annotations (example, minimum, maximum, default, etc.)

Changes:
- Add isDto flag to NestParameterMetadata to identify DTO query parameters
- Update parser to mark @query() without field name as DTO
- Update openapiGenerator to expand DTO properties into individual query parameters
- Add tests for @query() DTO expansion
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Extract JSDoc annotation merging logic into a shared utility function
in schemaBuilder.ts and reuse it in both schemaBuilder.ts and
nestjs/openapiGenerator.ts to avoid code duplication.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hyeonss0417 hyeonss0417 merged commit be1cb23 into main Dec 25, 2025
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NestJS] @Query() DTO parameters not expanded into individual query parameters

2 participants