Skip to content

Commit

Permalink
Fixed #398 FastAPI integration fails if docs are disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmorell committed Jul 12, 2024
1 parent 8493ac0 commit 0b02508
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions rollbar/contrib/fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,19 @@ def get_installed_middlewares(app):


def has_bare_routing(app_or_router):
expected_app_routes = 4
expected_router_routes = 0

if (
isinstance(app_or_router, FastAPI)
and expected_app_routes != len(app_or_router.routes)
) or (
isinstance(app_or_router, APIRouter)
and expected_router_routes != len(app_or_router.routes)
):
if not isinstance(app_or_router, (FastAPI, APIRouter)):
return False

urls = [
app_or_router.__getattribute__('openapi_url', None),
app_or_router.__getattribute__('docs_url', None),
app_or_router.__getattribute__('redoc_url', None),
app_or_router.__getattribute__('swagger_ui_oauth2_redirect_url', None),
]

for route in app_or_router.routes:
if route is None or route.path in urls:
continue
return False

return True

0 comments on commit 0b02508

Please sign in to comment.