django-ninja
django-ninja copied to clipboard
Returning alternate response objects
I have an endpoint that returns a profile details
@router.get("/profile/{id}", response=ProfileDetailsSchema)
to avoid leaking PPI, the ProfileDetailsSchema does not contain any fields containing personal details.
PPI details are accessed via
@router.get("/profile/{id}/private", response=PrivateProfileSchema)
But to simplify the API I'd like to use a single endpoint that looks at the request.user to see if they should have access to the PPI or not.
How would I specify the response=
field to allow for either ProfileDetailsSchema
or PrivateProfileSchema
and then return the appropriate response...