From a4e7c96c8a98e3a5f7b9e384a014e4853053d75b Mon Sep 17 00:00:00 2001 From: seriaati Date: Sat, 21 Sep 2024 20:59:55 +0800 Subject: [PATCH] Fix validation error on ShiyuDefenseMonster --- genshin/models/zzz/chronicle/challenge.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/genshin/models/zzz/chronicle/challenge.py b/genshin/models/zzz/chronicle/challenge.py index 700ff379..6bf34ed5 100644 --- a/genshin/models/zzz/chronicle/challenge.py +++ b/genshin/models/zzz/chronicle/challenge.py @@ -63,9 +63,16 @@ class ShiyuDefenseMonster(APIModel): id: int name: str - weakness: ZZZElementType = Aliased("weak_element_type") + weakness: typing.Union[ZZZElementType, int] = Aliased("weak_element_type") level: int + @pydantic.validator("weakness", pre=True) + def __convert_weakness(cls, v: int) -> typing.Union[ZZZElementType, int]: + try: + return ZZZElementType(v) + except ValueError: + return v + class ShiyuDefenseNode(APIModel): """Shiyu Defense node model."""