Commit 86b0a52
committed
[go] support io.Reader and []byte response types in client decode
The Go generator maps binary types to *os.File by default. Callers can
override that with --type-mappings to get io.Reader or []byte, and
setBody already handles both for request bodies. The shared decode
helper, however, only asserts *string, *os.File, and **os.File. When
Execute declares localVarReturnValue io.Reader or []byte and calls
decode(&localVarReturnValue, ...), no branch matches and the call
returns 'undefined response type'.
Add two branches:
- *io.Reader wraps the already-buffered bytes in a bytes.Reader.
- *[]byte assigns the bytes directly. This branch must stay before the
JSON branch, since json.Unmarshal accepts *[]byte and base64-decodes
into it, which is not what we want for raw binary responses.
Both shapes are useful for different scenarios: []byte is more honest
(the response is fully buffered in memory anyway), while io.Reader is
forward-compatible (the return type stays valid if the response path is
ever refactored to skip the eager buffering and stream the body).
bytes is already imported in every generated client.go. The same
additive patch is applied to the eleven Go client samples.1 parent 2114edc commit 86b0a52
12 files changed
Lines changed: 108 additions & 0 deletions
File tree
- modules/openapi-generator/src/main/resources/go
- samples
- client
- echo_api
- go-external-refs
- go
- others/go
- allof_multiple_ref_and_discriminator
- oneof-anyof-required
- oneof-discriminator-lookup
- petstore/go/go-petstore
- openapi3/client
- extensions/x-auth-id-alias/go-experimental
- petstore
- go-petstore-generateMarshalJSON-false
- go-petstore-withXml
- go
- go-petstore-aws-signature
- go-petstore
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
542 | 551 | | |
543 | 552 | | |
544 | 553 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments