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 caa368a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions rollbar/contrib/fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,20 @@ def get_installed_middlewares(app):
return middlewares


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)
):
def has_bare_routing(app_or_router: FastAPI | APIRouter):
if not isinstance(app_or_router, (FastAPI, APIRouter)):
return False

urls = [
getattr(app_or_router, 'openapi_url', None),
getattr(app_or_router, 'docs_url', None),
getattr(app_or_router, 'redoc_url', None),
getattr(app_or_router, '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 caa368a

Please sign in to comment.