@@ -316,6 +316,11 @@ def __init__(
316316 """
317317 self .method = method .upper ()
318318 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+
319324 self .rule = rule
320325 self .func = func
321326 self ._middleware_stack = func
@@ -435,7 +440,7 @@ def dependant(self) -> "Dependant":
435440 if self ._dependant is None :
436441 from aws_lambda_powertools .event_handler .openapi .dependant import get_dependant
437442
438- self ._dependant = get_dependant (path = self .path , call = self .func )
443+ self ._dependant = get_dependant (path = self .openapi_path , call = self .func )
439444
440445 return self ._dependant
441446
@@ -542,7 +547,7 @@ def _openapi_operation_summary(self) -> str:
542547 Returns the OpenAPI operation summary. If the user has not provided a summary, we
543548 generate one based on the route path and method.
544549 """
545- return self .summary or f"{ self .method .upper ()} { self .path } "
550+ return self .summary or f"{ self .method .upper ()} { self .openapi_path } "
546551
547552 def _openapi_operation_metadata (self , operation_ids : Set [str ]) -> Dict [str , Any ]:
548553 """
@@ -692,7 +697,7 @@ def _openapi_operation_return(
692697 return {"schema" : return_schema }
693698
694699 def _generate_operation_id (self ) -> str :
695- operation_id = self .func .__name__ + self .path
700+ operation_id = self .func .__name__ + self .openapi_path
696701 operation_id = re .sub (r"\W" , "_" , operation_id )
697702 operation_id = operation_id + "_" + self .method .lower ()
698703 return operation_id
@@ -1452,7 +1457,7 @@ def get_openapi_schema(
14521457 if result :
14531458 path , path_definitions = result
14541459 if path :
1455- paths .setdefault (route .path , {}).update (path )
1460+ paths .setdefault (route .openapi_path , {}).update (path )
14561461 if path_definitions :
14571462 definitions .update (path_definitions )
14581463
0 commit comments