Closed HerrMuellerluedenscheid closed 2 years ago
Or should I rather implement OpenApiFromRequest<'_>
for db::PgConnection
to somehow return nothing?
I also have the same problem and I'm not sure how to solve it. One solution that could possibly get around this is to have all the routes that do the actual logic under the route /api/stuff/...
and maybe have a seperate base route that goes like /openapi/stuff...
and have some sort of dummy functions that return the same structs.
For example for your case you could try having a seperate function like this:
#[openapi]
#[rocket::get("/openapi/<id>")
async fn retrieve(id: i32) -> Result<Json<Artist>, NotFound<Json<ApiError>>> {
return Json(Artist { ... })
}
Yes this is a very roundabout way of doing it and I'm also looking if there's anything else possible
Okay now I just feel stupid. The solution is in the README if you scroll a bit lower in the FAQ and click on "Implement OpenApiFromRequest
for Diesel DB"
Lol! I didn't see that either. I didn't really go through the README.md but went straight to the documentation and searched for diesel
. If possible it would be worth considering to move the FAQs to some place where they can be found by keyword search.
Haha, yeah had to put it somewhere so added it there. I'll add it to Rust Docs too so it shows up in searches there too.
I was trying to use
okapi
in a project that usesdiesel
for database management. Basically as in this example: https://github.com/TmLev/crud-rest-api-rust-rocket-diesel-postgres/blob/65783a859f8b8afe42861cf1a210401a9c24cee9/src/main.rsTaking for example this signature:
okapi
would have to skip the first argumentconnection: PgConnection
. I didn't find how to do that if it's possible. Is it possible?thanks in advance!