7
7
8
8
from ... import Config , utils
9
9
from ... import schema as oai
10
+ from ...utils import PythonIdentifier
10
11
from ..errors import ParseError , PropertyError
12
+ from .any import AnyProperty
11
13
from .enum_property import EnumProperty
12
14
from .protocol import PropertyProtocol , Value
13
15
from .schemas import Class , ReferencePath , Schemas , parse_reference_path
@@ -30,7 +32,7 @@ class ModelProperty(PropertyProtocol):
30
32
optional_properties : list [Property ] | None
31
33
relative_imports : set [str ] | None
32
34
lazy_imports : set [str ] | None
33
- additional_properties : bool | Property | None
35
+ additional_properties : Property | None
34
36
_json_type_string : ClassVar [str ] = "Dict[str, Any]"
35
37
36
38
template : ClassVar [str ] = "model_property.py.jinja"
@@ -78,7 +80,7 @@ def build(
78
80
optional_properties : list [Property ] | None = None
79
81
relative_imports : set [str ] | None = None
80
82
lazy_imports : set [str ] | None = None
81
- additional_properties : bool | Property | None = None
83
+ additional_properties : Property | None = None
82
84
if process_properties :
83
85
data_or_err , schemas = _process_property_data (
84
86
data = data , schemas = schemas , class_info = class_info , config = config , roots = model_roots
@@ -386,25 +388,37 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None:
386
388
)
387
389
388
390
391
+ ANY_ADDITIONAL_PROPERTY = AnyProperty .build (
392
+ name = "additional" ,
393
+ required = True ,
394
+ default = None ,
395
+ description = "" ,
396
+ python_name = PythonIdentifier (value = "additional" , prefix = "" ),
397
+ example = None ,
398
+ )
399
+
400
+
389
401
def _get_additional_properties (
390
402
* ,
391
403
schema_additional : None | (bool | (oai .Reference | oai .Schema )),
392
404
schemas : Schemas ,
393
405
class_name : utils .ClassName ,
394
406
config : Config ,
395
407
roots : set [ReferencePath | utils .ClassName ],
396
- ) -> tuple [bool | ( Property | PropertyError ) , Schemas ]:
408
+ ) -> tuple [Property | None | PropertyError , Schemas ]:
397
409
from . import property_from_data
398
410
399
411
if schema_additional is None :
400
- return True , schemas
412
+ return ANY_ADDITIONAL_PROPERTY , schemas
401
413
402
414
if isinstance (schema_additional , bool ):
403
- return schema_additional , schemas
415
+ if schema_additional :
416
+ return ANY_ADDITIONAL_PROPERTY , schemas
417
+ return None , schemas
404
418
405
419
if isinstance (schema_additional , oai .Schema ) and not any (schema_additional .model_dump ().values ()):
406
420
# An empty schema
407
- return True , schemas
421
+ return ANY_ADDITIONAL_PROPERTY , schemas
408
422
409
423
additional_properties , schemas = property_from_data (
410
424
name = "AdditionalProperty" ,
@@ -425,7 +439,7 @@ def _process_property_data(
425
439
class_info : Class ,
426
440
config : Config ,
427
441
roots : set [ReferencePath | utils .ClassName ],
428
- ) -> tuple [tuple [_PropertyData , bool | Property ] | PropertyError , Schemas ]:
442
+ ) -> tuple [tuple [_PropertyData , Property | None ] | PropertyError , Schemas ]:
429
443
property_data = _process_properties (
430
444
data = data , schemas = schemas , class_name = class_info .name , config = config , roots = roots
431
445
)
@@ -442,7 +456,7 @@ def _process_property_data(
442
456
)
443
457
if isinstance (additional_properties , PropertyError ):
444
458
return additional_properties , schemas
445
- elif isinstance ( additional_properties , bool ) :
459
+ elif additional_properties is None :
446
460
pass
447
461
else :
448
462
property_data .relative_imports .update (additional_properties .get_imports (prefix = ".." ))
0 commit comments