Skip to content

Return raw bytes for binary response bodies - #21

Merged
meoyawn merged 1 commit into
masterfrom
fix-binary-response-body
Nov 22, 2026
Merged

meoyawn merged 1 commit into
masterfrom
fix-binary-response-body

Conversation

@meoyawn

@meoyawn meoyawn commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

A response such as

"200":
  content:
    application/octet-stream:
      schema:
        type: string
        contentMediaType: application/octet-stream

generated a TypeScript client whose getFileResult declared { status: 200; body: string; raw: Response } but returned { status: 200, raw: response }, and getFile(): Promise<string> returned response.body. Strict tsc rejects it. The existing private-typescript golden had the same inconsistency for its application/octet-stream ValidationErr 400 response (28 tsc --strict errors). Go converted the raw bytes to the schema type (ValidationErr(rawBody)), which does not compile for non-string schemas.

Fix

  • clientgen.Response.Binary(): a body with a schema that is not JSON, text/XML or SSE.
  • TypeScript: binary bodies are read with response.blob() and typed Blob (same type used for binary multipart parts). getFileResult now returns { status: 200; body: Blob; raw: Response } | { status: 404; raw: Response }, and getFile returns Promise<Blob>.
  • Go: binary bodies are stored as *[]byte (bounded read as before, no JSON decoding), matching Rust Vec<u8> and Dart List<int>, which were already correct.
  • New binary-response.yaml fixture with Go client and TypeScript client goldens; update-goldens regenerates them. README documents the mapping.

Verification

  • moon run oasmith:check (golangci-lint: 0 issues; go test ./... passes).
  • tsc --strict --noEmit on binary-response-typescript, private-typescript and config-typescript goldens: no errors.
  • Go client generated from private.yaml now passes go vet.

A response whose media type is neither JSON, text, XML nor an event
stream but carries a schema (e.g. OpenAPI 3.1+ `type: string` with
`contentMediaType: application/octet-stream`) was declared with a typed
body in TypeScript (`body: string`) while the implementation returned no
body, so generated clients failed strict `tsc`. Go converted the bytes to
the schema type, which fails to compile for non-string schemas.

Classify such responses as binary in clientgen. TypeScript now reads them
with `response.blob()` and types them as `Blob`, matching binary multipart
parts; Go stores the bytes as `[]byte`, matching Rust `Vec<u8>` and Dart
`List<int>`. Add a binary-response fixture with Go and TypeScript goldens,
and refresh the private TypeScript golden, whose octet-stream 400 response
had the same inconsistency.
@meoyawn
meoyawn merged commit 56cb36a into master Nov 22, 2026
1 check passed
@meoyawn
meoyawn deleted the fix-binary-response-body branch November 22, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant