django-ninja icon indicating copy to clipboard operation
django-ninja copied to clipboard

feat: support returning pydantic model as result

Open mh-alahdadian opened this issue 1 year ago • 6 comments

allow returning pydantic model as result and pass converting and validation

mh-alahdadian avatar Nov 17 '24 17:11 mh-alahdadian

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")

vitalik avatar Nov 22 '24 12:11 vitalik

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

mh-alahdadian avatar Nov 24 '24 11:11 mh-alahdadian

well coverage shows that it never actually calls the needed line

vitalik avatar Dec 06 '24 18:12 vitalik

well coverage shows that it never actually calls the needed line

fixed it too I'm not sure why github pipeline is not running on pull request when I push new changes?

mh-alahdadian avatar Dec 18 '24 09:12 mh-alahdadian

could we merge it ?

mh-alahdadian avatar Jan 11 '25 07:01 mh-alahdadian

@vitalik , I have some more ideas to implement, but I think you are so busy to maintain and accept PRs , do you have any substitute ?

mh-alahdadian avatar Jan 22 '25 12:01 mh-alahdadian