From 926ff867251104c0e94c0e5ad8da63b5b905a7f8 Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Mon, 18 Dec 2023 15:00:44 +0100 Subject: [PATCH] fix(event-handler): fix operation tags schema generation (#3528) --- aws_lambda_powertools/event_handler/api_gateway.py | 2 +- aws_lambda_powertools/event_handler/openapi/models.py | 2 +- tests/functional/event_handler/test_openapi_params.py | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/aws_lambda_powertools/event_handler/api_gateway.py b/aws_lambda_powertools/event_handler/api_gateway.py index 3b7f788b519..172b57de277 100644 --- a/aws_lambda_powertools/event_handler/api_gateway.py +++ b/aws_lambda_powertools/event_handler/api_gateway.py @@ -559,7 +559,7 @@ def _openapi_operation_metadata(self, operation_ids: Set[str]) -> Dict[str, Any] # Ensure tags is added to the operation if self.tags: - operation["tags"] = [{"name": tag for tag in self.tags}] + operation["tags"] = self.tags # Ensure summary is added to the operation operation["summary"] = self._openapi_operation_summary() diff --git a/aws_lambda_powertools/event_handler/openapi/models.py b/aws_lambda_powertools/event_handler/openapi/models.py index 2ad8dbf2263..e886e30d396 100644 --- a/aws_lambda_powertools/event_handler/openapi/models.py +++ b/aws_lambda_powertools/event_handler/openapi/models.py @@ -380,7 +380,7 @@ class Config: # https://swagger.io/specification/#operation-object class Operation(BaseModel): - tags: Optional[List[Tag]] = None + tags: Optional[List[str]] = None summary: Optional[str] = None description: Optional[str] = None externalDocs: Optional[ExternalDocumentation] = None diff --git a/tests/functional/event_handler/test_openapi_params.py b/tests/functional/event_handler/test_openapi_params.py index 4ac425c9fdd..1fbdbef2bde 100644 --- a/tests/functional/event_handler/test_openapi_params.py +++ b/tests/functional/event_handler/test_openapi_params.py @@ -10,7 +10,6 @@ Parameter, ParameterInType, Schema, - Tag, ) from aws_lambda_powertools.event_handler.openapi.params import ( Body, @@ -119,7 +118,7 @@ def handler( assert get.summary == "Get Users" assert get.operationId == "GetUsers" assert get.description == "Get paginated users" - assert get.tags == [Tag(name="Users")] + assert get.tags == ["Users"] parameter = get.parameters[0] assert parameter.required is False @@ -378,7 +377,7 @@ def handler(): assert len(get.tags) == 1 tag = get.tags[0] - assert tag.name == "Users" + assert tag == "Users" def test_openapi_with_excluded_operations(): @@ -421,7 +420,7 @@ def handler(): schema = app.get_openapi_schema() tags = schema.paths["/example-resource"].put.tags assert len(tags) == 1 - assert tags[0].name == "Example" + assert tags[0] == "Example" def test_create_header():