Skip to content

Use response models #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Use response models #519

wants to merge 2 commits into from

Conversation

gadomski
Copy link
Member

Related Issue(s):

Description:

WIP PR to allow response models to actually be used to validate outgoing objects. Currently just has a failing test.

We currently wrap every response in a Response of some sort:

def _wrap_response(resp: Any, response_class: Type[Response]) -> Response:
if isinstance(resp, Response):
return resp
elif resp is not None:
return response_class(resp)
else: # None is returned as 204 No Content
return Response(status_code=HTTP_204_NO_CONTENT)

This short-circuits the response model system in FastAPI: https://github.com/tiangolo/fastapi/blob/40df42f5c7d92815ceeb546df60256dacb3eed57/fastapi/routing.py#L241-L244

To fix, we'll need to pass through raw JSON objects as-is if response models are enabled.

PR Checklist:

  • Code is formatted and linted (run pre-commit run --all-files)
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@gadomski gadomski added this to the 2.5.0 milestone Jan 31, 2023
@gadomski
Copy link
Member Author

gadomski commented May 9, 2023

Closing as OBE #555.

@gadomski gadomski closed this May 9, 2023
@gadomski gadomski removed this from the 2.5.0 milestone May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response models are not being used to validate responses
1 participant