Skip to content

Conversation

@hyeonss0417
Copy link
Contributor

@hyeonss0417 hyeonss0417 commented Jan 15, 2026

Summary

Add support for file upload fields in DTOs using the @format binary JSDoc tag for NestJS integration.

Problem

Previously, file uploads were only recognized when using the @UploadedFile() decorator. When a DTO class contained a MulterFile type property, TJS would convert the entire MulterFile interface into a schema, causing buffer, stream, and other internal properties to appear in the Swagger UI.

Solution

Use the @format binary JSDoc tag to explicitly indicate file upload fields in DTOs.

Usage

export class CreateFoodIntakeFromImageDto {
  /**
   * Food image file
   * @format binary
   */
  file!: any;

  /**
   * Intake time (defaults to current time if not provided)
   * @format date-time
   * @example "2024-11-24T12:30:00.000Z"
   */
  intakeAt?: string;
}

Generated OpenAPI Schema

requestBody:
  required: true
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          file:
            type: string
            format: binary
            description: Food image file
          intakeAt:
            type: string
            format: date-time
        required:
          - file

Changes

  • schemaBuilder.ts: Detect @format binary tag in mergeJsDocAnnotations and convert to { type: 'string', format: 'binary' } schema
  • openapiGenerator.ts: Automatically use multipart/form-data content type when Body DTO contains @format binary properties
  • tests: Add tests for file upload scenarios with @format binary

Why @format binary instead of type detection?

We chose @format binary JSDoc tag over hardcoding type names (MulterFile, Express.Multer.File, etc.):

  • Follows OpenAPI standard
  • Explicit and clear intent
  • Flexible and not dependent on specific type names

- Add support for @Format binary JSDoc tag to indicate file upload fields in DTOs
- Automatically use multipart/form-data content type when DTO contains binary fields
- Convert @Format binary properties to { type: 'string', format: 'binary' } schema
- Add tests for file upload scenarios with @Format binary

Usage:
```typescript
export class CreateFoodIntakeFromImageDto {
  /**
   * 음식 이미지 파일
   * @Format binary
   */
  file!: any;

  /**
   * 섭취 시간
   * @Format date-time
   */
  intakeAt?: string;
}
```
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 8370039 into main Jan 15, 2026
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.

2 participants