[Java] Generated methods for multipart/form-data requestBody missing body parameter
Description
Generating Java code for a YAML file that contains a multipart/form requestBody results in a method that lacks any parameters to pass values in. As such there's no way to upload data. The yaml file I included isn't what I'm using, but it exhibits the same problem. The multiform data part came from https://swagger.io/docs/specification/describing-request-body/multipart-requests/
I can add a parameter section that duplicates the requestBody section and the code generated will take in said parameters, but parameters are not used to add form data for post, put and paste operations.
For my real YAML file, https://editor.swagger.io/ generates code that takes a "body" object parameter in the post methods. The included yaml file won't generate code for some reason, though it's listed as valid. The body object isn't correct though as the values need to go in the localVarFormParams variable and that's not happening.
Swagger-codegen version
3.0.0-SNAPSHOT (nightly)
Swagger declaration file content or url
openapi: "3.0.1"
info:
version: 1.0.0
title: Test
paths:
/upload:
post:
summary: Upload a file with info
operationId: uploadImage
requestBody:
content:
multipart/form-data: # Media type
schema: # Request payload
type: object
properties: # Request parts
id: # Part 1 (string value)
type: string
format: uuid
address: # Part2 (object)
type: object
properties:
street:
type: string
city:
type: string
profileImage: # Part 3 (an image)
type: string
format: binary
responses:
'200':
description: Response
Command line used for generation
java -jar swagger-codegen-cli.jar generate -l java -i test.yml -o code
this generates the following methods in DefaultApi.java which don't take any parameters.
/**
* Upload a file with info
*
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public void uploadImage() throws ApiException {
uploadImageWithHttpInfo();
}
/**
* Upload a file with info
*
* @return ApiResponse<Void>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<Void> uploadImageWithHttpInfo() throws ApiException {
com.squareup.okhttp.Call call = uploadImageValidateBeforeCall(null, null);
return apiClient.execute(call);
}
Steps to reproduce
Simply take the test.yaml file and generate java code.
If I replace multipart/form-data with any other type in the yaml file, the code will add a body parameter, but that won't work since it needs to be form data.
I checked and using "application/x-www-form-urlencoded" also doesn't work.
Hello, Did you find a solution or workaround for this? Thanks;
I have the same problem.
+1
Faced the same issue. Any chance it will be fixed?
This is a serious issue that has been open for over a year - any timeline on a fix?
It is now open for over 3 years ... and I also have this issue
I am facing the same issue, my GAV details:
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.32</version>
seems to be fixed in SwaggerHub On-Premise 2.1.0 v3.0.34