Open rcaught opened 1 month ago
You can in fact return anything that Flask accepts as a response type. If you return a different pydantic model it will function. The main use of the return type is actually the openapi schema generation. So far it has been rare enough that when I need it I have been able to cover it with the schema_extra argument to the decorator and in most, if not all of those cases, the response type has been something non-pydantic (such as binary data, etc). When possible I prefer to use the typing system before adding arguments to the decorator.
Do you have a specific use case in mind?
Instead of the Union type for response flexibility, have you considered defining the response model in the decorator (with the Union as a fall back)?
https://fastapi.tiangolo.com/tutorial/response-model/?h=annota#response_model-parameter https://fastapi.tiangolo.com/tutorial/response-model/?h=annota#invalid-return-type-annotations https://fastapi.tiangolo.com/tutorial/response-model/?h=annota#disable-response-model