DOCSP-56401-[PYTHON]-Add-OpenAPI-Response-Documentation-to-FastAPI-Endpoints #88
Conversation
| summary="Search movies using MongoDB Search.", | ||
| responses={ | ||
| **SEARCH_ENDPOINT_RESPONSES, | ||
| 400: FASTAPI_400_MISSING_SEARCH_PARAMS |
There was a problem hiding this comment.
i think this is overwriting the FASTAPI_400_INVALID_SEARCH_OPERATOR key
There was a problem hiding this comment.
yep. from Augment:
Issue: The /api/v1/movies/search endpoint can return TWO different 400 errors, but only ONE is documented in the OpenAPI schema.
Why: In the code, the responses dict has duplicate 400 keys, and the second one overwrites the first:
responses={
**SEARCH_ENDPOINT_RESPONSES, # Contains: 400: INVALID_SEARCH_OPERATOR
400: FASTAPI_400_MISSING_SEARCH_PARAMS # This OVERWRITES the above!
}Result: When you expand the GET /api/v1/movies/search endpoint below and look at > the "400" response, you'll only see documentation for "Missing search parameters" - the "Invalid search operator" error is missing!
The two 400 errors that can occur:
Invalid search operator: "Invalid search operator 'invalid'. The search operator must be one of {'must', 'should', 'mustNot', 'filter'}."
Missing search parameters: "At least one search parameter must be provided." (This is the only one documented)
There was a problem hiding this comment.
You are right. I am going to use the oneOf schema to fix that. I can see both in the api docs page, now with the fix.
What is Augment? 👀
There was a problem hiding this comment.
an AI coding tool: https://www.augmentcode.com
| } | ||
|
|
||
| VECTOR_SEARCH_RESPONSES = { | ||
| 400: CUSTOM_400_VOYAGE_SERVICE_UNAVAILABLE, |
There was a problem hiding this comment.
wouldn't a svc unavailable be a 503?
There was a problem hiding this comment.
Correct. Hmmm I noticed that the error responses are actually mixed. I will address that in the next commit.
- addressed differences in python and express backend responses
cbullinger
left a comment
There was a problem hiding this comment.
This looks great! Nice job. My only suggestion might be to update the PR description so it includes the additional work standardizing responses
What this PR Does?
This PR improves the OpenAPI Response Documentation. The current API documentation at /docs was incomplete due to the endpoints not being fully documented. This PR adds the responses parameter to all of the api endpoints in the
movies.pyfile and adds a helper module to ease future maintenance.Changes Made
src/utils/response_docs.pyerror_response.pyfile:Testing
No breaking changes. The only changes are to the codebase readability and the /docs page
Jira
This ticket originated from this suggestion.