2# +==== BEGIN CatFeeder =================+
5# ...............)..(.')
7# ...............\(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
14# CREATION DATE: 23-01-2026
15# LAST Modified: 23:49:53 24-01-2026
17# This is the project in charge of making the connected cat feeder project work.
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: The decorator allowing the user to set and specify their own tags for the endpoint.
21# Metadata decorators for API endpoint documentation.
23# Provides decorators to add tags, descriptions, and other documentation metadata.
26# +==== END CatFeeder =================+
29from functools
import wraps
30from typing
import Callable
32from .decorator_constants
import TagCategory
36 """Set tags for endpoint categorization in API documentation.
39 tags: Tag categories to assign to the endpoint.
44 def decorator(func: Callable) -> Callable:
46 def wrapper(*args, **kwargs):
47 return func(*args, **kwargs)
50 tag_values = [tag.value
if isinstance(
51 tag, TagCategory)
else str(tag)
for tag
in tags]
52 setattr(wrapper,
"_tags", tag_values)
61 """Set description for the endpoint.
64 description: Description text for the endpoint.
69 def decorator(func: Callable) -> Callable:
71 def wrapper(*args, **kwargs):
72 return func(*args, **kwargs)
74 setattr(wrapper,
"_description", description)
77 if hasattr(func,
'_requires_auth'):
78 setattr(wrapper,
"_requires_auth", getattr(func,
"_requires_auth"))
79 if hasattr(func,
'_requires_admin'):
83 getattr(func,
"_requires_admin")
85 if hasattr(func,
'_public'):
86 setattr(wrapper,
"_public", getattr(func,
"_public"))
87 if hasattr(func,
'_security_level'):
91 getattr(func,
"_security_level")
93 if hasattr(func,
'_tags'):
94 setattr(wrapper,
"_tags", getattr(func,
"_tags"))
95 if hasattr(func,
'_summary'):
96 setattr(wrapper,
"_summary", getattr(func,
"_summary"))
97 if hasattr(func,
'_response_model'):
101 getattr(func,
"_response_model")
109 """Set summary for the endpoint.
112 summary: Summary text for the endpoint.
117 def decorator(func: Callable) -> Callable:
119 def wrapper(*args, **kwargs):
120 return func(*args, **kwargs)
122 setattr(wrapper,
"_summary", summary)
125 if hasattr(func,
'_requires_auth'):
126 setattr(wrapper,
"_requires_auth", getattr(func,
"_requires_auth"))
127 if hasattr(func,
'_requires_admin'):
131 getattr(func,
"_requires_admin")
133 if hasattr(func,
'_public'):
134 setattr(wrapper,
"_public", getattr(func,
"_public"))
135 if hasattr(func,
'_security_level'):
139 getattr(func,
"_security_level")
141 if hasattr(func,
'_tags'):
142 setattr(wrapper,
"_tags", getattr(func,
"_tags"))
143 if hasattr(func,
'_description'):
144 setattr(wrapper,
"_description", getattr(func,
"_description"))
145 if hasattr(func,
'_response_model'):
149 getattr(func,
"_response_model")
157 """Set custom operation ID for the endpoint.
160 operation_id: Custom operation ID for OpenAPI schema.
165 def decorator(func: Callable) -> Callable:
167 def wrapper(*args, **kwargs):
168 return func(*args, **kwargs)
171 wrapper.__name__ = operation_id
172 setattr(wrapper,
"_operation_id", operation_id)
174 setattr(wrapper,
"_operation_id_base", operation_id)
183 """Mark endpoint as belonging to user management category."""
184 return set_tags(TagCategory.USERS)(func)
188 """Mark endpoint as belonging to cat management category."""
189 return set_tags(TagCategory.CAT_MANAGEMENT)(func)
193 """Mark endpoint as belonging to front-end management category."""
194 return set_tags(TagCategory.FRONT_END)(func)
198 """Mark endpoint as belonging to front-end assets management category."""
199 return set_tags(TagCategory.FRONT_END_ASSETS)(func)
203 """Mark endpoint as belonging to OAuth category."""
204 return set_tags(TagCategory.OAUTH)(func)
208 """Mark endpoint as belonging to authentication category."""
209 return set_tags(TagCategory.AUTHENTICATION)(func)
213 """Mark endpoint as belonging to system category."""
214 return set_tags(TagCategory.SYSTEM)(func)
218 """Helper function to preserve existing metadata attributes."""
220 '_requires_auth',
'_requires_admin',
'_public',
'_testing_only',
221 '_security_level',
'_environment',
'_description',
'_summary',
222 '_response_model',
'_operation_id',
'_accepts_json_body',
223 '_json_body_description',
'_json_body_example',
'_requires_bearer_auth'
226 for attr
in metadata_attrs:
227 if hasattr(func, attr):
228 setattr(wrapper, attr, getattr(func, attr))