openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Generated Java client is sending multipart parts in wrong order

Open tweetysat opened this issue 3 years ago • 0 comments

I have to generate a client for a rest api. The openapi 3.0 file contains

document_body:
  type: object
  properties:
    info:
      $ref: '#/components/schemas/UploadInfo'
    file:
      type: string
      format: binary

I'm generating the client with

<generatorName>java</generatorName>
<library>okhttp-gson</library>

In the generated files I have

public String upload(UploadInfo info, File _file) throws ApiException {
    ApiResponse<String> localVarResp = uploadWithHttpInfo(info, _file);
    return localVarResp.getData();
}

When using the client I can see in the logs

2022-10-17 09:48:33.018  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : --> POST http://...:4080/upload
2022-10-17 09:48:33.018  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : Content-Length: 1844
2022-10-17 09:48:33.018  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : Accept: application/json
2022-10-17 09:48:33.018  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : Content-Type: multipart/form-data
2022-10-17 09:48:33.018  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : User-Agent: OpenAPI-Generator/2.0.0/java
2022-10-17 09:48:33.019  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : 
2022-10-17 09:48:33.019  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : --c963f9a0-4bad-455e-ad08-9bac95d95796
Content-Disposition: form-data; name="file"; filename="MessageBody5576982632595433767.pdf"
Content-Type: application/pdf
Content-Length: 1228

JVBERi0xL....
Content-Disposition: form-data; name="info"
Content-Type: application/json; charset=utf-8
Content-Length: 228

{...}
--c963f9a0-4bad-455e-ad08-9bac95d95796--

2022-10-17 09:48:33.019  INFO 14704 --- [nio-8091-exec-1] okhttp3.OkHttpClient                     : --> END POST (1844-byte body)

The problem is that the api needs that the info part is sent before the file part. I don't know why the client is inverting the 2 parts.

Is there a solution ?

tweetysat avatar Oct 17 '22 07:10 tweetysat