oapi-codegen
oapi-codegen copied to clipboard
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 usefmt.Sprintf
Co-authored-by: claude-sonnet:3.7-thinking
Closes #1914.