Skip to content

Commit da8b517

Browse files
tests: improve coverage
1 parent 3d2cb7f commit da8b517

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Handler with tags for testing tag merging."""
2+
3+
from __future__ import annotations
4+
5+
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
6+
7+
app = APIGatewayRestResolver()
8+
9+
10+
@app.get("/tagged")
11+
def tagged_endpoint():
12+
"""Endpoint in tagged handler."""
13+
return {"tagged": True}
14+
15+
16+
# Override get_openapi_schema to include tags
17+
_original_get_openapi_schema = app.get_openapi_schema
18+
19+
20+
def get_openapi_schema_with_tags(**kwargs):
21+
kwargs.setdefault("tags", ["handler-tag"])
22+
return _original_get_openapi_schema(**kwargs)
23+
24+
25+
app.get_openapi_schema = get_openapi_schema_with_tags

tests/functional/event_handler/_pydantic/test_openapi_merge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,16 @@ def test_openapi_merge_add_schema():
338338
# THEN it should be included in the merged schema
339339
schema = merge.get_openapi_schema()
340340
assert "/external" in schema["paths"]
341+
342+
343+
def test_openapi_merge_tags_from_schema():
344+
# GIVEN an OpenAPIMerge without config tags
345+
merge = OpenAPIMerge(title="Tags API", version="1.0.0")
346+
347+
# WHEN discovering a handler that has tags in its schema
348+
merge.discover(path=MERGE_HANDLERS_PATH, pattern="**/tagged_handler.py")
349+
350+
# THEN schema tags should include tags from discovered handler
351+
schema = merge.get_openapi_schema()
352+
tag_names = [t["name"] for t in schema.get("tags", [])]
353+
assert "handler-tag" in tag_names

0 commit comments

Comments
 (0)