Skip to content

Commit 98b3242

Browse files
committed
Update typing to support snake_case and camelCase through __getattr__
1 parent a80f14f commit 98b3242

File tree

4 files changed

+93
-53
lines changed

4 files changed

+93
-53
lines changed

scripts/generate_types.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ uv run datamodel-codegen \
3333
--use-one-literal-as-default \
3434
--class-name A2A \
3535
--use-standard-collections \
36-
--use-subclass-enum
36+
--use-subclass-enum \
37+
--snake-case-field \
38+
--no-alias
39+
3740

3841
echo "Codegen finished successfully."

src/a2a/pydantic_base.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
"""A2A Pydantic Base Model with shared configuration."""
22

3+
from typing import Any
4+
35
from pydantic import BaseModel, ConfigDict
4-
from pydantic.alias_generators import to_snake
6+
from pydantic.alias_generators import to_camel, to_snake
57

68

79
class A2ABaseModel(BaseModel):
810
"""Base model for all A2A types with shared configuration."""
911

1012
model_config = ConfigDict(
11-
alias_generator=to_snake,
13+
alias_generator=to_camel,
1214
populate_by_name=True,
13-
arbitrary_types_allowed=True,
15+
frozen=True,
1416
)
17+
18+
def __getattr__(self, name: str) -> Any:
19+
snake = to_snake(name)
20+
if hasattr(self, snake):
21+
return getattr(self, snake)
22+
raise AttributeError(
23+
f'{type(self).__name__} object has no attribute {name!r}'
24+
)

0 commit comments

Comments
 (0)