Skip to content

[JAVA] [Swift5] multipart/form-data upload with multiple files in one field #9839

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

Open
JohannesKuehnel opened this issue Nov 8, 2019 · 0 comments

Comments

@JohannesKuehnel
Copy link

JohannesKuehnel commented Nov 8, 2019

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
  1. Create a Swagger 2.0 document with a POST endpoint and the parameter provided above.
  2. Run the code generation with one of the commands from above.
  3. 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.

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

No branches or pull requests

1 participant