@@ -64,7 +64,13 @@ def __init__(self, config: APIConfig):
6464 self .config = config
6565
6666 def extract_api_schema (self , js_file_path : str ) -> List [Dict [str , Any ]]:
67- """Extract the API schema using multiple fallback methods with file caching."""
67+ """
68+ Extract API schema from JavaScript file using Node.js parsing with fallback.
69+
70+ Attempts Node.js parsing first for accurate JavaScript evaluation, then falls back
71+ to Python regex-based parsing if Node.js is unavailable. Handles complex JavaScript
72+ structures including nested objects, arrays, and dynamic expressions.
73+ """
6874 file_path = Path (js_file_path ).resolve ()
6975 current_mtime = file_path .stat ().st_mtime
7076
@@ -192,7 +198,13 @@ def restore_patterns(obj: Any) -> Any:
192198 return self ._extract_basic_structure (schema_str )
193199
194200 def _extract_basic_structure (self , content : str ) -> List [Dict [str , Any ]]:
195- """Extract basic structure when JSON parsing fails."""
201+ """
202+ Extract basic API structure using regex patterns as Node.js fallback.
203+
204+ Performs comprehensive regex-based parsing of JavaScript API schema definitions
205+ when Node.js is unavailable. Handles multiple JavaScript syntax patterns,
206+ object property extraction, and nested structure parsing with error recovery.
207+ """
196208 endpoints = []
197209
198210 paths = self ._PATH_PATTERN .findall (content )
@@ -235,7 +247,13 @@ def _extract_basic_structure(self, content: str) -> List[Dict[str, Any]]:
235247 def flatten_api_endpoints (
236248 self , schema : List [Dict [str , Any ]], parent_path : str = ""
237249 ) -> List [Dict [str , Any ]]:
238- """Flatten the nested API schema structure."""
250+ """
251+ Flatten nested API endpoints into a list of individual endpoints with path resolution.
252+
253+ Recursively processes nested API schema structures, resolves path hierarchies,
254+ normalizes endpoint definitions, and creates flat endpoint list suitable for
255+ OpenAPI specification generation. Handles complex nesting and path inheritance.
256+ """
239257 endpoints = []
240258
241259 for item in schema :
@@ -363,7 +381,13 @@ def _build_standardized_components(self) -> Dict[str, Any]:
363381 return components
364382
365383 def _get_standardized_schemas (self ) -> Dict [str , Any ]:
366- """Generate comprehensive standardized OpenAPI schemas for common Proxmox API data types and structures."""
384+ """
385+ Generate comprehensive standardized schema definitions for OpenAPI specification.
386+
387+ Creates reusable schemas for common Proxmox patterns including error responses,
388+ task objects, resource identifiers, and validation patterns. High line count
389+ due to detailed schema definitions required for comprehensive API coverage.
390+ """
367391 schemas = {
368392 # Standard response schemas
369393 "ProxmoxError" : {
@@ -549,7 +573,13 @@ def _get_standardized_error_responses(self) -> Dict[str, Any]:
549573 }
550574
551575 def _convert_endpoint_to_openapi (self , endpoint : Dict [str , Any ]) -> Dict [str , Any ]:
552- """Convert a Proxmox API endpoint to OpenAPI format with comprehensive parameter and response handling."""
576+ """
577+ Convert a Proxmox API endpoint to OpenAPI format with comprehensive parameter and response handling.
578+
579+ Processes endpoint methods, parameters, and responses to create complete OpenAPI
580+ path item objects. Handles parameter validation, response schema generation,
581+ security requirements, and standardized error responses for each HTTP method.
582+ """
553583 path_item = {}
554584
555585 for method , method_info in endpoint ["methods" ].items ():
@@ -848,7 +878,13 @@ def _convert_type_to_openapi(
848878 def _get_standardized_schema_ref (
849879 self , param_info : Dict [str , Any ]
850880 ) -> Dict [str , Any ]:
851- """Determine appropriate schema reference for parameter based on name patterns and type information."""
881+ """
882+ Determine appropriate schema reference for parameter based on name patterns and type information.
883+
884+ Analyzes parameter characteristics including name patterns, type information,
885+ and descriptions to select appropriate standardized schema references.
886+ Provides consistent validation and documentation across similar parameters.
887+ """
852888 param_type = param_info .get ("type" , "string" )
853889 pattern = param_info .get ("pattern" , "" )
854890 description = param_info .get ("description" , "" ).lower ()
@@ -1048,7 +1084,13 @@ def get_pbs_config() -> APIConfig:
10481084
10491085
10501086def main () -> int :
1051- """Main function demonstrating unified parser usage for both PVE and PBS API generation."""
1087+ """
1088+ Main function demonstrating unified parser usage for both PVE and PBS API generation.
1089+
1090+ Handles command-line argument parsing, API type configuration, schema extraction,
1091+ endpoint flattening, OpenAPI specification generation, and output file creation.
1092+ High complexity due to comprehensive workflow orchestration and error handling.
1093+ """
10521094 if len (sys .argv ) < 4 :
10531095 print ("Usage: python unified_parser.py <api_type> <input_js_file> <output_dir>" )
10541096 print (" api_type: 'pve' or 'pbs'" )
0 commit comments