[Java][native] support InputStream mappings for binary payloads

WI
13d ago
+947-7

Fixes #24057.

Summary

  • Honor explicit file=InputStream and binary=InputStream mappings in the Java native client 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 InputStream request bodies without Jackson serialization, including the gzip path.
  • Keep the default File behavior 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 File path and a non-binary JSON mapping remain on their existing branches.
  • checkstyle:check passed for modules/openapi-generator.
  • git diff --check passed.

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-stream and x-java-native-body-input-stream when binary/file schemas resolve to java.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 InputStream request bodies via a one‑shot AtomicReference supplier; optional gzip uses ApiClient.gzipRequestBody; Jackson is skipped.
    • Non-binary schemas mapped to InputStream keep normal JSON serialization/deserialization.
  • Bug Fixes

    • gzipRequestBody handles null suppliers and frees internal streams on EOF to avoid double-closing and leaks.