FIX: Remove envelope response pattern and add Pydantic response models#76
Draft
FIX: Remove envelope response pattern and add Pydantic response models#76
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Note: This PR builds off of #75 and should not be reviewed until that has be reviewed and merged
{errorCode, errorMessage, payload}envelope from every REST response. Endpoints now return their DTO (or primitive) directly.response_model=to every handler inapp/api/v1/so Swagger and/openapi.jsonrender accurate, per-endpoint response schemas instead of{}.raise APIException(code, msg, status)withraise HTTPException(status_code=code, detail=msg)across handlers andapp/dependencies.py. Error bodies now follow FastAPI's default{"detail": "..."}shape.app/api/responses.py(thesuccess_response/error_responsehelpers andAPIExceptionclass),ApiResultResponsefromapp/schemas/common.py, and the matching exception handler inapp/main.py.Motivation
The envelope pattern was tracked as a bug in #32 and react-squirrel#77. Two problems with the old design:
-> dict, FastAPI couldn't generate accurate response examples —/docsshowed generic{}for every endpoint. Withresponse_model=attached, Swagger now shows the actual field shape for every response, and any consumer regenerating types from/openapi.jsongets correct TypeScript interfaces.success_response(x)on the backend) and hand-deserialize (response.data.payloadon the frontend) for no added signal. Removing it simplifies both ends and eliminates a class of bugs where handlers forgot to wrap.The frontend work to drop the
apiClient.tsunwrap layer is react-squirrel#77 and needs to deploy with with this change.Closes #32
Response shape diff (example)
Before —
GET /v1/snapshots:{ "errorCode": 0, "errorMessage": null, "payload": [{ "id": "...", "title": "...", "pvCount": 42 }] }After —
GET /v1/snapshots:Pre-merge checklist