Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use scope together with docs #415

Open
oriontvv opened this issue Apr 13, 2022 · 5 comments
Open

Unable to use scope together with docs #415

oriontvv opened this issue Apr 13, 2022 · 5 comments

Comments

@oriontvv
Copy link

oriontvv commented Apr 13, 2022

Hi, folk!
It looks like we can't use common preffix for a scope and default ui path swagger_ui_at("/-/docs").
For example, uncommenting lines will break docs:

App::new()
    .wrap_api()
    // .service(web::resource("/-/liveness").route(web::post().to(echo_pet)))
    // .service(
    //     web::scope("/-").service(web::resource("/metrics").route(web::post().to(echo_pet))),
    // )
    .with_json_spec_at("/api/spec/v2")
    .with_swagger_ui_at("/-/docs")
    .build()
@tiagolobocastro
Copy link
Collaborator

Hey!
By break the docs you mean the swagger endpoint is no longer available?

@oriontvv
Copy link
Author

@tiagolobocastro Yep, swagger_ui's docs handler doesn't respond.

@tiagolobocastro
Copy link
Collaborator

tiagolobocastro commented Apr 18, 2022

I can't quite remember this properly but with actix when you define a scope (eg: for "/-"), unless you have guards (eg to check for a headers etc), you can't at a later stage stage add a handler for something that falls within "/-" outside of the scope? (which is what .with_swagger_ui_at("/-/docs") does)

@rlebran
Copy link
Contributor

rlebran commented Apr 19, 2022

This is a known limitation of actix and this PR should fix the issue: actix/actix-web#2264

@lightsing
Copy link

you need to re-organize it as

App::new()
    .wrap_api()
    .with_json_spec_at("/api/spec/v2")
    .with_swagger_ui_at("/-/docs")
    .service(web::resource("/-/liveness").route(web::post().to(echo_pet)))
    .service(
       web::scope("/-").service(web::resource("/metrics").route(web::post().to(echo_pet))),
    )
    .build()

the scope router will swallow all traffic and return 404 if there's no match.
thus, you need to insert the route before scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants