Repository navigation
Return raw bytes for binary response bodies - #21
Merged
Merged
Conversation
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.
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.
Problem
A response such as
generated a TypeScript client whose
getFileResultdeclared{ status: 200; body: string; raw: Response }but returned{ status: 200, raw: response }, andgetFile(): Promise<string>returnedresponse.body. Stricttscrejects it. The existingprivate-typescriptgolden had the same inconsistency for itsapplication/octet-streamValidationErr400 response (28tsc --stricterrors). 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.response.blob()and typedBlob(same type used for binary multipart parts).getFileResultnow returns{ status: 200; body: Blob; raw: Response } | { status: 404; raw: Response }, andgetFilereturnsPromise<Blob>.*[]byte(bounded read as before, no JSON decoding), matching RustVec<u8>and DartList<int>, which were already correct.binary-response.yamlfixture with Go client and TypeScript client goldens;update-goldensregenerates them. README documents the mapping.Verification
moon run oasmith:check(golangci-lint: 0 issues;go test ./...passes).tsc --strict --noEmitonbinary-response-typescript,private-typescriptandconfig-typescriptgoldens: no errors.private.yamlnow passesgo vet.