|
4 | 4 | from collections.abc import Sequence
|
5 | 5 | from dataclasses import dataclass, field
|
6 | 6 | from datetime import datetime, timezone
|
| 7 | +from enum import Enum |
7 | 8 | from functools import cached_property
|
8 | 9 | from typing import Annotated, Any, Callable, Literal, Union, cast
|
9 | 10 |
|
@@ -730,9 +731,15 @@ class MyDefaultDc:
|
730 | 731 | x: int = 1
|
731 | 732 |
|
732 | 733 |
|
| 734 | +class MyEnum(Enum): |
| 735 | + a = 'a' |
| 736 | + b = 'b' |
| 737 | + |
| 738 | + |
733 | 739 | @dataclass
|
734 | 740 | class MyRecursiveDc:
|
735 | 741 | field: MyRecursiveDc | None
|
| 742 | + my_enum: MyEnum = Field(description='my enum') |
736 | 743 |
|
737 | 744 |
|
738 | 745 | @dataclass
|
@@ -826,9 +833,13 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
|
826 | 833 | },
|
827 | 834 | 'type': 'object',
|
828 | 835 | },
|
| 836 | + 'MyEnum': {'enum': ['a', 'b'], 'type': 'string'}, |
829 | 837 | 'MyRecursiveDc': {
|
830 |
| - 'properties': {'field': {'anyOf': [{'$ref': '#/$defs/MyRecursiveDc'}, {'type': 'null'}]}}, |
831 |
| - 'required': ['field'], |
| 838 | + 'properties': { |
| 839 | + 'field': {'anyOf': [{'$ref': '#/$defs/MyRecursiveDc'}, {'type': 'null'}]}, |
| 840 | + 'my_enum': {'description': 'my enum', 'anyOf': [{'$ref': '#/$defs/MyEnum'}]}, |
| 841 | + }, |
| 842 | + 'required': ['field', 'my_enum'], |
832 | 843 | 'type': 'object',
|
833 | 844 | },
|
834 | 845 | },
|
@@ -857,11 +868,15 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
|
857 | 868 | 'additionalProperties': False,
|
858 | 869 | 'required': ['field'],
|
859 | 870 | },
|
| 871 | + 'MyEnum': {'enum': ['a', 'b'], 'type': 'string'}, |
860 | 872 | 'MyRecursiveDc': {
|
861 |
| - 'properties': {'field': {'anyOf': [{'$ref': '#/$defs/MyRecursiveDc'}, {'type': 'null'}]}}, |
| 873 | + 'properties': { |
| 874 | + 'field': {'anyOf': [{'$ref': '#/$defs/MyRecursiveDc'}, {'type': 'null'}]}, |
| 875 | + 'my_enum': {'description': 'my enum', 'anyOf': [{'$ref': '#/$defs/MyEnum'}]}, |
| 876 | + }, |
862 | 877 | 'type': 'object',
|
863 | 878 | 'additionalProperties': False,
|
864 |
| - 'required': ['field'], |
| 879 | + 'required': ['field', 'my_enum'], |
865 | 880 | },
|
866 | 881 | },
|
867 | 882 | 'additionalProperties': False,
|
@@ -998,7 +1013,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
|
998 | 1013 | }
|
999 | 1014 | },
|
1000 | 1015 | 'additionalProperties': False,
|
1001 |
| - 'properties': {'x': {'oneOf': [{'type': 'integer'}, {'$ref': '#/$defs/MyDefaultDc'}]}}, |
| 1016 | + 'properties': {'x': {'anyOf': [{'type': 'integer'}, {'$ref': '#/$defs/MyDefaultDc'}]}}, |
1002 | 1017 | 'required': ['x'],
|
1003 | 1018 | 'type': 'object',
|
1004 | 1019 | }
|
@@ -1079,12 +1094,15 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
|
1079 | 1094 | {
|
1080 | 1095 | 'additionalProperties': False,
|
1081 | 1096 | 'properties': {
|
1082 |
| - 'x': {'maxItems': 1, 'minItems': 1, 'prefixItems': [{'type': 'integer'}], 'type': 'array'}, |
| 1097 | + 'x': { |
| 1098 | + 'prefixItems': [{'type': 'integer'}], |
| 1099 | + 'type': 'array', |
| 1100 | + 'description': 'minItems=1, maxItems=1', |
| 1101 | + }, |
1083 | 1102 | 'y': {
|
1084 |
| - 'maxItems': 1, |
1085 |
| - 'minItems': 1, |
1086 | 1103 | 'prefixItems': [{'type': 'string'}],
|
1087 | 1104 | 'type': 'array',
|
| 1105 | + 'description': 'minItems=1, maxItems=1', |
1088 | 1106 | },
|
1089 | 1107 | },
|
1090 | 1108 | 'required': ['x', 'y'],
|
@@ -1160,28 +1178,46 @@ class MyModel(BaseModel):
|
1160 | 1178 | 'MyModel': {
|
1161 | 1179 | 'additionalProperties': False,
|
1162 | 1180 | 'properties': {
|
1163 |
| - 'my_discriminated_union': {'oneOf': [{'$ref': '#/$defs/Apple'}, {'$ref': '#/$defs/Banana'}]}, |
| 1181 | + 'my_discriminated_union': {'anyOf': [{'$ref': '#/$defs/Apple'}, {'$ref': '#/$defs/Banana'}]}, |
1164 | 1182 | 'my_list': {'items': {'type': 'number'}, 'type': 'array'},
|
1165 | 1183 | 'my_patterns': {
|
1166 | 1184 | 'additionalProperties': False,
|
1167 |
| - 'patternProperties': {'^my-pattern$': {'type': 'string'}}, |
| 1185 | + 'description': "patternProperties={'^my-pattern$': {'type': 'string'}}", |
1168 | 1186 | 'type': 'object',
|
1169 | 1187 | 'properties': {},
|
1170 | 1188 | 'required': [],
|
1171 | 1189 | },
|
1172 |
| - 'my_recursive': {'anyOf': [{'$ref': '#/$defs/MyModel'}, {'type': 'null'}]}, |
| 1190 | + 'my_recursive': {'anyOf': [{'$ref': '#'}, {'type': 'null'}]}, |
1173 | 1191 | 'my_tuple': {
|
1174 |
| - 'maxItems': 1, |
1175 |
| - 'minItems': 1, |
1176 | 1192 | 'prefixItems': [{'type': 'integer'}],
|
1177 | 1193 | 'type': 'array',
|
| 1194 | + 'description': 'minItems=1, maxItems=1', |
1178 | 1195 | },
|
1179 | 1196 | },
|
1180 | 1197 | 'required': ['my_recursive', 'my_patterns', 'my_tuple', 'my_list', 'my_discriminated_union'],
|
1181 | 1198 | 'type': 'object',
|
1182 | 1199 | },
|
1183 | 1200 | },
|
1184 |
| - '$ref': '#/$defs/MyModel', |
| 1201 | + 'properties': { |
| 1202 | + 'my_recursive': {'anyOf': [{'$ref': '#'}, {'type': 'null'}]}, |
| 1203 | + 'my_patterns': { |
| 1204 | + 'type': 'object', |
| 1205 | + 'description': "patternProperties={'^my-pattern$': {'type': 'string'}}", |
| 1206 | + 'additionalProperties': False, |
| 1207 | + 'properties': {}, |
| 1208 | + 'required': [], |
| 1209 | + }, |
| 1210 | + 'my_tuple': { |
| 1211 | + 'prefixItems': [{'type': 'integer'}], |
| 1212 | + 'type': 'array', |
| 1213 | + 'description': 'minItems=1, maxItems=1', |
| 1214 | + }, |
| 1215 | + 'my_list': {'items': {'type': 'number'}, 'type': 'array'}, |
| 1216 | + 'my_discriminated_union': {'anyOf': [{'$ref': '#/$defs/Apple'}, {'$ref': '#/$defs/Banana'}]}, |
| 1217 | + }, |
| 1218 | + 'required': ['my_recursive', 'my_patterns', 'my_tuple', 'my_list', 'my_discriminated_union'], |
| 1219 | + 'type': 'object', |
| 1220 | + 'additionalProperties': False, |
1185 | 1221 | }
|
1186 | 1222 | )
|
1187 | 1223 |
|
|
0 commit comments