Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions fastapi_utils/cbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import pydantic
from fastapi import APIRouter, Depends
from fastapi.routing import APIRoute
from fastapi.routing import APIRoute, APIWebSocketRoute
from starlette.routing import Route, WebSocketRoute

PYDANTIC_VERSION = pydantic.VERSION
Expand Down Expand Up @@ -108,12 +108,16 @@ def _register_endpoints(router: APIRouter, cls: Type[Any], *urls: str) -> None:
_allocate_routes_by_method_name(router, url, function_members)
router_roles = []
for route in router.routes:
if not isinstance(route, APIRoute):
raise ValueError("The provided routes should be of type APIRoute")
if not isinstance(route, APIRoute) and not isinstance(route, APIWebSocketRoute):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, this is really nit pick but I prefer not (condition a or condition b)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem at all, i'll happily make the change :)

raise ValueError("The provided routes should be of type APIRoute or APIWebSocketRoute")

route_methods: Any = route.methods
cast(Tuple[Any], route_methods)
router_roles.append((route.path, tuple(route_methods)))
if isinstance(route, APIRoute):
route_methods: Any = route.methods
cast(Tuple[Any], route_methods)
router_roles.append((route.path, tuple(route_methods)))

if isinstance(route, APIWebSocketRoute):
router_roles.append((route.path, tuple(["WS"])))

if len(set(router_roles)) != len(router_roles):
raise Exception("An identical route role has been implemented more then once")
Expand Down