fix: expand @Query() DTO parameters into individual query parameters #92
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: