12
12
import pytest
13
13
from dirty_equals import IsListOrTuple
14
14
from inline_snapshot import snapshot
15
- from pydantic import BaseModel , Discriminator , Field , Tag
15
+ from pydantic import AnyUrl , BaseModel , Discriminator , Field , Tag
16
16
from typing_extensions import TypedDict
17
17
18
18
from pydantic_ai import Agent , ModelHTTPError , ModelRetry , UnexpectedModelBehavior
@@ -1094,6 +1094,14 @@ def tool_with_default(x: int = 1) -> str:
1094
1094
return f'{ x } ' # pragma: no cover
1095
1095
1096
1096
1097
+ def tool_with_datetime (x : datetime ) -> str :
1098
+ return f'{ x } ' # pragma: no cover
1099
+
1100
+
1101
+ def tool_with_url (x : AnyUrl ) -> str :
1102
+ return f'{ x } ' # pragma: no cover
1103
+
1104
+
1097
1105
def tool_with_recursion (x : MyRecursiveDc , y : MyDefaultRecursiveDc ):
1098
1106
return f'{ x } { y } ' # pragma: no cover
1099
1107
@@ -1155,6 +1163,45 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1155
1163
),
1156
1164
snapshot (None ),
1157
1165
),
1166
+ (
1167
+ tool_with_datetime ,
1168
+ None ,
1169
+ snapshot (
1170
+ {
1171
+ 'additionalProperties' : False ,
1172
+ 'properties' : {'x' : {'format' : 'date-time' , 'type' : 'string' }},
1173
+ 'required' : ['x' ],
1174
+ 'type' : 'object' ,
1175
+ }
1176
+ ),
1177
+ snapshot (True ),
1178
+ ),
1179
+ (
1180
+ tool_with_url ,
1181
+ None ,
1182
+ snapshot (
1183
+ {
1184
+ 'additionalProperties' : False ,
1185
+ 'properties' : {'x' : {'format' : 'uri' , 'minLength' : 1 , 'type' : 'string' }},
1186
+ 'required' : ['x' ],
1187
+ 'type' : 'object' ,
1188
+ }
1189
+ ),
1190
+ snapshot (None ),
1191
+ ),
1192
+ (
1193
+ tool_with_url ,
1194
+ True ,
1195
+ snapshot (
1196
+ {
1197
+ 'additionalProperties' : False ,
1198
+ 'properties' : {'x' : {'type' : 'string' , 'description' : 'minLength=1, format=uri' }},
1199
+ 'required' : ['x' ],
1200
+ 'type' : 'object' ,
1201
+ }
1202
+ ),
1203
+ snapshot (True ),
1204
+ ),
1158
1205
(
1159
1206
tool_with_recursion ,
1160
1207
None ,
@@ -1432,16 +1479,8 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1432
1479
{
1433
1480
'additionalProperties' : False ,
1434
1481
'properties' : {
1435
- 'x' : {
1436
- 'prefixItems' : [{'type' : 'integer' }],
1437
- 'type' : 'array' ,
1438
- 'description' : 'minItems=1, maxItems=1' ,
1439
- },
1440
- 'y' : {
1441
- 'prefixItems' : [{'type' : 'string' }],
1442
- 'type' : 'array' ,
1443
- 'description' : 'minItems=1, maxItems=1' ,
1444
- },
1482
+ 'x' : {'maxItems' : 1 , 'minItems' : 1 , 'prefixItems' : [{'type' : 'integer' }], 'type' : 'array' },
1483
+ 'y' : {'maxItems' : 1 , 'minItems' : 1 , 'prefixItems' : [{'type' : 'string' }], 'type' : 'array' },
1445
1484
},
1446
1485
'required' : ['x' , 'y' ],
1447
1486
'type' : 'object' ,
@@ -1537,9 +1576,10 @@ class MyModel(BaseModel):
1537
1576
},
1538
1577
'my_recursive' : {'anyOf' : [{'$ref' : '#' }, {'type' : 'null' }]},
1539
1578
'my_tuple' : {
1579
+ 'maxItems' : 1 ,
1580
+ 'minItems' : 1 ,
1540
1581
'prefixItems' : [{'type' : 'integer' }],
1541
1582
'type' : 'array' ,
1542
- 'description' : 'minItems=1, maxItems=1' ,
1543
1583
},
1544
1584
},
1545
1585
'required' : ['my_recursive' , 'my_patterns' , 'my_tuple' , 'my_list' , 'my_discriminated_union' ],
@@ -1555,11 +1595,7 @@ class MyModel(BaseModel):
1555
1595
'properties' : {},
1556
1596
'required' : [],
1557
1597
},
1558
- 'my_tuple' : {
1559
- 'prefixItems' : [{'type' : 'integer' }],
1560
- 'type' : 'array' ,
1561
- 'description' : 'minItems=1, maxItems=1' ,
1562
- },
1598
+ 'my_tuple' : {'maxItems' : 1 , 'minItems' : 1 , 'prefixItems' : [{'type' : 'integer' }], 'type' : 'array' },
1563
1599
'my_list' : {'items' : {'type' : 'number' }, 'type' : 'array' },
1564
1600
'my_discriminated_union' : {'anyOf' : [{'$ref' : '#/$defs/Apple' }, {'$ref' : '#/$defs/Banana' }]},
1565
1601
},
0 commit comments