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
@@ -1144,12 +1152,50 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1144
1152
snapshot (None ),
1145
1153
),
1146
1154
(
1147
- strict_compatible_tool ,
1155
+ tool_with_default ,
1148
1156
None ,
1149
1157
snapshot (
1150
1158
{
1151
1159
'additionalProperties' : False ,
1152
- 'properties' : {'x' : {'type' : 'integer' }},
1160
+ 'properties' : {'x' : {'default' : 1 , 'type' : 'integer' }},
1161
+ 'type' : 'object' ,
1162
+ }
1163
+ ),
1164
+ snapshot (None ),
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' }},
1153
1199
'required' : ['x' ],
1154
1200
'type' : 'object' ,
1155
1201
}
@@ -1413,6 +1459,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1413
1459
'properties' : {
1414
1460
'x' : {'maxItems' : 1 , 'minItems' : 1 , 'prefixItems' : [{'type' : 'integer' }], 'type' : 'array' },
1415
1461
'y' : {
1462
+ 'default' : ['abc' ],
1416
1463
'maxItems' : 1 ,
1417
1464
'minItems' : 1 ,
1418
1465
'prefixItems' : [{'type' : 'string' }],
@@ -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