Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
response.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: response.py
14# CREATION DATE: 23-01-2026
15# LAST Modified: 1:12:12 24-01-2026
16# DESCRIPTION:
17# This is the project in charge of making the connected cat feeder project work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: This is the file containing the decorators in charge of providing details for the responses of the endpoints.
21# Response decorators for API endpoints.
22#
23# Provides decorators to set response models and response-related metadata.
24# /STOP
25# // AR
26# +==== END CatFeeder =================+
27"""
28
29from functools import wraps
30from typing import Callable, Any, Optional
31
32
33def set_response_model(model: Optional[Any]) -> Callable:
34 """Set response model for the endpoint.
35
36 Args:
37 model: Pydantic model class or None to disable response model.
38
39 Returns:
40 Decorator function.
41 """
42 def decorator(func: Callable) -> Callable:
43 @wraps(func)
44 def wrapper(*args, **kwargs):
45 return func(*args, **kwargs)
46
47 setattr(wrapper, "_response_model", model)
48
49 # Preserve any existing metadata
50 if hasattr(func, '_requires_auth'):
51 setattr(wrapper, "_requires_auth", getattr(func, "_requires_auth"))
52 if hasattr(func, '_requires_admin'):
53 setattr(wrapper, "_requires_admin",
54 getattr(func, "_requires_admin"))
55 if hasattr(func, '_public'):
56 setattr(wrapper, "_public", getattr(func, "_public"))
57 if hasattr(func, '_security_level'):
58 setattr(wrapper, "_security_level",
59 getattr(func, "_security_level"))
60 if hasattr(func, '_tags'):
61 setattr(wrapper, "_tags", getattr(func, "_tags"))
62 if hasattr(func, '_description'):
63 setattr(wrapper, "_description", getattr(func, "_description"))
64 if hasattr(func, '_summary'):
65 setattr(wrapper, "_summary", getattr(func, "_summary"))
66
67 return wrapper
68 return decorator
Callable set_response_model(Optional[Any] model)
Definition response.py:33