@@ -235,8 +235,48 @@ async def check_call(args):
235
235
236
236
237
237
def test_complex_function_json_schema ():
238
+ """Test JSON schema generation for complex function arguments.
239
+
240
+ Note: This test accepts two equivalent JSON Schema formats for models with defaults:
241
+ 1. Pre-pydantic 2.7.2:
242
+ {
243
+ "$ref": "#/$defs/Model",
244
+ "default": {}
245
+ }
246
+
247
+ 2. Pydantic 2.7.2+:
248
+ {
249
+ "allOf": [
250
+ {
251
+ "$ref": "#/$defs/Model"
252
+ }
253
+ ],
254
+ "default": {}
255
+ }
256
+
257
+ Both formats are valid JSON Schema and represent the same validation rules.
258
+ The newer format using allOf is more correct according to the JSON Schema spec
259
+ as it properly composes the reference with additional properties.
260
+
261
+ This change in format does not affect runtime behavior since:
262
+ 1. Both schemas validate the same way
263
+ 2. The actual model classes and validation logic are unchanged
264
+ 3. func_metadata uses model_validate/model_dump, not the schema directly
265
+ """
238
266
meta = func_metadata (complex_arguments_fn )
239
- assert meta .arg_model .model_json_schema () == {
267
+ actual_schema = meta .arg_model .model_json_schema ()
268
+
269
+ # Create a copy of the actual schema to normalize
270
+ normalized_schema = actual_schema .copy ()
271
+
272
+ # Normalize the my_model_a_with_default field to handle both pydantic formats
273
+ if 'allOf' in actual_schema ['properties' ]['my_model_a_with_default' ]:
274
+ normalized_schema ['properties' ]['my_model_a_with_default' ] = {
275
+ '$ref' : '#/$defs/SomeInputModelA' ,
276
+ 'default' : {}
277
+ }
278
+
279
+ assert normalized_schema == {
240
280
"$defs" : {
241
281
"InnerModel" : {
242
282
"properties" : {"x" : {"title" : "X" , "type" : "integer" }},
0 commit comments