Skip to content

Commit

Permalink
KDP-1761: Workaround for FastAPI issue
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulVanSchayck committed Sep 25, 2023
1 parent 22e7f01 commit 44c7a28
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/covjson_pydantic/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Union

from pydantic import AwareDatetime
from pydantic import field_validator
from pydantic import model_validator
from pydantic import PositiveInt

Expand Down Expand Up @@ -74,6 +75,16 @@ class Domain(CovJsonBaseModel, extra="allow"):
axes: Axes
referencing: Optional[List[ReferenceSystemConnectionObject]] = None

# TODO: This is a workaround to allow domainType to work in strict mode, in combination with FastAPI.
# See: https://github.com/tiangolo/fastapi/discussions/9868
# And: https://github.com/KNMI/covjson-pydantic/issues/5
@field_validator("domainType", mode="before")
@classmethod
def value_to_enum(cls, v):
if isinstance(v, str):
return DomainType(v)
return v

@staticmethod
def check_axis(domain_type, axes, required_axes, allowed_axes, single_value_axes):
# Check required axes
Expand Down

0 comments on commit 44c7a28

Please sign in to comment.