swagger-api / swagger-api/swagger-codegen
[Spring] application/octet-stream generate an Objetc File instead of byte[]
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
-
Create a openAPi3 with this response :
responses:
'200':
content:
application/octet-stream:
schema:
type: string
format: binary -
Generate the Json file.
-
Launch the build with codegen 3.0.2 for spring
-
Check you have a signature => default ResponseEntity< File >
-
Try to reach this endpoint
-
Must get: "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation"
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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