File tree Expand file tree Collapse file tree 3 files changed +69
-82
lines changed
Expand file tree Collapse file tree 3 files changed +69
-82
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ uv run datamodel-codegen \
3535 --use-subclass-enum \
3636 --base-class a2a._base.A2ABaseModel \
3737 --field-constraints \
38- --snake-case-field
38+ --snake-case-field \
39+ --no-alias
3940
4041echo " Formatting generated file with ruff..."
4142uv run ruff format " $GENERATED_FILE "
Original file line number Diff line number Diff line change 11from pydantic import BaseModel , ConfigDict
2+ from pydantic .alias_generators import to_camel
3+
4+
5+ def to_camel_custom (snake : str ) -> str :
6+ """Convert a snake_case string to camelCase.
7+
8+ Args:
9+ snake: The string to convert.
10+
11+ Returns:
12+ The converted camelCase string.
13+ """
14+ # First, remove any trailing underscores. This is common for names that
15+ # conflict with Python keywords, like 'in_' or 'from_'.
16+ if snake .endswith ('_' ):
17+ snake = snake .rstrip ('_' )
18+ return to_camel (snake )
219
320
421class A2ABaseModel (BaseModel ):
@@ -13,4 +30,5 @@ class A2ABaseModel(BaseModel):
1330 validate_by_name = True ,
1431 validate_by_alias = True ,
1532 serialize_by_alias = True ,
33+ alias_generator = to_camel_custom ,
1634 )
You can’t perform that action at this time.
0 commit comments