@@ -147,44 +147,47 @@ def parse_parameters_for_args_schema(parameters: List[Dict[str, Any]]) -> Dict[s
147
147
148
148
return args_schema
149
149
150
- def resolve_schema_references (schema : Dict [str , Any ], openapi_schema : Dict [str , Any ]) -> Dict [str , Any ]:
150
+ def resolve_schema_references (schema_part : Dict [str , Any ], reference_schema : Dict [str , Any ]) -> Dict [str , Any ]:
151
151
"""
152
152
Resolve schema references in OpenAPI schemas.
153
153
154
154
Args:
155
- schema : The schema that may contain references
156
- openapi_schema : The full OpenAPI schema to resolve references from
155
+ schema_part : The part of the schema being processed that may contain references
156
+ reference_schema : The complete schema used to resolve references from
157
157
158
158
Returns:
159
159
The schema with references resolved
160
160
"""
161
161
# Make a copy to avoid modifying the input schema
162
- schema = schema .copy ()
162
+ schema_part = schema_part .copy ()
163
163
164
164
# Handle $ref directly in the schema
165
- if "$ref" in schema :
166
- ref_path = schema ["$ref" ]
165
+ if "$ref" in schema_part :
166
+ ref_path = schema_part ["$ref" ]
167
167
# Standard OpenAPI references are in the format "#/components/schemas/ModelName"
168
168
if ref_path .startswith ("#/components/schemas/" ):
169
169
model_name = ref_path .split ("/" )[- 1 ]
170
- if "components" in openapi_schema and "schemas" in openapi_schema ["components" ]:
171
- if model_name in openapi_schema ["components" ]["schemas" ]:
170
+ if "components" in reference_schema and "schemas" in reference_schema ["components" ]:
171
+ if model_name in reference_schema ["components" ]["schemas" ]:
172
172
# Replace with the resolved schema
173
- ref_schema = openapi_schema ["components" ]["schemas" ][model_name ].copy ()
173
+ ref_schema = reference_schema ["components" ]["schemas" ][model_name ].copy ()
174
174
# Remove the $ref key and merge with the original schema
175
- schema .pop ("$ref" )
176
- schema .update (ref_schema )
177
-
178
- # Handle array items
179
- if "type" in schema and schema ["type" ] == "array" and "items" in schema :
180
- schema ["items" ] = resolve_schema_references (schema ["items" ], openapi_schema )
181
-
182
- # Handle object properties
183
- if "properties" in schema :
184
- for prop_name , prop_schema in schema ["properties" ].items ():
185
- schema ["properties" ][prop_name ] = resolve_schema_references (prop_schema , openapi_schema )
186
-
187
- return schema
175
+ schema_part .pop ("$ref" )
176
+ schema_part .update (ref_schema )
177
+
178
+ # Recursively resolve references in all dictionary values
179
+ for key , value in schema_part .items ():
180
+ if isinstance (value , dict ):
181
+ schema_part [key ] = resolve_schema_references (value , reference_schema )
182
+ elif isinstance (value , list ):
183
+ # Only process list items that are dictionaries since only they can contain refs
184
+ schema_part [key ] = [
185
+ resolve_schema_references (item , reference_schema ) if isinstance (item , dict )
186
+ else item
187
+ for item in value
188
+ ]
189
+
190
+ return schema_part
188
191
189
192
def clean_schema_for_display (schema : Dict [str , Any ]) -> Dict [str , Any ]:
190
193
"""
0 commit comments