Support for pretty printing JSON
It doesn't look like this is supported, it would be nice to have it as an option.
Currently, the generated code for JSON encoding a response looks like so:
return json.NewEncoder(w).Encode(response)
It could easily be pretty printed by doing something like:
e := json.NewEncoder(w)
e.SetIndent("", " ")
return e.Encode(response)
However, it doesn't look like there is any way to configure oapi-codegen to do this. I could of course add middleware to unmarshal/re-marshal the response, but that seems like unnecessary work.
Apologies if this is a duplicate, I didn't see any similar requests.
This would be something we'd want to make opt in via an output-options configuration.
It's something we'd be willing to review a PR for - but is probably low priority for us, as it's not something that's commonly done, and although useful for human consumers, results in slightly higher network traffic cost, so isn't as useful for API-API traffic
For anyone else reading this: https://www.jvt.me/posts/2024/09/16/api-pretty/ has a bit more info on why this wouldn't be recommended, but as mentioned, we'd still likely take a contribution for it
Thanks for the replies Jamie! I'm mildly interesting in adding it as an option so I may put a PR in the future. I appreciate the blog post too!