fix: expand @Query() DTO parameters into individual query parameters#92
Merged
hyeonss0417 merged 2 commits intomainfrom Dec 25, 2025
Merged
fix: expand @Query() DTO parameters into individual query parameters#92hyeonss0417 merged 2 commits intomainfrom
hyeonss0417 merged 2 commits intomainfrom
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:The generated OpenAPI spec would have a single
queryparameter 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: AddisDtoflag toNestParameterMetadatato identify DTO query parametersparser.ts: Mark@Query()without field name argument as DTO (isDto: true)openapiGenerator.ts: AddbuildPropertySchemafunction and expand DTO properties into individual query parameters with JSDoc annotations (@example,@minimum,@maximum,@default, etc.)@Query()DTO expansionTesting
yarn test src/test/nestjs/schema.test.tsAll new tests pass: