feat(spring): @Streaming annotation for binary response streaming#618
Open
nsmnds wants to merge 2 commits into
Open
feat(spring): @Streaming annotation for binary response streaming#618nsmnds wants to merge 2 commits into
nsmnds wants to merge 2 commits into
Conversation
Lets a spec author opt in to chunked, never-fully-buffered response
streaming on Spring endpoints whose body is `Bytes`:
endpoint DownloadReport GET /api/report -> {
@streaming
200 -> Bytes
}
The Spring Kotlin/Java emitters substitute `org.springframework.core.io.Resource`
for the body type, skip the JSON serialize step, and add a `STREAMING`
marker on the handler companion. `WirespecResponseBodyAdvice` writes the
`Resource.inputStream` straight to `response.body`. `WirespecWebClient`
detects the marker and streams via `bodyToMono(Resource.class)` instead
of buffering bytes.
Other client SDKs are unaffected — `RawResponse.body: ByteArray?` stays
the same, and `fromResponse` still works (wrapping in `ByteArrayResource`)
for non-streaming callers like tests and mocks.
To enable Spring's per-emitter behavior, the core Kotlin/Java emitters
expose three new `open` hooks (`emitResponseBodyType`,
`emitResponseSerializeBody`, `emitResponseDeserializeBody`) plus a
companion-extras hook used to inject the marker.
https://claude.ai/code/session_013z9Zaawbdh3pnyMg4b2DSG
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds a
@Streamingannotation that opts aBytesresponse into chunked,never-fully-buffered response streaming on Spring endpoints — both server
and client (Spring
WirespecWebClient) sides.What changes
org.springframework.core.io.Resourcefor the body type when a response is annotated
@Streaming, skip the JSONserialize step, and emit a
STREAMINGmarker on the handler companion.WirespecResponseBodyAdvice(Kotlin + Java) dispatches on a runtimeResourcebody and writesResource.inputStreamstraight toresponse.bodywithapplication/octet-stream.WirespecWebClient(Kotlin + Java) detects the marker reflectivelyand consumes the response via
bodyToMono(Resource.class)instead ofbuffering bytes.
@Streamingon a non-Bytesresponse fails the emit.KotlinEndpointDefinitionEmitterandJavaEndpointDefinitionEmitterexpose three newopenhooks(
emitResponseBodyType,emitResponseSerializeBody,emitResponseDeserializeBody) plus a companion-extras hook so per-emittersubclasses can override response-body behavior without touching the
request path.
concatGenericssanitizer: now strips dots so fully-qualified bodytypes produce valid identifiers.
Out of scope (intentional)
the existing
RawResponse.body: ByteArray?contract — unchanged.fromResponsestill works for non-streaming callers (tests, mocks)by wrapping the buffered body in
ByteArrayResource. The Springstreaming client bypasses that path entirely.
Test plan
:src:compiler:core:jvmTest,:src:compiler:emitters:kotlin:jvmTest,:src:compiler:emitters:java:jvmTest— all green:src:integration:spring:jvmTest— all green (existing 49 tests +6 new emitter tests asserting Resource body / STREAMING marker /
@Streamingvalidation for both Kotlin and Java):src:converter:openapi:jvmTest,:src:integration:jackson:jvmTest— all green (verifies
concatGenericschange is backward-compatible)full body for a slow
InputStreamResourceserver (recommendedfollow-up integration test, not yet added)
https://claude.ai/code/session_013z9Zaawbdh3pnyMg4b2DSG