swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
335 stars 17 forks source link

[Feature] Possibility to define multiple success status. Add HTTPMultiResponder #177

Closed benbender closed 9 months ago

benbender commented 9 months ago

[There was a discussion about having the ability to define multiple success status. As it was proposed in discussion and it seemed to possibly be forgotten, I'll add this here as an issue.]

It's easy to specify multiple error statuses with u.SetExpectedErrors(...), and I can override the "success" status with nethttp.SuccessStatus(http.StatusCreated) when creating the handler. But: my API needs to return either 200 or 201 status based on some logic, with essentially the same JSON response.

I cannot find a way to do that nicely: I don't want to override the whole response serialization, and I don't think treating 200 or 201 as an "error" is the right approach. Any ideas?

Originally posted by @haimgel in https://github.com/swaggest/rest/discussions/153

haimgel commented 9 months ago

@benbender, this hasn't been forgotten. I opened a PR to implement this in #155 (already merged).

benbender commented 9 months ago

Oh, sorry, I only searched for HTTPMultiResponder and couldn't find a PR. Thx for your outstanding work! <3