[Java] InputStream is preferable to File from oas v3 with format binary

Open
#994 5 comments 23 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, openapi
Domain
api, backend, tooling

Research direction

Run the shown Maven build and jaxrs-jersey generation command with the linked OpenAPI YAML. Compare the generated testsapi.java and testsapiservice.java examples, then trace the Java generator path that maps binary request bodies. Done means generated code uses InputStream instead of File without breaking the generated API and service output.

Written by the indexing model from the issue text.

Description

Description

Currently, File type is employed in generated codes from oas v3 with format binary.
I think InputStream type is more suitable for it.

I locally test with jersey, and found that jersey accepts File type as request body entity, but it internally writes the binary stream to local disk, and passes the wrote file to the resource class argument.
It is not good for performance, so I think we should change type into InputStream

openapi-generator version

current master (abe741f)

OpenAPI declaration file content or url

https://gist.github.com/fujigon/dd00a99b79a2bc811761b29e63e08a39#file-openapi-yaml

Command line used for generation
# git clone, etc
mvn package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi.yaml -g jaxrs-jersey
Steps to reproduce

execute the command, and it successfully runs.
I get

Related issues/PRs
Suggest a fix/enhancement

https://github.com/fujigon/openapi-generator/tree/feature/fix-primitive-type-resolve

Dominant language
Java
Stars
26.8k
Forks
7.7k
Avg merge
1d 6h
Merged PRs (30d)
100

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.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.