Commit b6b8746
feat(server,openapi): support ReadableStream<Uint8Array> as handler return value (#1535)
## Summary
Adds **partial** support for returning a `ReadableStream<Uint8Array>`
directly from an oRPC handler (OpenAPIHandler only), bypassing JSON
serialization. This enables streaming binary responses (ZIP archives,
large file downloads, chunked transfer) without buffering the full
response in memory.
> **Note:** Full ecosystem support (RPCHandler/Link, OpenAPILink,
WebSocket adapters, etc.) is planned for v2 — see
[#1058](#1058 (comment)).
This PR intentionally does **not** close #1058.
### Stream passthrough
- **`@orpc/standard-server`** — adds `ReadableStream<Uint8Array>` to the
`StandardBody` union type
- **`@orpc/server`** — `StandardRPCCodec.encode()` detects
`ReadableStream` and passes it through without serializing
- **`@orpc/openapi`** — `StandardOpenAPICodec.encode()` detects
`ReadableStream` (both as direct return and inside `{ body: stream,
headers }` detailed output), respects the contract's `successStatus`,
and bypasses serialization
- **`@orpc/standard-server-fetch`** — `toFetchBody()` returns the stream
directly; the `ReadableStream` branch runs before header cleanup so
caller-set `content-type`/`content-disposition` are preserved
- **`@orpc/standard-server-node`** — `toNodeHttpBody()` converts via
`Readable.fromWeb()`; same header-preservation fix
- **`@orpc/standard-server`** — `generateContentDisposition()` gets an
optional `disposition` parameter (defaults to `'inline'`, fully
backward-compatible)
### OpenAPI spec cleanup (fixes #1536)
- **`@orpc/openapi`** — `separateObjectSchema` no longer leaves empty
`properties: {}` / `required: []` on extracted schemas (replaces them
with `undefined`)
- **`@orpc/openapi`** — new `isNeverSchema()` helper identifies `false`
/ `{ not: true }` / `{ not: {} }` schemas; `toOpenAPIContent()` now
skips the spurious `application/json: { schema: { not: {} } }` entry
that used to appear alongside binary content (e.g. when using
`oz.openapi(z.instanceof(ReadableStream), { contentMediaType:
'application/zip' })`)
- **`@orpc/openapi`** — generator skips emitting an empty `requestBody`
for POST routes whose input consists only of path parameters
Tests added for all new paths including header preservation,
detailed-output streaming, never-schema detection, and the
empty-requestBody case.
## Backward compatibility
This is a non-breaking change.
- Previously, returning a `ReadableStream` from a handler would result
in it being serialized as `{}` (or a runtime error), which is not useful
behaviour anyone would rely on.
- `generateContentDisposition()`'s new `disposition` parameter defaults
to `'inline'`, preserving existing output.
- The OpenAPI spec cleanups only suppress output that was previously
noise (empty bodies, `not: {}` alongside real content).
Existing handlers and generated specs are unaffected.
## Motivation
We are migrating a service from Hapi.js to Hono + oRPC. One endpoint
streams a ZIP archive on-the-fly using `archiver` — the archive must be
piped directly to the response. All existing workarounds (returning `new
Response(stream)`, `oz.blob()`, casting) either fail at runtime or
require bypassing oRPC entirely, losing auth middleware and
client-library support.
Relates to #1058 (partial — OpenAPIHandler only)
Closes #1536
## Test plan
- [ ] `pnpm --filter @orpc/standard-server test`
- [ ] `pnpm --filter @orpc/server test`
- [ ] `pnpm --filter @orpc/openapi test`
- [ ] `pnpm --filter @orpc/standard-server-fetch test`
- [ ] `pnpm --filter @orpc/standard-server-node test`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Dinh Le <[email protected]>1 parent 0ee06ff commit b6b8746
17 files changed
Lines changed: 297 additions & 14 deletions
File tree
- apps/content/docs/openapi
- packages
- openapi/src
- adapters/standard
- server/src/adapters/standard
- standard-server-fetch/src
- standard-server-node/src
- standard-server/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
185 | 205 | | |
186 | 206 | | |
187 | 207 | | |
| |||
251 | 271 | | |
252 | 272 | | |
253 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
254 | 292 | | |
255 | 293 | | |
256 | 294 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
79 | 88 | | |
80 | 89 | | |
81 | 90 | | |
| |||
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
139 | 148 | | |
140 | 149 | | |
141 | 150 | | |
| |||
1428 | 1437 | | |
1429 | 1438 | | |
1430 | 1439 | | |
1431 | | - | |
1432 | 1440 | | |
1433 | 1441 | | |
1434 | 1442 | | |
| |||
1707 | 1715 | | |
1708 | 1716 | | |
1709 | 1717 | | |
1710 | | - | |
1711 | 1718 | | |
1712 | 1719 | | |
1713 | 1720 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
310 | 312 | | |
311 | 313 | | |
312 | 314 | | |
| |||
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
| 334 | + | |
332 | 335 | | |
333 | 336 | | |
334 | 337 | | |
| |||
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
351 | | - | |
| 354 | + | |
352 | 355 | | |
353 | 356 | | |
354 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
72 | 100 | | |
73 | 101 | | |
74 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
39 | 93 | | |
40 | 94 | | |
41 | 95 | | |
| |||
121 | 175 | | |
122 | 176 | | |
123 | 177 | | |
124 | | - | |
125 | 178 | | |
126 | 179 | | |
127 | 180 | | |
| |||
152 | 205 | | |
153 | 206 | | |
154 | 207 | | |
155 | | - | |
156 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
157 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
158 | 229 | | |
159 | | - | |
160 | 230 | | |
161 | 231 | | |
162 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
34 | 60 | | |
35 | 61 | | |
36 | 62 | | |
| |||
57 | 83 | | |
58 | 84 | | |
59 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
60 | 90 | | |
61 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
62 | 96 | | |
63 | 97 | | |
64 | 98 | | |
| |||
75 | 109 | | |
76 | 110 | | |
77 | 111 | | |
78 | | - | |
| 112 | + | |
79 | 113 | | |
80 | 114 | | |
81 | | - | |
| 115 | + | |
82 | 116 | | |
83 | 117 | | |
84 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
85 | 123 | | |
86 | 124 | | |
87 | 125 | | |
| |||
0 commit comments