Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set multiple cookie headers in an OpenAPI route #895

Open
musjj opened this issue Oct 11, 2024 · 0 comments
Open

Set multiple cookie headers in an OpenAPI route #895

musjj opened this issue Oct 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@musjj
Copy link

musjj commented Oct 11, 2024

Description of the feature

Current, if you try to set multiple Set-Cookie headers, only the last one is used:

struct Api;

#[derive(ApiResponse)]
pub enum FooResponse {
    #[oai(status = 200)]
    SetCookie(
        #[oai(header = "Set-Cookie")] String,
        #[oai(header = "Set-Cookie")] String,
    ),
}

#[OpenApi]
impl Api {
    #[oai(path = "/foo", method = "get")]
    pub async fn foo(&self) -> FooResponse {
        FooResponse::SetCookie("foo=1".into(), "bar=1".into())
    }
}
$ curl -I http://localhost:3000/foo
HTTP/1.1 200 OK
set-cookie: bar=1
date: Fri, 11 Oct 2024 16:21:35 GMT

This is a limitation of the current OpenAPI spec: OAI/OpenAPI-Specification#1237.

But is there a way to work around this? Is there a way to set additional headers in the response object beyond what is annotated in the struct?

@musjj musjj added the enhancement New feature or request label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant