anatine/zod-plugins

multipart/form-data

Opened this issue · 1 comments

Hi,
This is an extension of the closed question: #69

I'm trying to migrate away from the nestjs swagger annotations to using zod instead, which on the whole is working - apart from multipart-form.

So previously I had:

export class ImageClassificationRequest {
  @ApiProperty({
    enum: availableClassificationModels,
    type: String,
    description: 'The model to use for image classification'
  })
  
  public model!: KnownImageClassificationModel
  @ApiProperty({
    type: 'string',
    format: 'binary'
  })
  public image!: string
}

In swagger I get a file input:

Screenshot 2024-10-10 at 13 16 42

However if i try and use binary format string with zod:

const binarySchema = extendApi(z.string(), {
  format: 'binary'
})

export class ImageClassificationRequest extends createZodDto(
  z.strictObject({
    model: classificationModelsZodType.describe(
      'The model to use for image classification'
    ),
    image: binarySchema.describe('The image to classify')
  })
) {}

Swagger just becomes a string:

Screenshot 2024-10-10 at 13 17 45

Any help would be appreciated!

The same question!