forked from a2aproject/a2a-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_base.py
More file actions
39 lines (30 loc) · 1.26 KB
/
_base.py
File metadata and controls
39 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
def to_camel_custom(snake: str) -> str:
"""Convert a snake_case string to camelCase.
Args:
snake: The string to convert.
Returns:
The converted camelCase string.
"""
# First, remove any trailing underscores. This is common for names that
# conflict with Python keywords, like 'in_' or 'from_'.
if snake.endswith('_'):
snake = snake.rstrip('_')
return to_camel(snake)
class A2ABaseModel(BaseModel):
"""Base class for shared behavior across A2A data models.
Provides a common configuration (e.g., alias-based population) and
serves as the foundation for future extensions or shared utilities.
This implementation provides backward compatibility for camelCase aliases
by lazy-loading an alias map upon first use. Accessing or setting
attributes via their camelCase alias will raise a DeprecationWarning.
"""
model_config = ConfigDict(
# SEE: https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.populate_by_name
validate_by_name=True,
validate_by_alias=True,
serialize_by_alias=True,
alias_generator=to_camel_custom,
extra='forbid',
)