Commit e705964
fix(client): correctly marshal
* fix(client): correctly marshal `text/plain` requests
As noted in #1914, there are cases where trying to interact with a
`text/plain` endpoint that requires input, for instance when receiving a
UUID, may not render correctly.
We should first check if the type is a `Stringer`, aka has a `String()`
method, and use that - otherwise use `fmt.Sprintf("%v", ...)` to
generate a string type.
Via [0], we can make sure that we wrap the generated type in an empty
`interface`, so we can perform the type assertion.
This also adds a test case to validate the functionality for:
- a UUID, which has a `String()` method
- a `float32`, which is a primitive datatype that needs to use
`fmt.Sprintf`
Co-authored-by: claude-sonnet:3.7-thinking <[email protected]>
Closes #1914.
[0]: https://www.jvt.me/posts/2025/05/10/go-type-assertion-concrete/
* fix(client): add three-tier text/plain body marshaling for #1914
For text/plain request bodies, the generated client code now:
1. Checks if the body type implements fmt.Stringer and uses String()
2. Falls back to fmt.Sprintf("%v", body) for primitive types
3. Returns an error for complex types (objects, arrays, composed
schemas), directing the user to implement a String() method
Adds Schema.IsPrimitive() to distinguish primitive OpenAPI types
(string, integer, number, boolean) from complex ones at codegen time.
Closes #1914.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Apply suggestion from @gaiaz-iusipov
Co-authored-by: Gaiaz Iusipov <[email protected]>
* Update generated files
---------
Co-authored-by: claude-sonnet:3.7-thinking <[email protected]>
Co-authored-by: Jamie Tanna <[email protected]>
Co-authored-by: Marcin Romaszewicz <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Marcin Romaszewicz <[email protected]>
Co-authored-by: Gaiaz Iusipov <[email protected]>text/plain requests (#1975)1 parent 524f053 commit e705964
File tree
8 files changed
+508
-4
lines changed- internal/test
- issues/issue-1914
- strict-server/client
- pkg/codegen
- templates
8 files changed
+508
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments