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

response in api decorator can not have Exception class

Open changja88 opened this issue 2 years ago • 1 comments

@member_router.get('', response={200: Member, 401: AuthenticationError}, auth=AuthBearer()) Above code is not working beacuase of AuthenticationError which is not inherited from BaseModel(pydantic) I hope there should be a exception class inheried from BaseModel to make doc

Thanks

changja88 avatar Nov 21 '23 04:11 changja88

Hi @changja88

the expectation for the response is that you define them as schemas (with fields)

in your case you can do something like this:


class UnauthorizedResponse(Schema):
    details: str

...


@member_router.get('', response={200: Member, 401: UnauthorizedResponse}, auth=AuthBearer())

vitalik avatar Nov 21 '23 08:11 vitalik