Skip to content

fix(event-handler): operation tags are now string to correct schema generation #3528

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

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/event_handler/openapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/event_handler/test_openapi_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Parameter,
ParameterInType,
Schema,
Tag,
)
from aws_lambda_powertools.event_handler.openapi.params import (
Body,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down