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

Add names to routes #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions fastapi_crudrouter/core/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
)

prefix = str(prefix if prefix else self.schema.__name__).lower()
item_name = self.schema.__name__.lower()
prefix = self._base_path + prefix.strip("/")
tags = tags or [prefix.strip("/").capitalize()]

Expand All @@ -60,6 +61,7 @@ def __init__(
response_model=Optional[List[self.schema]], # type: ignore
summary="Get All",
dependencies=get_all_route,
name=f"get_all_{item_name}",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name=f"get_all_{item_name}",
name=f"get_all_{prefix}",

Copy link
Author

Choose a reason for hiding this comment

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

We need item_name because prefix is a path prefix for the API and includes slashes. Which made me realise that using prefix for item might also end up with slashes, so I'll change item name to the lowercased schema class name.

)

if create_route:
Expand All @@ -70,6 +72,7 @@ def __init__(
response_model=self.schema,
summary="Create One",
dependencies=create_route,
name=f"create_one_{item_name}",
)

if delete_all_route:
Expand All @@ -80,6 +83,7 @@ def __init__(
response_model=Optional[List[self.schema]], # type: ignore
summary="Delete All",
dependencies=delete_all_route,
name=f"delete_all_{item_name}",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name=f"delete_all_{item_name}",
name=f"delete_all_{prefix}",

)

if get_one_route:
Expand All @@ -91,6 +95,7 @@ def __init__(
summary="Get One",
dependencies=get_one_route,
error_responses=[NOT_FOUND],
name=f"get_one_{item_name}",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name=f"get_one_{item_name}",
name=f"get_one_{prefix}",

)

if update_route:
Expand All @@ -102,6 +107,7 @@ def __init__(
summary="Update One",
dependencies=update_route,
error_responses=[NOT_FOUND],
name=f"update_one_{item_name}",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name=f"update_one_{item_name}",
name=f"update_one_{prefix}",

)

if delete_one_route:
Expand All @@ -113,6 +119,7 @@ def __init__(
summary="Delete One",
dependencies=delete_one_route,
error_responses=[NOT_FOUND],
name=f"delete_one_{item_name}",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name=f"delete_one_{item_name}",
name=f"delete_one_{prefix}",

)

def _add_api_route(
Expand Down