netwo-io / apistos

Actix-web wrapper for automatic OpenAPI 3.0 documentation generation.
MIT License
148 stars 6 forks source link

Can't use wrap() function in resource #95

Closed hiromaily closed 5 months ago

hiromaily commented 5 months ago

I'm using apistos with actix-web.

Part of my service settings are using configure()

  .service(
      web::scope("/admin")
          .app_data(admin_data.clone()) // admin state // maybe divide it into each configuration level
          .configure(routes::api_admin_login_config)
          .configure(routes::api_admin_users_config)
          .configure(routes::api_admin_users_id_config),
  )

Part of configuration is

pub fn api_admin_users_id_config(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::resource("/users/{user_id}")
            .route(web::get().to(handlers::admin::get_user))
            .route(web::put().to(handlers::admin::update_user))
            .route(web::delete().to(handlers::admin::delete_user))
            .wrap(from_fn(auth_jwt::mw_admin_auth_jwt)),
    );
}

However, .wrap(from_fn(auth_jwt::mw_admin_auth_jwt)) can't work here though it works using actix_web::web. Error message says,

the trait bound `apistos::web::Resource<actix_web::Resource<impl ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse<impl MessageBody>, Error = actix_web::Error, InitError = ()>>>: apistos::internal::definition_holder::DefinitionHolder` is not satisfied
the trait `apistos::internal::definition_holder::DefinitionHolder` is implemented for `apistos::web::Resource`

I need to set warp() with middleware at each resource but I don't know how.

rlebran commented 5 months ago

Hi, I will have a look asap. Thanks for the report.

rlebran commented 5 months ago

Fix has been merged to main. A release will be available soon.

hiromaily commented 5 months ago

@rlebran Thanks so much!