Skip to content

Commit 013d222

Browse files
Fixing required api field bug.
1 parent be20b82 commit 013d222

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/common/decorators/field.decorator.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ export function Field(options: FieldOptions) {
6666
decorators.push(GraphQLField(pick({ ...options, nullable: !required }, ['nullable', 'name', 'description', 'type'])));
6767

6868
// Swagger property decorator
69-
if (required) {
70-
decorators.push(ApiProperty(swaggerMeta));
71-
} else {
72-
decorators.push(ApiPropertyOptional(swaggerMeta));
69+
// IMPORTANT: Only apply ApiProperty/ApiPropertyOptional if this field is NOT a query or path parameter
70+
// Query and path parameters are documented via @ApiQuery and @ApiParam in the @Api decorator
71+
// Applying ApiProperty here would treat them as body properties, causing Swagger UI issues
72+
if (!options.inQuery && !options.inPath) {
73+
if (required) {
74+
decorators.push(ApiProperty(swaggerMeta));
75+
} else {
76+
decorators.push(ApiPropertyOptional(swaggerMeta));
77+
}
7378
}
7479

7580
if (!required) {

0 commit comments

Comments
 (0)