File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
tests/functional/event_handler/_pydantic Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments