Skip to content

Commit

Permalink
fix: messageBody validate
Browse files Browse the repository at this point in the history
  • Loading branch information
xncbf committed May 30, 2022
1 parent b68890f commit 86337e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rcs-pydantic"
version = "0.2.0"
version = "0.2.1"
description = ""
authors = ["xncbf <xncbf12@gmail.com>"]
keywords = ["pydantic", "rcs", "fastapi"]
Expand Down
11 changes: 9 additions & 2 deletions rcs_pydantic/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, List, Optional, Union

from pydantic import BaseModel, Field, validator
from pydantic.error_wrappers import ValidationError

from . import enums
from .errors import ErrorCodeEnum, LegacyErrorCodeEnum
Expand Down Expand Up @@ -501,7 +502,7 @@ class MessageInfo(BaseModel):
postBackId: Optional[str] = Field(max_length=40)
postBackData: Optional[str] = Field(max_length=2048)
displayText: Optional[str] = Field(max_length=200)
messageBody: Union[TextMessageInfo, UserLocationInfo, FileMessageInfo, None]
messageBody: Optional[str]
"""
eventType이message인 경우에만 설정
- 텍스트 메시지의 경우 샘플
Expand Down Expand Up @@ -535,7 +536,13 @@ class MessageInfo(BaseModel):
def check_message_body(cls, v, values, **kwargs):
if v:
if values["eventType"] == enums.EventTypeEnum.MESSAGE:
return json.loads(v)
v = json.loads(v)
for basemodel in [TextMessageInfo, UserLocationInfo, FileMessageInfo]:
try:
return basemodel(**v)
except ValidationError:
pass
raise ValueError("Invalid messageBody")
raise ValueError("messageBody is not allowed")

userContact: str = Field(max_length=40)
Expand Down

0 comments on commit 86337e0

Please sign in to comment.