Skip to content

fix: Generate StrEnum types for enums #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/update-a2a-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jobs:
--use-default-kwarg \
--use-one-literal-as-default \
--class-name A2A \
--use-standard-collections
--use-standard-collections \
--use-subclass-enum
echo "Codegen finished."

- name: Create Pull Request with Updates
Expand Down
3 changes: 2 additions & 1 deletion development.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ uv run datamodel-codegen \
--use-default-kwarg \
--use-one-literal-as-default \
--class-name A2A \
--use-standard-collections
--use-standard-collections \
--use-subclass-enum
```
6 changes: 3 additions & 3 deletions src/a2a/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class A2A(RootModel[Any]):
root: Any


class In(Enum):
class In(str, Enum):
"""
The location of the API key. Valid values are "query", "header", or "cookie".
"""
Expand Down Expand Up @@ -484,7 +484,7 @@ class JSONRPCSuccessResponse(BaseModel):
"""


class Role(Enum):
class Role(str, Enum):
"""
Message sender's role
"""
Expand Down Expand Up @@ -731,7 +731,7 @@ class TaskResubscriptionRequest(BaseModel):
"""


class TaskState(Enum):
class TaskState(str, Enum):
"""
Represents the possible states of a Task.
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,3 +1487,12 @@ def test_a2a_error_validation_and_serialization() -> None:
invalid_data: dict[str, Any] = {'code': -99999, 'message': 'Unknown error'}
with pytest.raises(ValidationError):
A2AError.model_validate(invalid_data)


def test_subclass_enums() -> None:
"""validate subtype enum types"""
assert "cookie" == In.cookie

assert "user" == Role.user

assert "working" == TaskState.working