11from typing import List , Union
2+
3+ from pydantic_core import PydanticUndefinedType , PydanticUndefined
4+
5+ from osbot_utils .utils .Dev import pprint
6+
7+ from osbot_fast_api .client .schemas .Schema__Endpoint__Param import Schema__Endpoint__Param
8+ from osbot_fast_api .client .schemas .enums .Enum__Param__Location import Enum__Param__Location
29from osbot_utils .type_safe .type_safe_core .collections .Type_Safe__List import Type_Safe__List
310from osbot_fast_api .schemas .consts__Fast_API import FAST_API_DEFAULT_ROUTES_PATHS
411from osbot_utils .type_safe .Type_Safe import Type_Safe
@@ -61,16 +68,18 @@ def create_api_route(self, route : Union[APIRoute, Route] , # Fa
6168 http_methods = [] # Convert methods to enum
6269 for method in sorted (route .methods ):
6370 http_methods .append (Enum__Http__Method (method ))
64- method_name = Safe_Str__Id (route .name )
65- route_class = self .extract_route_class (route ) # Determine route class if from Routes__* pattern
71+ method_name = Safe_Str__Id (route .name )
72+ route_class = self .extract__route_class (route ) # Determine route class if from Routes__* pattern
73+ path_params = self .extract__path_params (route = route )
6674 if type (route_class ) is APIRoute : # only the APIRoute class has the
6775 route_tags = route .tags # .tags method
6876 else :
69- route_tags = None
77+ route_tags = None
7078 return Schema__Fast_API__Route (http_path = path ,
7179 method_name = method_name ,
7280 http_methods = http_methods ,
7381 route_type = Enum__Route__Type .API_ROUTE ,
82+ path_params = path_params ,
7483 route_tags = route_tags ,
7584 route_class = route_class ,
7685 is_default = self .is_default_route (str (path )))
@@ -112,6 +121,16 @@ def extract_mount_routes(self, mount: Mount , # Mo
112121
113122 return routes
114123
124+ @type_safe
125+ def extract__path_params (self , route : APIRoute ):
126+ path_params = []
127+ for param in route .dependant .path_params :
128+ path_params .append (Schema__Endpoint__Param (name = param .name ,
129+ location = Enum__Param__Location .PATH ,
130+ param_type = param .type_ ,
131+ required = param .required ))
132+ return path_params
133+
115134 @type_safe
116135 def create_websocket_route (self , route : APIWebSocketRoute , # WebSocket route
117136 path : Safe_Str__Fast_API__Route__Prefix
@@ -138,7 +157,7 @@ def _combine_paths(self, prefix : Safe_Str__Fast_API__Route__Prefix, # Prefix
138157 def is_default_route (self , path : str ) -> bool : # Check if default route
139158 return path in FAST_API_DEFAULT_ROUTES_PATHS
140159
141- def extract_route_class (self , route ) -> Safe_Str__Id : # Extract class name (in most cases it will be something like Routes__* )
160+ def extract__route_class (self , route ) -> Safe_Str__Id : # Extract class name (in most cases it will be something like Routes__* )
142161 route_class = None
143162 if hasattr (route , 'endpoint' ):
144163 if hasattr (route .endpoint , '__self__' ): # first try to get the class name (if inside a class)
0 commit comments