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

Returning alternate response objects

Open nhi-vanye opened this issue 8 months ago • 1 comments

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...

nhi-vanye avatar Jun 26 '24 11:06 nhi-vanye