Fastapi: [BUG] Swagger `Try it out` missing parameters when using `include_router` with a url variable in the prefix

Created on 28 Oct 2019  路  5Comments  路  Source: tiangolo/fastapi

Describe the bug
When a router is added to an app using include_router, and the prefix parameter contains a url variable (e.g. '/{account}/devices'), the variable is not included as a parameter in the swagger documentation.

To Reproduce
Steps to reproduce the behavior:

  1. Create a router using APIRouter()
  2. Add the router to the app using app.include_router with a prefix.
  3. Add a url variable to the prefix
app.include_router(
    device_router,
    prefix="/{account}/devices"
)
  1. Launch the application and browse to /docs
  2. Expand the path and click the Try it out button

Expected behavior
When browsing the swagger docs on http://localhost:8080/docs, I want to be able to use the Try it out feature.

Screenshots
image

Environment:

  • OS: [e.g. Linux / macOS]
  • FastAPI Version: 0.38.1
  • Python version: 3.7

Additional context

bug

Most helpful comment

Yeah this sounds like a bug in the openapi schema generation. Probably worth a check to see if updating to 0.42 fixes it.

All 5 comments

Didn't test but should you copy the openapi.json output to the swagger editor website, do you get the same issue? this is just to get a sense if the generated schema looks correct.
Also, don't think it will make any difference but latest version is 0.42.0

Yeah this sounds like a bug in the openapi schema generation. Probably worth a check to see if updating to 0.42 fixes it.

I'll try both of those suggestions @euri10 & @dmontagu.

I have another app on 0.39.1 that I tried this with and it looks like it is working.
I'm going to test a couple more cases before closing this.

Thanks for the help here everyone! :clap: :bow:

I assume you solved your problem, so thanks for reporting back and closing the issue :+1:

Was this page helpful?
0 / 5 - 0 ratings