diff --git a/docs/openapi.json b/docs/openapi.json index d6f00c7f..43065685 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -302,17 +302,16 @@ }, "responses": { "200": { - "description": "Successful Response", + "description": "Feedback received and stored", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FeedbackResponse" } } - }, - "response": "Feedback received and stored" + } }, - "400": { + "401": { "description": "Missing or invalid credentials provided by client", "content": { "application/json": { @@ -323,7 +322,7 @@ } }, "403": { - "description": "User is not authorized", + "description": "Client does not have permission to access resource", "content": { "application/json": { "schema": { @@ -332,6 +331,16 @@ } } }, + "500": { + "description": "User feedback can not be stored", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, "422": { "description": "Validation Error", "content": { @@ -1181,6 +1190,37 @@ "title": "DatabaseConfiguration", "description": "Database configuration." }, + "ErrorResponse": { + "properties": { + "detail": { + "additionalProperties": { + "type": "string" + }, + "type": "object", + "title": "Detail" + } + }, + "type": "object", + "required": [ + "detail" + ], + "title": "ErrorResponse", + "description": "Model representing error response for query endpoint.", + "examples": [ + { + "detail": { + "cause": "Failed to handle request to https://bam-api.res.ibm.com/v2/text", + "response": "Error while validation question" + } + }, + { + "detail": { + "cause": "Invalid conversation ID 1237-e89b-12d3-a456-426614174000", + "response": "Error retrieving conversation history" + } + } + ] + }, "FeedbackCategory": { "type": "string", "enum": [ diff --git a/src/app/endpoints/feedback.py b/src/app/endpoints/feedback.py index 82263b4a..c91b6857 100644 --- a/src/app/endpoints/feedback.py +++ b/src/app/endpoints/feedback.py @@ -11,6 +11,7 @@ from auth.interface import AuthTuple from configuration import configuration from models.responses import ( + ErrorResponse, FeedbackResponse, StatusResponse, UnauthorizedResponse, @@ -23,17 +24,23 @@ router = APIRouter(prefix="/feedback", tags=["feedback"]) auth_dependency = get_auth_dependency() -# Response for the feedback endpoint feedback_response: dict[int | str, dict[str, Any]] = { - 200: {"response": "Feedback received and stored"}, - 400: { + 200: { + "description": "Feedback received and stored", + "model": FeedbackResponse, + }, + 401: { "description": "Missing or invalid credentials provided by client", "model": UnauthorizedResponse, }, 403: { - "description": "User is not authorized", + "description": "Client does not have permission to access resource", "model": ForbiddenResponse, }, + 500: { + "description": "User feedback can not be stored", + "model": ErrorResponse, + }, } diff --git a/src/models/responses.py b/src/models/responses.py index c00d61cd..c5a319d2 100644 --- a/src/models/responses.py +++ b/src/models/responses.py @@ -470,3 +470,28 @@ class ConversationsListResponse(BaseModel): ] } } + + +class ErrorResponse(BaseModel): + """Model representing error response for query endpoint.""" + + detail: dict[str, str] + + model_config = { + "json_schema_extra": { + "examples": [ + { + "detail": { + "response": "Error while validation question", + "cause": "Failed to handle request to https://bam-api.res.ibm.com/v2/text", + }, + }, + { + "detail": { + "response": "Error retrieving conversation history", + "cause": "Invalid conversation ID 1237-e89b-12d3-a456-426614174000", + }, + }, + ] + } + }