Skip to content

Commit

Permalink
fix: ensure Entity objects return type as str
Browse files Browse the repository at this point in the history
close #433
  • Loading branch information
korikuzma committed Jul 17, 2024
1 parent aba012e commit 4aab91b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ga4gh/core/entity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Any, Dict, Annotated, Optional, Union, List
from enum import Enum

from pydantic import BaseModel, Field, RootModel, StringConstraints, model_serializer
from pydantic import BaseModel, Field, RootModel, StringConstraints, model_serializer, field_validator

from ga4gh.core import GA4GH_IR_REGEXP

Expand Down Expand Up @@ -175,6 +175,17 @@ class _Entity(BaseModel):
alternativeLabels: Optional[List[str]] = Field(None, description="Alternative name(s) for the Entity.")
extensions: Optional[List[Extension]] = Field(None, description="A list of extensions to the entity. Extensions are not expected to be natively understood, but may be used for pre-negotiated exchange of message attributes between systems.")

@field_validator("type")
def validate_type(cls, v: str | Enum) -> str:
"""Ensure that ``type`` field is represented as a string
:param v: Input values
:return: String representation of ``type`` field
"""
if isinstance(v, Enum):
v = v.value
return v


class _DomainEntity(_Entity):
"""An Entity that is specific to a particular biomedical domain such as disease,
Expand Down

0 comments on commit 4aab91b

Please sign in to comment.