Skip to content

Better handling of HTTP redirects #2512

Closed
@mitar

Description

@mitar

It looks to me like the OpenAPI specification does not have enough of support for HTTP redirects returned from the API. For example, we have /user/me endpoint which returns a HTTP redirect to something like /user/<id> based on the user associated with the access token used for the API call. We allow only GET requests on /user/me while we allow a full set of HTTP methods on /user/<id> (like creation of the user, deletion, updating).

Now the issue is how to describe this /user/me endpoint. If we just specify that it returns a 307 HTTP status code and Location header (which is probably the closest to what exactly the call is returning) then this seems to not be well supported by codegen clients. Some codegen clients have to know how to parse the response, but there is no information about the response schema after redirect, or in other words, there is no information in the spec about where will Location always point to, so client cannot prepare for that in advance: only dynamically after Location header is received it could check to which API endpoint it is pointing to and parse response using that API endpoint's response handling code. But if one wants to have all API responses handled statically, this is not possible.

Moreover, in browsers, you cannot really obtain Location header for 3xx responses using fetch. So you cannot manually traverse the redirect here. Which means that the client in the browser cannot really know where it is going in the redirect and only after it already receives the response it might be able to figure out where it got redirected and how to parse the response.

In summary, I think OpenAPI specification is missing a critical component to specify redirects: where does redirects go to? Is it to some other endpoint and which one, or is it something completely else. By knowing to which endpoint it is going, codegen client could know how to parse API responses after redirect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpSupporting HTTP features and interactions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions