11from collections import defaultdict
22from dataclasses import dataclass , field
3+ from functools import cached_property
4+ import re
35from typing import Literal
46
57from .schemas import ModelSchema , Property , SchemaData , UnionSchema
@@ -84,7 +86,7 @@ def get_raw_definition(self) -> str:
8486 required = self .required ,
8587 schema_data = self .body_schema ,
8688 )
87- return prop .get_param_defination ()
89+ return prop .get_param_definition ()
8890
8991 def get_endpoint_definition (self ) -> str :
9092 prop = Property (
@@ -93,7 +95,7 @@ def get_endpoint_definition(self) -> str:
9395 required = not bool (self .allowed_models ),
9496 schema_data = self .body_schema ,
9597 )
96- return prop .get_param_defination ()
98+ return prop .get_param_definition ()
9799
98100
99101@dataclass (kw_only = True )
@@ -139,6 +141,17 @@ def name(self) -> str:
139141 self .method , self .path .replace ("{" , "" ).replace ("}" , "" ).replace ("/" , "_" )
140142 )
141143
144+ @cached_property
145+ def eval_path (self ) -> str :
146+ """Actual string used to construct the path with param names"""
147+ params_in_path = re .findall (r"\{([^\}]+)\}" , self .path )
148+ param_name_map = {param .name : param .prop_name for param in self .path_params }
149+ path = self .path
150+ for param in params_in_path :
151+ if param in param_name_map :
152+ path = path .replace (f"{{{ param } }}" , f"{{{ param_name_map [param ]} }}" )
153+ return path
154+
142155 @property
143156 def path_params (self ) -> list [Parameter ]:
144157 return [param for param in self .parameters if param .param_in == "path" ]
0 commit comments