-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[develop 2.0] add support for multiple file uploads #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think there's some confusion here. @mhdl64 is using Swagger 1.2 and not 2.0. Another problem is that I can't think of a way to describe multiple file uploads, unless we modify the 2.0 spec. You can describe a single file parameter, no problem. But you cannot specify an array of files, since We could change that, though it'll carry complications to both the documentation and the schema (not a reason not to add support for it). Even if we do add support for it, we may need to impose a Last thing, there's a ticket for a future version of the spec to allow specifying the mime type(s) of the uploaded files, and it should integrate well into this solution. |
{
"type": "array",
"items": {
"type": "file"
}
} looks appropriate but it's not supported. See here: |
@webron @fehguy I was able to work around the issue using a different name for the parameter object. So that the parameter is 'translated' to an Array. Example: The parameter {
"path": "api/v1/upload",
"operations": [
{
"summary": "Upload multiple files",
"consumes": "multipart/form-data",
"parameters": [
{
"paramType": "formData",
"name": "files[]",
"type": "file",
"required": true
},
{
"paramType": "formData",
"name": "files[]",
"type": "file",
"required": false
},
{
"paramType": "formData",
"name": "files[]",
"type": "file",
"required": false
},
{
"paramType": "formData",
"name": "files[]",
"type": "file",
"required": false
}
],
"responseMessages": [
{
"code": 201,
"responseModel": null,
"message": "Created"
},
{
"code": 422,
"responseModel": null,
"message": "Unprocessable Entity"
}
],
"method": "post",
"nickname": "Api::V1::Uploads#create"
}
]
} Note: I'm using a Rails backend and documented the API with the DSL of the swagger-docs gem. |
Technically, that's not a valid Swagger definition though. |
Maybe this could just be "allowMultiple" for files if the param is a form and ignore the param name? I'm just saying because my attempt to get multiple files to work was the same as Muhammad's from the google group post, so maybe other people are going to try the same thing first.
|
Unfortunately, the current specification doesn't provide a way to solve it unfortunately. This is why there's an issue on swagger-spec about it linked above. |
ok since this isn't supported by the spec, I'm going to close it. |
@webron i assume @JanDintel's suggestion is not a valid definition because he repeats the same parameter name multiple times? but there should be no problem to only use a single block
only drawback i noticed so far is the file upload in the swagger gui does not support multiple files. |
@webermax the spec doesn't support a definition of a mulit-file parameter. You can define as many file parameters as you want, but you'd have to define the exact number of files. |
Per this discussion:
https://groups.google.com/forum/#!topic/swagger-swaggersocket/6a_tAGtj7CE
Would be helpful to add support for arrays of files. This would require updates in swagger-js as well.
The text was updated successfully, but these errors were encountered: