-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[JAVA] Bug generating request body for array of files upload #9195
Comments
Seeing this exact issue in 3.0.5 when attempting to upload multiple zip files. Server side receives a single multipart body when there should be one per file. |
Encountered this bug using swagger-codegen-cli-3.0.24 to generate a Client for a provided swagger-api. When using the api call, the files are not processed by the server. We found a workaround by using org.springframework.core.io.FileSystemResource.FileSystemResource for the call. For this we added a type mapping to the codegen call like: --type-mappings File=org.springframework.core.io.Resource With this the typ mapping the method signiture changed from:
to:
Unfortunatly we ran into another error than we jackson was not able to serialize the call:
This error is affected by the call to the formParams variable inside the generated client:
When checked in detail (via debugger), not the Resourcefiles are added to the MultiValueMap, but the (Array)list itself is placed inside a List for the key "images". When changing add to addAll, all files are beeing send to the server and can be processed there. Unfortunately I am missing the experience with the swagger project to convert this into a PR, but maybe this will help others when facing the same problem. |
I generated code using The JSON issue can be either resolved in the object's class To fix the file list issue I patched generated class
|
Java code generated for request body for multi-part form data does not put the content of the files in request body, instead it places the file path and name in the request body.
Git clone and build Swagger-codegen version 3.0.5 via instructions on Github README
Swagger yaml openapi-upload-files.yaml
Build client from OpenApi yaml with Swagger Codegen
Java class used for generation of POST request
Compile test program
Monitor POST requests in another terminal window
Run test program
Produces this POST request body (seen in tcpdump window):
There should have been two bodies with Content-Disposition that included a 'filename="test<#>.txt" and the contents of the file
ApiClient.java creates a correct body only if the instance of the formParams Object is a File, but in the test case it is a List of Files and so the correct body is not created.
The text was updated successfully, but these errors were encountered: