swagger-api / swagger-api/swagger-codegen

[Spring] application/octet-stream generate an Objetc File instead of byte[]

Open
#8,872 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Swagger-codegen version

V 3.0.2

Description

I was using swagger 2.0 with mavenplugin-codegen V 2.3.1 :
When i have a response type application/octet-stream
=> Json file : "schema" : { "type" : "string", "format" : "binary"}
=> Genetares this signature in the Interface API:
@RequestMapping(value = "/addressbooks/export/{addressBookId}", produces = { "application/octet-stream" }, method = RequestMethod.GET)
public ResponseEntity<byte[]>

Now i have migrated in openApi3 with mavenplugin-codegen V3.0.2
When i have a response type application/octet-stream
=> Json file : "content":{"application/octet-stream":{"schema":{"type":"string","format":"binary"}}}
=> it generates this signature Interface API :
@RequestMapping(value = "/addressbooks/export/{addressBookId}",produces = { "application/octet-stream", "application/json" }, method = RequestMethod.GET)
default ResponseEntity< File >

The fact that the response is a File instead of byte[] makes spring raise this exception :
"org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation"

Steps to reproduce
  1. Create a openAPi3 with this response :
    responses:
    '200':
    content:
    application/octet-stream:
    schema:
    type: string
    format: binary

  2. Generate the Json file.

  3. Launch the build with codegen 3.0.2 for spring

  4. Check you have a signature => default ResponseEntity< File >

  5. Try to reach this endpoint

  6. Must get: "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation"

Related issues/PRs
Suggest a fix/enhancement

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 by reproducing the Spring generator output from the OpenAPI 3 response schema shown in the issue using swagger-codegen 3.0.2 and the Maven plugin. Trace the generated endpoint signature and its response handling; done means an application/octet-stream response generates a usable byte[] representation instead of File and no longer raises the reported media-type exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.