Closed Letgamer closed 22 hours ago
Hmm it is quite hard to tell from here what might go wrong but the example here https://github.com/juhaku/utoipa/blob/master/examples/actix-web-scopes-binding/src/main.rs does work. If you just run it it will correctly set the handler under specific scopes.
Even if I add another module here called
mod api3 {
use actix_web::get;
#[utoipa::path(
responses(
(status = 200, description = "Foobar", body = str)
)
)]
#[get("/foobar")]
pub(super) async fn foobar() -> &'static str {
"foobar"
}
}
And then modify the example App definition as follows, it does work. However the web::get().to(...)
does not show up in the openapi.json as that is by design.
.service(
scope::scope("/api")
.service(crate::api3::foobar)
.route("/foo", web::get().to(|| async { "foo" }))
.route("/bar", web::get().to(|| async { "bar" }))
.service(scope::scope("/v1").service(api1::hello1))
.service(scope::scope("/v2").service(api2::hello2)),
)
Hey, I appreciate the Answer, thanks for the help :)
However the web::get().to(...) does not show up in the openapi.json as that is by design.
Just wanna point out that I am aware of that and that it is not my problem, I am talking about the:
.service(
scope::scope("/api/v1/accounts")
.wrap(auth.clone())
.service(route_changepwd)
That's from your example, that's the one I mean, so I am specifically talking about the .service that isn't working.
I am closing this issue as it seems more likely to be an issue on my side.
If I figure out the problem, I will post a solution here for the sake of completeness👍
Hey there, I am currently building a password manager backend API, here is the source code: https://github.com/Letgamer/rsPass
I have the following problem, and hopefully it isn't a dumb error on my side😅:
I have in the main.rs:
and in the routes.rs I have:
I then wanted to change the routes in the scopes to also automatically determine the path and request type as at the routes outside the scope, I tried using your example and changed the main.rs to:
And I added the macro to the route in routes.rs:
So that is now exactly the same as shown in your README.md: https://github.com/juhaku/utoipa/blob/master/utoipa-actix-web/README.md
The Route is correctly registered under /api/v1/accounts/changepwd but not in the openapi.json/swagger-ui. There the path is: So the scope is completely ignored.
I would appreciate any help, thanks in advance :)