-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
The official Swagger 2.0 documentation states binary string arrays as the workaround for specifying a multipart/form-data upload with multiple files in one field (like a file array).
However, uploading an arbitrary number of files (an array of files) is not supported. There is an open feature request at OAI/OpenAPI-Specification#254. For now, you can use a binary string array as a workaround for uploading an arbitrary number of files:
type: array items: type: string format: binary
Swagger UI already has problems correctly rendering this type, but code generation (for Java okhttp-gson and Swift5 at least) "fails" as well. The code generation itself is done without errors, but the request isn't formed correctly.
Swagger-codegen version
2.4.9
Swagger declaration file content or url
parameters: - in: formData name: images description: Image files for the post type: array items: type: string format: binary
Command line used for generation
Java (okhttp-gson): java -jar swagger-codegen-cli.jar generate -DhideGenerationTimestamp=true -DartifactId="android-client" -DartifactVersion="0.1" -i openApi.yml -l java --library=okhttp-gson -o build/
Swift5: java -jar swagger-codegen-cli.jar generate -i openApi.yml -l swift5 -o build/
Steps to reproduce
- Create a Swagger 2.0 document with a POST endpoint and the parameter provided above.
- Run the code generation with one of the commands from above.
- Take a look at the generated methods for the upload and/or try to send a file (a simple [mocked] backend should suffice).
Related issues/PRs
OAI/OpenAPI-Specification#254
swagger-api/swagger-codegen-generators#150
PR: #9840
Suggest a fix/enhancement
The codegen templates for Java with okhttp-gson and Swift5 (Alamofire) should interpret arrays with binary strings as file parameters. Like swagger-codegen for the normal Java client does.