Describe the bug
When an operation returns a bytes body with a custom @header contentType (e.g. application/zip),
the emitter generates broken response code that:
- Correctly sets the content-type from the
@header property, then immediately overwrites it with application/json
- Calls
Uint8Array.toJsonObject() which doesn't exist, causing a runtime crash
This is the response-side equivalent of the request-side fix in #6898.
Reproduction
@post
op exportFile(): {
@statusCode statusCode: 200;
@header contentType: "application/zip";
@body content: bytes;
};
Generated code in server-raw.ts:
// Bug 1: correct content-type is immediately overwritten
ctx.response.setHeader("content-type", result.contentType); // "application/zip" ✓
ctx.response.setHeader("content-type", "application/json"); // overwrites it ✗
// Bug 2: Uint8Array has no static toJsonObject method — throws at runtime
ctx.response.end(globalThis.JSON.stringify(Uint8Array.toJsonObject(result.content)));
Expected behavior:
ctx.response.setHeader("content-type", result.contentType);
ctx.response.end(result.content); // send bytes directly, no JSON serialization
Root cause:
In packages/http-server-js/src/http/server/index.ts, the response body handling block unconditionally applies JSON serialization without checking whether the body type is bytes (via ctx.program.checker.isStdType(body.type, "bytes")). The same check already exists on the request deserialization path (added in #6898) but was not applied symmetrically to responses.
Additional context:
Emitter version: 0.58.0-alpha.26
Checklist
Describe the bug
When an operation returns a
bytesbody with a custom@header contentType(e.g.application/zip),the emitter generates broken response code that:
@headerproperty, then immediately overwrites it withapplication/jsonUint8Array.toJsonObject()which doesn't exist, causing a runtime crashThis is the response-side equivalent of the request-side fix in #6898.
Reproduction
Generated code in
server-raw.ts:Expected behavior:
Root cause:
In
packages/http-server-js/src/http/server/index.ts, the response body handling block unconditionally applies JSON serialization without checking whether the body type is bytes (viactx.program.checker.isStdType(body.type, "bytes")). The same check already exists on the request deserialization path (added in #6898) but was not applied symmetrically to responses.Additional context:
Emitter version: 0.58.0-alpha.26
Checklist