@@ -155,6 +155,21 @@ def {operation_id}(mist_session: _APISession{code_path_params}{multipart}) -> _A
155155 """
156156
157157
158+ def keep_deprecated (max_deprecation_version : str , current_version : str ) -> bool :
159+ """
160+ Determine if deprecated functions should be kept based on version comparison.
161+ """
162+ current = current_version .split ("." )
163+ max_version = max_deprecation_version .split ("." )
164+
165+ for i , req in enumerate (max_version ):
166+ if current [int (i )] < req :
167+ break
168+ if current [int (i )] > req :
169+ return False
170+ return True
171+
172+
158173def fprint (message : str ) -> None :
159174 """Print a formatted message with left justification to 80 characters."""
160175 print (f"{ message } " .ljust (80 ))
@@ -568,48 +583,6 @@ def _gen_uri(endpoint_path: str) -> str:
568583# HTTP method function generators (CRUD operations)
569584
570585
571- def _create_get_deprecated_device_events (
572- operation_id : str ,
573- endpoint_path : str ,
574- path_params : list ,
575- query_params : list ,
576- ) -> str :
577- """
578- Create deprecated version of DeviceEvents GET functions for backward compatibility.
579- Handles the renaming from DevicesEvents to DeviceEvents.
580-
581- Args:
582- operation_id: Current OpenAPI operation ID (DeviceEvents*)
583- endpoint_path: API endpoint path
584- path_params: Path parameters list
585- query_params: Query parameters list
586-
587- Returns:
588- str: Generated deprecated function code
589- """
590- code = ""
591- code_path_params , desc_path_params = _gen_code_params (path_params , operation_id )
592- code_query_params , desc_query_params = _gen_code_params (query_params , operation_id )
593- code_query = _gen_query_code (query_params )
594- code_desc = _gen_description (operation_id , [], desc_path_params , desc_query_params )
595-
596- # Generate old operation ID for the deprecated function
597- old_operation_id = operation_id .replace ("DeviceEvents" , "DevicesEvents" , 1 )
598- code += FUNCTION_GET_DEPRECATED_TEMPLATE .format (
599- version_deprecated = "0.45.0" ,
600- version_final = "0.60.0" ,
601- version_current = version ,
602- operation_id = operation_id ,
603- old_operation_id = old_operation_id ,
604- code_path_params = code_path_params ,
605- code_query_params = code_query_params ,
606- code_desc = code_desc ,
607- uri = _gen_uri (endpoint_path ),
608- query_code = code_query ,
609- )
610- return code
611-
612-
613586def _create_get_deprecated (
614587 operation_id : str ,
615588 tags : list ,
@@ -633,6 +606,9 @@ def _create_get_deprecated(
633606 str: Generated deprecated function code
634607 """
635608 code = ""
609+ if not keep_deprecated (version_final , VERSION ):
610+ print (f"Skipping deprecated function { operation_id } as per version settings." )
611+ return code
636612 code_path_params , desc_path_params = _gen_code_params (path_params , operation_id )
637613 code_query_params , desc_query_params = _gen_code_params (query_params , operation_id )
638614 code_query = _gen_query_code (query_params )
@@ -644,7 +620,7 @@ def _create_get_deprecated(
644620 code += FUNCTION_GET_DEPRECATED_TEMPLATE .format (
645621 version_deprecated = version_deprecated ,
646622 version_final = version_final ,
647- version_current = version ,
623+ version_current = VERSION ,
648624 operation_id = new_operation_id ,
649625 old_operation_id = operation_id ,
650626 code_path_params = code_path_params ,
@@ -678,14 +654,7 @@ def _create_get(
678654 """
679655 code = ""
680656 has_deprecated = False
681- # Create deprecated version for DeviceEvents functions (backward compatibility)
682- if operation_id .startswith ("DeviceEvents" ):
683- has_deprecated = True
684- code += _create_get_deprecated_device_events (
685- operation_id , endpoint_path , path_params , query_params
686- )
687- elif DEPRECATED_METHODS .get (operation_id ):
688- has_deprecated = True
657+ if DEPRECATED_METHODS .get (operation_id ):
689658 code += _create_get_deprecated (
690659 operation_id ,
691660 tags ,
@@ -696,6 +665,8 @@ def _create_get(
696665 path_params ,
697666 query_params ,
698667 )
668+ if code :
669+ has_deprecated = True
699670
700671 # Generate main function parameters and documentation
701672 code_path_params , desc_path_params = _gen_code_params (path_params , operation_id )
@@ -1433,7 +1404,7 @@ def start(
14331404# Script entry point
14341405
14351406# Get version from command line argument for deprecation warnings
1436- version = sys .argv [1 ]
1407+ VERSION = sys .argv [1 ]
14371408
14381409# Clean up existing API folder to ensure fresh generation
14391410if os .path .exists (f"{ ROOT_FOLDER } /{ ROOT_API_FOLDER } " ):
0 commit comments