Skip to content

Commit d45fb4b

Browse files
committed
first working version of Fast_API__Client__Generator :)
1 parent d1fda47 commit d45fb4b

File tree

6 files changed

+523
-390
lines changed

6 files changed

+523
-390
lines changed

osbot_fast_api/client/Client__Generator__AST.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def _build_response_handling(self, endpoint: Schema__Endpoint__Contract,
481481
else:
482482
return '''
483483
# Return response data
484-
return result.json if result.json else result.text'''
484+
return result.json if result.json else result.text'''
485485

486486
def _generate_module_aggregator(self, module : Schema__Routes__Module, # Module to generate aggregator for
487487
route_classes : List[str] # Route classes to aggregate

osbot_fast_api/client/Fast_API__Client__Generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def generate_client(self, client_name: Optional[str] = None #
2121
contract = self.extract_contract()
2222
# Generate client code
2323
generator = Client__Generator__AST(contract = contract ,
24-
client_name = client_name )
24+
client_name = client_name )
2525

2626
return generator.generate_client_files()
2727

@@ -51,7 +51,7 @@ def print_client_summary(self): #
5151

5252
contract = self.extract_contract()
5353

54-
print(f"Service: {contract.service_name} v{contract.version}")
54+
print(f"Service: {contract.service_name} {contract.version}")
5555
print(f"Modules: {len(contract.modules)}")
5656
print(f"Total Endpoints: {len(contract.endpoints)}")
5757
print()

osbot_fast_api/client/Fast_API__Contract__Extractor.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ def extract_endpoint_contracts(self, route_data: Schema__Fast_API__Route
9595
for http_method in (http_methods or [Enum__Http__Method.GET]): # Create one contract per HTTP method
9696
operation_id = f"{http_method.value.lower()}__{method_name}" # Create operation_id with HTTP method prefix
9797

98-
endpoint = Schema__Endpoint__Contract(operation_id = operation_id ,
99-
path_pattern = http_path ,
100-
method = http_method ,
101-
route_method = method_name )
98+
endpoint = Schema__Endpoint__Contract(operation_id = operation_id ,
99+
path_pattern = http_path ,
100+
method = http_method ,
101+
route_method = method_name ,
102+
path_params = route_data.path_params , # Copy extracted params
103+
query_params = route_data.query_params ) # Copy extracted params
102104

103105
endpoint_func = None # Find the actual endpoint function (same for all methods)
104106
for route_obj in self.fast_api.app().routes:
@@ -109,15 +111,6 @@ def extract_endpoint_contracts(self, route_data: Schema__Fast_API__Route
109111
qualname = route_obj.endpoint.__qualname__ # Extract route class
110112
if '.' in qualname:
111113
endpoint.route_class = qualname.split('.')[0]
112-
#raise Exception("Code below can be deleted since have captured this on the Fast_API__Route__Extrator")
113-
# if hasattr(route_obj, 'path_regex'): # Extract path parameters
114-
# param_pattern = r'\{(\w+)\}'
115-
# path_params = re.findall(param_pattern, http_path)
116-
# for param_name in path_params:
117-
# endpoint.path_params.append(Schema__Endpoint__Param(name = param_name,
118-
# location = Enum__Param__Location.PATH,
119-
# param_type = 'str' ))
120-
# break
121114

122115
# Enhance with function signature analysis (same for all methods)
123116
if endpoint_func:

tests/unit/client/test_Client__Generator__AST.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test__build_response_handling(self): #
367367
assert code =="""\
368368
369369
# Return response data
370-
return result.json if result.json else result.text"""
370+
return result.json if result.json else result.text"""
371371

372372
assert "# Return response data" in code
373373
assert "return result.json if result.json else result.text" in code

0 commit comments

Comments
 (0)