Skip to content

Commit e705964

Browse files
jamietannaclaude-sonnet:3.7-thinkingJamie Tannamromaszewiczclaude
authored
fix(client): correctly marshal text/plain requests (#1975)
* 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]>
1 parent 524f053 commit e705964

File tree

8 files changed

+508
-4
lines changed

8 files changed

+508
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# yaml-language-server: $schema=../../../../configuration-schema.json
2+
package: issue1914
3+
output: client.gen.go
4+
generate:
5+
client: true
6+
models: true

0 commit comments

Comments
 (0)