@@ -94,25 +94,32 @@ def load_schemas_from_file(file_path: Path) -> None:
9494 if schema_name not in all_schemas :
9595 # Check if this schema is itself a reference
9696 if isinstance (schema_def , dict ) and "$ref" in schema_def :
97- ref = schema_def ["$ref" ]
97+ ref_value : Any = schema_def ["$ref" ] # type: ignore[misc ]
9898 # Resolve the reference using ParseContext utilities
99- try :
100- context = ParseContext (abs_path )
101- target_context = context .resolve_reference (ref )
102-
103- # Load and navigate to the referenced schema
104- with target_context .filepath .open ("r" ) as ref_file :
105- ref_spec = yaml .safe_load (ref_file )
106-
107- if target_context .json_pointer :
108- resolved_schema = navigate_json_pointer (ref_spec , target_context .json_pointer )
109- else :
110- resolved_schema = ref_spec
111-
112- all_schemas [schema_name ] = resolved_schema
113- except Exception as e :
114- print (f"Warning: Could not resolve reference { ref } in { abs_path } : { e } " )
115- all_schemas [schema_name ] = schema_def
99+ if isinstance (ref_value , str ):
100+ try :
101+ context = ParseContext (abs_path )
102+ target_context = context .resolve_reference (
103+ ref_value
104+ )
105+
106+ # Load and navigate to the referenced schema
107+ with target_context .filepath .open ("r" ) as ref_file :
108+ ref_spec = yaml .safe_load (ref_file )
109+
110+ if target_context .json_pointer :
111+ resolved_schema = navigate_json_pointer (
112+ ref_spec , target_context .json_pointer
113+ )
114+ else :
115+ resolved_schema = ref_spec
116+
117+ all_schemas [schema_name ] = resolved_schema
118+ except Exception as e :
119+ print (
120+ f"Warning: Could not resolve reference { ref_value } in { abs_path } : { e } "
121+ )
122+ all_schemas [schema_name ] = schema_def
116123 else :
117124 all_schemas [schema_name ] = schema_def
118125
@@ -124,7 +131,9 @@ def load_schemas_from_file(file_path: Path) -> None:
124131 all_schemas [schema_name ] = msg_def ["payload" ]
125132
126133 # Find and process all external file references
127- self ._find_and_process_refs (spec , abs_path .parent , load_schemas_from_file )
134+ self ._find_and_process_refs (
135+ spec , abs_path .parent , load_schemas_from_file
136+ )
128137
129138 except Exception as e :
130139 print (f"Warning: Could not load component schemas from { abs_path } : { e } " )
@@ -141,26 +150,27 @@ def _find_and_process_refs(
141150 if isinstance (data , dict ):
142151 # Check if this is a reference
143152 if "$ref" in data :
144- ref = data ["$ref" ]
145- if isinstance (ref , str ) and not ref .startswith ("#" ):
153+ ref_value : Any = data ["$ref" ] # type: ignore[misc ]
154+ if isinstance (ref_value , str ) and not ref_value .startswith ("#" ):
146155 # External reference - extract file path
147- if "#" in ref :
148- file_part = ref .split ("#" )[0 ]
156+ file_part : str
157+ if "#" in ref_value :
158+ file_part = ref_value .split ("#" )[0 ]
149159 else :
150- file_part = ref
160+ file_part = ref_value
151161
152162 if file_part :
153163 # Resolve relative path
154164 ref_path = (base_dir / file_part ).resolve ()
155165 process_file (ref_path )
156166
157167 # Recurse into all dict values
158- for value in data .values ():
168+ for value in data .values (): # type: ignore[misc]
159169 self ._find_and_process_refs (value , base_dir , process_file )
160170
161171 elif isinstance (data , list ):
162172 # Recurse into all list items
163- for item in data :
173+ for item in data : # type: ignore[misc]
164174 self ._find_and_process_refs (item , base_dir , process_file )
165175
166176 def _resolve_references (self , schemas : dict [str , Any ]) -> dict [str , Any ]:
0 commit comments