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

openapi doesn't ignore Rocket request guards? #119

Closed
ChronosWS opened this issue Oct 18, 2022 · 2 comments
Closed

openapi doesn't ignore Rocket request guards? #119

ChronosWS opened this issue Oct 18, 2022 · 2 comments

Comments

@ChronosWS
Copy link

I have an API implemented thus:

#[openapi]
#[get("/job/namespaces/<namespace>/users/<user_id>")]
async fn get_user_jobs(
    namespace: &str,
    user_id: UserId,
    job_state: &State<JobSharedState>,
    _user_authorization: UserAuthorization
) -> Json<Option<JobData>> {
    let mut job_state = job_state.write().await;
    Json(logic::get_user_jobs(namespace, user_id, &mut job_state)
        .await)
}

This generates an error:

the trait bound `UserAuthorization: OpenApiFromRequest<'_>` is not satisfied
the following other types implement trait `OpenApiFromRequest<'a>`:
  &'r ContentType
  &'r Host<'r>
  &'r Limits
  &'r Route
  &'r rocket::Config
  &'r rocket::State<T>
  &'r rocket::http::Accept
  &'r rocket::http::CookieJar<'r>
and 8 others

I feel like this UserAuthorization - which exists to implement an authentication guard - should not be part of the API spec. But it also seems like this might be a common pattern so maybe I am unaware of how to make okapi do the right thing?

@ralpha
Copy link
Collaborator

ralpha commented Oct 19, 2022

If you just want to ignore it: See #113 (recent addition, not released yet, only in master)

But you might also want to take a look at this example: https://github.com/GREsau/okapi/tree/master/examples/secure_request_guard/src
This example shows how you can implement different authentication methods into the spec. This way you can still use the try buttons in the swagger/rapidoc. So definitely worth a look in my opinion.

@ChronosWS
Copy link
Author

Thank you! I knew I must have missed something!

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

No branches or pull requests

2 participants