Closed glademiller closed 5 years ago
No, I have missed something simple apparently. There was a breaking rewrite lately which got rid of all of whatever #[api_v2_operation]
was previously doing and moved to internal traits. The former had the luxury of ignoring function parameters whenever they won't serve any purpose in spec generation (such as Data<T>
or middleware::*
), whereas the latter doesn't and I forgot to implement the traits for these thingies after the rewrite (sigh).
I'll patch this up and release a patch version soon. Thanks for reporting this! :)
Thanks for your hard work.
Hey @glademiller, I've added empty schema impls for actix types in 7199f534fff8e5f34f90cfe87ade981bc473449f. With that change, the only thing that would cause the above error is middleware::auth::UserData
. If that's a type you own, then you can mark it with #[api_v2_schema(empty)]
and the error should go away. Can you try plugging the plugin again?
I have a problem using the commit you mentioned (7199f53).
error[E0277]: the trait bound `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>: actix_service::IntoNewService<_>` is not satisfied
--> src/bin/api_server.rs:46:5
|
46 | HttpServer::new(|| {
| ^^^^^^^^^^^^^^^ the trait `actix_service::IntoNewService<_>` is not implemented for `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>`
|
= note: required by `actix_web::server::HttpServer::<F, I, S, B>::new`
error[E0277]: the trait bound `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>: actix_service::IntoNewService<_>` is not satisfied
--> src/bin/api_server.rs:46:5
|
46 | / HttpServer::new(|| {
47 | | App::new()
48 | | .wrap_api()
49 | | .with_json_spec_at("/api")
50 | | .route("/import_data_set", web::post().to_async(import_data_set))
51 | | })
| |______^ the trait `actix_service::IntoNewService<_>` is not implemented for `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>`
|
= note: required by `actix_web::server::HttpServer`
error[E0277]: the trait bound `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>: actix_service::IntoNewService<_>` is not satisfied
--> src/bin/api_server.rs:52:10
|
52 | .bind((Ipv4Addr::LOCALHOST, PORT))
| ^^^^ the trait `actix_service::IntoNewService<_>` is not implemented for `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>`
error[E0277]: the trait bound `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>: actix_service::IntoNewService<_>` is not satisfied
--> src/bin/api_server.rs:46:5
|
46 | / HttpServer::new(|| {
47 | | App::new()
48 | | .wrap_api()
49 | | .with_json_spec_at("/api")
... |
52 | | .bind((Ipv4Addr::LOCALHOST, PORT))
53 | | .expect(&format!("Can not bind to port {}", PORT))
| |__________________________________________________________^ the trait `actix_service::IntoNewService<_>` is not implemented for `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>`
|
= note: required by `actix_web::server::HttpServer`
error[E0277]: the trait bound `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>: actix_service::IntoNewService<_>` is not satisfied
--> src/bin/api_server.rs:54:10
|
54 | .run()
| ^^^ the trait `actix_service::IntoNewService<_>` is not implemented for `paperclip_actix::App<actix_web::app_service::AppEntry, actix_http::body::Body>`
Here is the relevant part of my code. Note that before both struct ImportDataSet
and enum Message
, I put:
#[api_v2_schema]
#[derive(Serialize, Deserialize)]
#[api_v2_operation]
fn import_data_set() -> impl Future<Item = HttpResponse, Error = Error> {
// some code
}
fn main() {
use std::net::Ipv4Addr;
HttpServer::new(|| {
App::new()
.wrap_api()
.with_json_spec_at("/api")
.route("/import_data_set", web::post().to_async(import_data_set))
})
.bind((Ipv4Addr::LOCALHOST, PORT))
.expect(&format!("Can not bind to port {}", PORT))
.run()
.unwrap();
}
@Ploppz Once .wrap_api()
is called, the existing actix_web::App
gets transformed to a wrapper from the plugin. Now, .build()
method should be called to get the App
back. Try using:
HttpServer::new(|| {
App::new()
.wrap_api()
.with_json_spec_at("/api")
.route("/import_data_set", web::post().to_async(import_data_set))
.build()
})
Sorry I missed that. Thanks!
Sorry for the delayed response I've been away from a computer for the past little while. I annotated my UserData struct as requested and now have a different error in addition to the original. The new error is below and originates in my middleware which adds UserData to the extensions.
error[E0063]: missing fields `cyclic`, `data_type`, `description` and 9 other fields in initializer of `middleware::auth::UserData`
--> src/middleware/auth.rs:203:37
|
203 | req.extensions_mut().insert(UserData {
| ^^^^^^^^ missing `cyclic`, `data_type`, `description` and 9 other fields
@glademiller Wait, that's not right. The code above appears to be using paperclip::api_v2_schema
macro rather than paperclip::actix::api_v2_schema
(the former is used by codegen, whereas the latter is used by the plugin). Could you try importing the macro directly like so:
use paperclip::actix::api_v2_schema;
#[api_v2_schema]
pub struct UserData {
...
And, did you enable the actix
feature?
You are correct I was using paperclip::api_v2_schema using actix worked great thank you.
It seems like I am probably missing something simple. This is the error I am getting