Skip to content

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

@anatoly-spb

Description

@anatoly-spb

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions