oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

fix(client): correctly marshal `text/plain` requests

Open jamietanna opened this issue 9 months ago • 0 comments

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

Closes #1914.

jamietanna avatar May 10 '25 15:05 jamietanna