GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
606 stars 110 forks source link

Missing instances OpenApiFromRequest #71

Closed ssadler closed 2 years ago

ssadler commented 2 years ago

Hi, I'm trying to set up rocket_okapi in my project and getting some errors:

// I can't find this instance (rocket_db_pools::Connection<T>)
the trait `OpenApiFromRequest<'_>` is not implemented for `rocket_db_pools::Connection<db::MyDB>`

// There is an instance for &State<T> but T has to have 'static lifetime... I'm not sure how that is possible?
the trait `OpenApiFromRequest<'_>` is not implemented for `&rocket::State<MyState>`

// I can find this instance* but I'm not sure why I'm getting this for MyType, since it derives Deserialize and JsonSchema
// * https://docs.rs/rocket_okapi/0.8.0-rc.1/rocket_okapi/request/trait.OpenApiFromData.html
the trait `OpenApiFromData<'_>` is not implemented for `rocket::serde::json::Json<MyType>`

And this one which is not a missing instance, I think it has to do with using #[macro_use] extern crate rocket;:

expected enum `rocket_http::method::Method`, found enum `rocket::http::Method`
note: perhaps two different versions of crate `rocket_http` are being used?

Package versions:

schemars = "0.8"                                                 
okapi = { version = "0.7.0-rc.1" }                               
rocket_okapi = { version = "0.8.0-rc.1", features = ["swagger"] }

[dependencies.rocket]                                            
git = "https://github.com/SergioBenitez/Rocket"                  
version = "0.5.0-rc.1"                                           
features = ["json"]                                              

[dependencies.rocket_db_pools]                                   
git = "https://github.com/SergioBenitez/Rocket"                  
version = "0.1.0-rc"                                             
features = ["sqlx_postgres"]                                     

Thanks...

ralpha commented 2 years ago

You are using Rocket's master branch, not the creates.io version (for which the current version is made).

So you have to use Rockets version from create.io (not git, there are some small differences) OR @ThouCheese recently made a fork that works on Rockets master branch: https://github.com/ThouCheese/okapi

But note that you would have to use the same version everywhere (both Rocket and Okapi to avoid conflicts like these), this is important when using more then 1 crate with these dependencies (usually only for bigger projects).

ssadler commented 2 years ago

Oh right, makes sense. Thanks for the quick reply, hope this might help someone else Googling.