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

Redirect response type error #827

Open
brussee opened this issue Jun 1, 2024 · 1 comment
Open

Redirect response type error #827

brussee opened this issue Jun 1, 2024 · 1 comment
Labels
question Further information is requested

Comments

@brussee
Copy link

brussee commented Jun 1, 2024

How should a redirect be done with poem_openapi?

Error:
poem::Response and poem_openapi::payload::Response<()> have similar names, but are actually distinct types

In:

#[poem_openapi::OpenApi]
impl IndexApi {
    #[oai(path = "/", method = "get")]
    async fn index(&self) -> poem::Result<poem_openapi::payload::Response<()>> {
        Ok(poem::IntoResponse::into_response(
            poem::web::Redirect::see_other("http:https://127.0.0.1:3000/api/v1/swagger"),
        ))
    }
}
@brussee brussee added the question Further information is requested label Jun 1, 2024
@brussee
Copy link
Author

brussee commented Jun 1, 2024

I've found this conversion as a workaround:

pub struct IndexApi;

#[poem_openapi::OpenApi]
impl IndexApi {
    #[oai(path = "/", method = "get")]
    async fn index(&self) -> poem::Result<()> {
        Err(poem::error::Error::from_response(
            poem::IntoResponse::into_response(poem::web::Redirect::see_other(
                "http:https://127.0.0.1:3000/api/v1/swagger".to_owned(),
            )),
        ))
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant