Skip to content
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

feat: support returning pydantic model as result #1338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mh-alahdadian
Copy link

@mh-alahdadian mh-alahdadian commented Nov 17, 2024

allow returning pydantic model as result and pass converting and validation

@vitalik
Copy link
Owner

vitalik commented Nov 22, 2024

Hi @mh-alahdadian

could you also add test case for multiple response codes ?

@router.get("/check_pydantic", response={200: UserModel, 201: Message})
def check_pydantic(request):
    if something:
          return 201, {"message": "Created"}
    return 200, UserModel(id=1, user_name="John")

@mh-alahdadian
Copy link
Author

Hi @mh-alahdadian

could you also add test case for multiple response codes ?

@router.get("/check_pydantic", response={200: UserModel, 201: Message})
def check_pydantic(request):
    if something:
          return 201, {"message": "Created"}
    return 200, UserModel(id=1, user_name="John")

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants