@@ -316,6 +316,11 @@ def __init__(
316
316
"""
317
317
self .method = method .upper ()
318
318
self .path = "/" if path .strip () == "" else path
319
+
320
+ # OpenAPI spec only understands paths with { }. So we'll have to convert Powertools' < >.
321
+ # https://swagger.io/specification/#path-templating
322
+ self .openapi_path = re .sub (r"<(.*?)>" , lambda m : f"{{{ '' .join (m .group (1 ))} }}" , self .path )
323
+
319
324
self .rule = rule
320
325
self .func = func
321
326
self ._middleware_stack = func
@@ -435,7 +440,7 @@ def dependant(self) -> "Dependant":
435
440
if self ._dependant is None :
436
441
from aws_lambda_powertools .event_handler .openapi .dependant import get_dependant
437
442
438
- self ._dependant = get_dependant (path = self .path , call = self .func )
443
+ self ._dependant = get_dependant (path = self .openapi_path , call = self .func )
439
444
440
445
return self ._dependant
441
446
@@ -542,7 +547,7 @@ def _openapi_operation_summary(self) -> str:
542
547
Returns the OpenAPI operation summary. If the user has not provided a summary, we
543
548
generate one based on the route path and method.
544
549
"""
545
- return self .summary or f"{ self .method .upper ()} { self .path } "
550
+ return self .summary or f"{ self .method .upper ()} { self .openapi_path } "
546
551
547
552
def _openapi_operation_metadata (self , operation_ids : Set [str ]) -> Dict [str , Any ]:
548
553
"""
@@ -692,7 +697,7 @@ def _openapi_operation_return(
692
697
return {"schema" : return_schema }
693
698
694
699
def _generate_operation_id (self ) -> str :
695
- operation_id = self .func .__name__ + self .path
700
+ operation_id = self .func .__name__ + self .openapi_path
696
701
operation_id = re .sub (r"\W" , "_" , operation_id )
697
702
operation_id = operation_id + "_" + self .method .lower ()
698
703
return operation_id
@@ -1452,7 +1457,7 @@ def get_openapi_schema(
1452
1457
if result :
1453
1458
path , path_definitions = result
1454
1459
if path :
1455
- paths .setdefault (route .path , {}).update (path )
1460
+ paths .setdefault (route .openapi_path , {}).update (path )
1456
1461
if path_definitions :
1457
1462
definitions .update (path_definitions )
1458
1463
0 commit comments