dmontagu / fastapi-utils

Reusable utilities for FastAPI
MIT License
1.89k stars 165 forks source link

Don't infer `response_model` for invalid types #260

Closed nzig closed 1 year ago

nzig commented 1 year ago

It is possible for inferring_router to raise an exception if a function uses a return type that is not a valid response_model. An example is an endpoint that returns Response instead of letting FastAPI construct one.

This PR fixes that by only inferring the response_model if the return annotation is a valid response_model.

Fixes #229 Fixes #172

nzig commented 1 year ago

This is now builtin to FastAPI (https://fastapi.tiangolo.com/release-notes/#0890), so I'm closing this PR.