-
-
Notifications
You must be signed in to change notification settings - Fork 925
Handle specially API endpoints with only one successful response status code #276
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I'm not a fan of the ClientWithResponses. I use the Client and unmarshal myself. Each response code can produce a different result. This code is very naive, and just generates that list dutifully. We'd have to do some type analysis to squash responses with the same response schema. So then, how do we know to name it "successResponse" or something like that. You'd get one field for some responses, another for some more, and you'd still have to switch on response code. I'm honestly unsure of how to make this API look nice. |
I like that generator makes a boilerplate here. Maybe the easiest would be to parse into something like:
So no need to figure out what is the meaning of each response type, just expose it directly. Also, it does not matter which status code it came through (if somebody cares, they can check the |
What about using a map with status code as key and error struct as value. That gives us more flexibility for working with errors. Currently, it's really hard to get the right errors by status code.
|
I am not sure what why would a map help here? For every response there would always be just one entry in that map? So that can then be simply two fields instead of a map, a |
When I generate API I get such response structure for our calls, example:
I would prefer something like:
First, I would not have to know exactly which 2xx status code is returned. Second, I can call
response.StatusCode()
to obtain the status code, there is no point in having that also part of the field name. Given that this for generating HTTP API it is pretty reasonable to assume 2xx codes are success and everything else is failure. So if there is only one successful response status code defined in the API, make it simply be namedSuccess
. And if all errors have the same type, collapse them as well intoError
.Currently I have to have such ugly code to make sense of this:
Alternatively, there could be some methods on the struct (for backwards compatibility) which would be returning those success or error values.
The text was updated successfully, but these errors were encountered: