@@ -298,7 +298,7 @@ def handler(event, context):
298
298
return app .resolve (event , context )
299
299
300
300
# Also check the route configurations
301
- routes = app ._routes
301
+ routes = app ._static_routes
302
302
assert len (routes ) == 5
303
303
for route in routes :
304
304
if route .func == get_func :
@@ -1205,7 +1205,7 @@ def patch_func():
1205
1205
app .include_router (router )
1206
1206
1207
1207
# Also check check the route configurations
1208
- routes = app ._routes
1208
+ routes = app ._static_routes
1209
1209
assert len (routes ) == 5
1210
1210
for route in routes :
1211
1211
if route .func == get_func :
@@ -1647,3 +1647,26 @@ def get_message():
1647
1647
assert response ["multiValueHeaders" ]["Content-Type" ] == [content_types .APPLICATION_JSON ]
1648
1648
response_body = json .loads (response ["body" ])
1649
1649
assert response_body ["message" ] == "success"
1650
+
1651
+
1652
+ def test_route_match_prioritize_full_match ():
1653
+ # GIVEN a Http API V1, with a function registered with two routes
1654
+ app = APIGatewayRestResolver ()
1655
+ router = Router ()
1656
+
1657
+ @router .get ("/my/{path}" )
1658
+ def dynamic_handler () -> Response :
1659
+ return Response (200 , content_types .APPLICATION_JSON , json .dumps ({"hello" : "dynamic" }))
1660
+
1661
+ @router .get ("/my/path" )
1662
+ def static_handler () -> Response :
1663
+ return Response (200 , content_types .APPLICATION_JSON , json .dumps ({"hello" : "static" }))
1664
+
1665
+ app .include_router (router )
1666
+
1667
+ # WHEN calling the event handler with /foo/dynamic
1668
+ response = app (LOAD_GW_EVENT , {})
1669
+
1670
+ # THEN the static_handler should have been called, because it fully matches the path directly
1671
+ response_body = json .loads (response ["body" ])
1672
+ assert response_body ["hello" ] == "static"
0 commit comments