OpenAPITools / OpenAPITools/openapi-generator

Generated Java client is sending multipart parts in wrong order

Open
#13,711 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java generator's okhttp-gson multipart request generation and reproduce the issue using the supplied OpenAPI 3.0 schema and request log. Done means the generated client sends the info part before the file part for this upload operation, with a regression test covering the ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.