Type |聽Version
---|---
Question | 4.x
I am trying to create a multipart endpoint (file upload).
I used the example in the docs and it seems to work fine, but I can't make the swagger doc show the file field of the request. I am also using a path param.
Here is an example
import { Controller, PathParams, Post } from '@tsed/common';
import { MultipartFile } from '@tsed/multipartfiles';
type MulterFile = Express.Multer.File;
@Controller('/api')
export default class FileCtrl {
@Post('/:username')
test(@MultipartFile() myFile: MulterFile, @Required() @PathParams('username') username: string) {
// Logic ...
}
}
swagger result:
paths:
'/api/{username}':
post:
parameters:
- in: path
name: username
type: string
required: true
consumes: []
Expected Result:
paths:
'/api/{username}':
post:
consumes:
- multipart/form-data
parameters:
- in: path
name: username
type: string
required: true
- in: formData
name: myFile
type: file
description: The file to upload.
responses:
'200':
description: Success
Am I doing something wrong? or is this missing functionality?
Thanks!
Multipart decorators didn't add information for the swagger spec.
this issue can help you : #378
Thanks for the fast response!
this helps:
@Operation({consumes: ["application/x-www-form-urlencoded"]})
But I can't seem to set the type to file
ha ok... Hum we need to improve the multipartfile module for that.
@Romakita do you have an estimate when it will be added? 馃槃
Work in progress :)
Thanks!
Tested and it's looking good! waiting for #311 to be resolved and I'll upgrade 馃槃
Hi @Romakita!
Found two small issues,
The new code adds a creates the following swagger:
paths:
'/api/{username}':
post:
consumes:
- multipart/form-data
parameters:
- in: path
name: username
type: string
required: true
- in: formData
required: false # This fails validation and it's missing the "name" field
type: file
There are two issues are:
name fieldrequired: false field which fails swagger validationshould be:
paths:
'/api/{username}':
post:
consumes:
- multipart/form-data
parameters:
- in: path
name: username
type: string
required: true
- in: formData
name: myFile # <-- this is missing
type: file
Thanks for all your help!
Hi @Romakita!
Did you verify the issue? 馃槃
Hi @TomerAmirV,
This problem is fixed with the latest release. It support only a single file right now. Multiple file isn't support by swagger ui with the swagger 2.0 spec
@Romakita, the second bug I reported is in version 4.23.1, after the first fix
Hi @Romakita, any news on the second bug?
ok. I didn't seen your second issue. Currently, the name doesn't exists with the Multipartfile decorator. Multipartfile use anonymous field name and swagger accept this configuration.
I think this was fixed, and it's working in version 4.25.0 馃帀
Most helpful comment
Work in progress :)