[Java][native] support InputStream mappings for binary payloads
Fixes #24057.
Summary
- Honor explicit
file=InputStreamandbinary=InputStreammappings in the Javanativeclient for binary responses and raw request bodies. - Return mapped response streams directly instead of routing them through the temporary-file branch, while preserving caller ownership in synchronous and asynchronous APIs.
- Publish raw
InputStreamrequest bodies without Jackson serialization, including the gzip path. - Keep the default
Filebehavior and JSON serialization/deserialization unchanged.
Implementation notes
The generator derives native-only template flags after type resolution. The stream path is selected only when the original OpenAPI schema is binary/file and the resolved Java type is java.io.InputStream; mapping an ordinary JSON schema to InputStream therefore continues to use Jackson.
The native templates transfer response-stream ownership before their cleanup blocks run. Async delivery also propagates cancellation to the transport and closes a stream that loses a delivery race. Request publishers are one-shot and thread-safe, including gzip, so a retry cannot read a consumed stream or double-close the normal source path.
@bbdouglas, this touches the Java 11 native HTTP client templates.
Verification
- Focused generator/runtime scope: 9 tests, 0 failures/errors.
- Generated and packaged fresh synchronous, asynchronous, and gzip-enabled Java native clients.
- Verified the default
Filepath and a non-binary JSON mapping remain on their existing branches. checkstyle:checkpassed formodules/openapi-generator.git diff --checkpassed.
The full repository test matrix was not run locally; CI is expected to provide the broader generator/sample coverage.
PR checklist
- Read the contribution guidelines.
- Run the full repository build/sample/doc regeneration commands from the PR template. Targeted generator tests, generated-client packages, and checkstyle were run as documented above; this change has no checked-in sample delta.
- Mention the relevant technical committee member.
Summary by cubic
Adds support for explicit file=InputStream and binary=InputStream mappings in the Java native client, streaming binary responses and raw request bodies as java.io.InputStream. Improves async cancellation and one‑shot request publishing; keeps default File downloads and JSON handling unchanged. Fixes #24057.
-
New Features
- Generator marks operations with
x-java-native-response-input-streamandx-java-native-body-input-streamwhen binary/file schemas resolve tojava.io.InputStream(via type or import mapping). - Return mapped response streams directly; async APIs propagate cancellation to transport and close undeliverable streams while keeping successful streams caller-owned.
- Publish
InputStreamrequest bodies via a one‑shotAtomicReferencesupplier; optional gzip usesApiClient.gzipRequestBody; Jackson is skipped. - Non-binary schemas mapped to
InputStreamkeep normal JSON serialization/deserialization.
- Generator marks operations with
-
Bug Fixes
gzipRequestBodyhandles null suppliers and frees internal streams on EOF to avoid double-closing and leaks.