OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] [RESTCLIENT] [MAVEN] Maven plugin 7.22.0 produces invalid client code to get application/octet-stream

Open
#23,885 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have a simple OpenAPI specification (external openapi, I cannot change it):

paths:
  /download:
    get:
      summary: Download file
      operationId: downloadFile
      parameters:
        - name: fileName
          in: query
          description: File name
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        "4XX":
          description: Failure
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/errorResponse"

I generate code client with openapi-generator-maven-plugin 7.22.0 and try to download file via the generated client in my unit test:

  @Test
  void downloadProblem() {
    File ok = defaultApi.downloadFile("ok");
    assertThat(ok).exists();
  }

I expect the code downloads file successfully, but instead one failed with:

org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.io.File] and content type [application/octet-stream]

	at org.springframework.web.client.DefaultRestClient.readWithMessageConverters(DefaultRestClient.java:251)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.readBody(DefaultRestClient.java:826)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.lambda$body$1(DefaultRestClient.java:765)
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:586)
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchange(DefaultRestClient.java:540)
	at org.springframework.web.client.RestClient$RequestHeadersSpec.exchange(RestClient.java:677)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.executeAndExtract(DefaultRestClient.java:821)
	at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.body(DefaultRestClient.java:765)

openapi-generator version

7.22.0

OpenAPI declaration file content or url

https://github.com/anatoly-spb/openapi-octet-stream-problem/blob/main/src/main/resources/downloader.yaml

Generation Details

https://github.com/anatoly-spb/openapi-octet-stream-problem/blob/main/pom.xml#L109

Steps to reproduce
Related issues/PRs
Suggest a fix

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

Clone the linked reproduction project and run the downloadProblem test with mvn test, using downloader.yaml and the generation settings in pom.xml as the starting points. Trace the generated Java REST client’s application/octet-stream handling and compare it with the expected File result; done means the test downloads the file successfully without UnknownContentTypeException.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
49/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.