File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
pydantic_ai_slim/pydantic_ai Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def check_object_json_schema(schema: JsonSchemaValue) -> ObjectJsonSchema:
48
48
49
49
if schema .get ('type' ) == 'object' :
50
50
return schema
51
+ elif schema .get ('$ref' ) is not None :
52
+ return schema .get ('$defs' , {}).get (schema ['$ref' ][8 :]) # This removes the initial "#/$defs/".
51
53
else :
52
54
raise UserError ('Schema must be an object' )
53
55
Original file line number Diff line number Diff line change @@ -44,6 +44,30 @@ def test_check_object_json_schema():
44
44
object_schema = {'type' : 'object' , 'properties' : {'a' : {'type' : 'string' }}}
45
45
assert check_object_json_schema (object_schema ) == object_schema
46
46
47
+ ref_schema = {
48
+ '$defs' : {
49
+ 'JsonModel' : {
50
+ 'properties' : {
51
+ 'type' : {'title' : 'Type' , 'type' : 'string' },
52
+ 'items' : {'anyOf' : [{'$ref' : '#/$defs/JsonModel' }, {'type' : 'null' }]},
53
+ },
54
+ 'required' : ['type' , 'items' ],
55
+ 'title' : 'JsonModel' ,
56
+ 'type' : 'object' ,
57
+ }
58
+ },
59
+ '$ref' : '#/$defs/JsonModel' ,
60
+ }
61
+ assert check_object_json_schema (ref_schema ) == {
62
+ 'properties' : {
63
+ 'type' : {'title' : 'Type' , 'type' : 'string' },
64
+ 'items' : {'anyOf' : [{'$ref' : '#/$defs/JsonModel' }, {'type' : 'null' }]},
65
+ },
66
+ 'required' : ['type' , 'items' ],
67
+ 'title' : 'JsonModel' ,
68
+ 'type' : 'object' ,
69
+ }
70
+
47
71
array_schema = {'type' : 'array' , 'items' : {'type' : 'string' }}
48
72
with pytest .raises (UserError , match = '^Schema must be an object$' ):
49
73
check_object_json_schema (array_schema )
You can’t perform that action at this time.
0 commit comments