This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Select response model specified in responses based on status code #2022
Labels
You can continue the conversation there. Go to discussion →
First check
Example
Here's a self-contained minimal, reproducible, example with my use case:
Description
In contradiction to the documentation for the 503 status code, the sample code will result in a reply
{"default": "yes"}
without any validation errors.It would be nice if fastapi could select the correct model depending on the status code declared in the response object.
The solution you would like
The code should result in an
OtherModel
being serialized instead of the default one based on the selected status code.Describe alternatives you've considered
Using
JSONResponse
manually is tedious and error prone. At least using a model directly in JSONResponse would be nice instead of having to convert it manually to dict.Environment
The text was updated successfully, but these errors were encountered: