@@ -83,6 +83,7 @@ def __init__(self, swagger_url=None):
83
83
self .swagger_url = swagger_url or "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/swagger.json"
84
84
self .swagger_spec = None
85
85
self .path_to_operation = {}
86
+ self .deprecated_operations = set ()
86
87
self .known_resource_types = set ()
87
88
self .load_swagger_spec ()
88
89
@@ -140,12 +141,19 @@ def _build_path_mapping(self):
140
141
if method .lower () in ['get' , 'post' , 'put' , 'patch' , 'delete' ] and 'operationId' in operation :
141
142
operation_id = operation ['operationId' ]
142
143
144
+ # Check if operation is deprecated
145
+ description = operation .get ('description' , '' ).lower ()
146
+ if 'deprecated' in description :
147
+ self .deprecated_operations .add (operation_id )
148
+
143
149
# Normalize the path for matching
144
150
normalized_path = self ._normalize_swagger_path (path )
145
151
key = f"{ method .lower ()} :{ normalized_path } "
146
152
self .path_to_operation [key ] = operation_id
147
153
148
154
print (f"Loaded { len (self .path_to_operation )} API operations from Swagger spec" )
155
+ if self .deprecated_operations :
156
+ print (f"Found { len (self .deprecated_operations )} deprecated operations" )
149
157
150
158
def _extract_resource_types (self ):
151
159
"""Extract resource types from Swagger paths to avoid hardcoding."""
@@ -663,21 +671,28 @@ def write_results(endpoint_counts, stats, swagger_mapper=None, output_file=None,
663
671
if ineligible_endpoints is None :
664
672
ineligible_endpoints = set ()
665
673
666
- # Filter out ineligible endpoints from results
674
+ # Filter out ineligible endpoints and deprecated operations from results
667
675
filtered_endpoint_counts = Counter ()
668
676
ineligible_found_count = 0
677
+ deprecated_found_count = 0
678
+ deprecated_operations = swagger_mapper .deprecated_operations if swagger_mapper else set ()
679
+
669
680
for endpoint , count in endpoint_counts .items ():
670
- if endpoint not in ineligible_endpoints :
671
- filtered_endpoint_counts [endpoint ] = count
672
- else :
681
+ if endpoint in ineligible_endpoints :
673
682
ineligible_found_count += count
683
+ elif endpoint in deprecated_operations :
684
+ deprecated_found_count += count
685
+ else :
686
+ filtered_endpoint_counts [endpoint ] = count
674
687
675
688
# Update stats to reflect filtering
676
689
filtered_stats = stats .copy ()
677
690
filtered_stats ['unique_endpoints' ] = len (filtered_endpoint_counts )
678
691
filtered_stats ['total_api_calls' ] = sum (filtered_endpoint_counts .values ())
679
- filtered_stats ['ineligible_endpoints_filtered' ] = len (endpoint_counts ) - len ( filtered_endpoint_counts )
692
+ filtered_stats ['ineligible_endpoints_filtered' ] = len ([ ep for ep in endpoint_counts if ep in ineligible_endpoints ] )
680
693
filtered_stats ['ineligible_api_calls_filtered' ] = ineligible_found_count
694
+ filtered_stats ['deprecated_endpoints_filtered' ] = len ([ep for ep in endpoint_counts if ep in deprecated_operations ])
695
+ filtered_stats ['deprecated_api_calls_filtered' ] = deprecated_found_count
681
696
if sort_by == 'count' :
682
697
sorted_endpoints = filtered_endpoint_counts .most_common ()
683
698
sort_desc = "sorted by count (descending)"
@@ -699,6 +714,9 @@ def write_results(endpoint_counts, stats, swagger_mapper=None, output_file=None,
699
714
if ineligible_endpoints :
700
715
output .append (f"Ineligible endpoints filtered: { filtered_stats ['ineligible_endpoints_filtered' ]} " )
701
716
output .append (f"Ineligible API calls filtered: { filtered_stats ['ineligible_api_calls_filtered' ]} " )
717
+ if deprecated_operations :
718
+ output .append (f"Deprecated endpoints filtered: { filtered_stats ['deprecated_endpoints_filtered' ]} " )
719
+ output .append (f"Deprecated API calls filtered: { filtered_stats ['deprecated_api_calls_filtered' ]} " )
702
720
output .append (f"Results { sort_desc } " )
703
721
output .append ("" )
704
722
output .append ("Endpoint Name (OpenAPI Operation ID) | Count" )
@@ -726,6 +744,10 @@ def write_results(endpoint_counts, stats, swagger_mapper=None, output_file=None,
726
744
if ineligible_endpoints :
727
745
stable_missing_operations = stable_missing_operations - ineligible_endpoints
728
746
747
+ # Filter out deprecated operations from missing operations
748
+ if deprecated_operations :
749
+ stable_missing_operations = stable_missing_operations - deprecated_operations
750
+
729
751
if stable_missing_operations :
730
752
filtered_count = len (missing_operations ) - len (stable_missing_operations )
731
753
@@ -735,8 +757,8 @@ def write_results(endpoint_counts, stats, swagger_mapper=None, output_file=None,
735
757
output .append ("=" * 70 )
736
758
output .append (f"Total missing stable endpoints: { len (stable_missing_operations )} " )
737
759
if filtered_count > 0 :
738
- output .append (f"(Filtered out { filtered_count } alpha/beta endpoints)" )
739
- output .append (f"These are stable API endpoints defined in the Swagger spec but not exercised in this audit log:" )
760
+ output .append (f"(Filtered out { filtered_count } alpha/beta/deprecated endpoints)" )
761
+ output .append (f"These are stable, non-deprecated API endpoints defined in the Swagger spec but not exercised in this audit log:" )
740
762
output .append ("" )
741
763
742
764
# Sort missing operations alphabetically
0 commit comments