@@ -177,9 +177,9 @@ def _createAnnotations(
177177 self .root = v
178178 elif _type == "object" :
179179 if (
180- schema .additionalProperties
181- and isinstance ( schema .additionalProperties , ( SchemaBase , ReferenceBase ))
182- and not schema .properties
180+ not schema .properties
181+ and schema .additionalProperties is not None
182+ and not Model . booleanFalse ( schema .additionalProperties )
183183 ):
184184 """
185185 https://swagger.io/docs/specification/data-models/dictionaries/
@@ -412,7 +412,7 @@ def get_patternProperties(self_):
412412
413413 classinfo .properties ["aio3_patternProperties" ].default = property (mkx ())
414414
415- if not schema .additionalProperties :
415+ if Model . booleanFalse ( schema .additionalProperties ) :
416416
417417 def mkx ():
418418 def validate_patternProperties (self_ ):
@@ -473,21 +473,16 @@ def createConfigDict(schema: "SchemaType"):
473473 arbitrary_types_allowed_ = False
474474 extra_ = "allow"
475475
476- if schema .additionalProperties is not None :
477- if isinstance (schema .additionalProperties , bool ):
478- if not schema .additionalProperties :
479- extra_ = "forbid"
480- else :
481- arbitrary_types_allowed_ = True
482- elif isinstance (schema .additionalProperties , (SchemaBase , ReferenceBase )):
483- """
484- we allow arbitrary types if additionalProperties has no properties
485- """
486- assert schema .additionalProperties .properties is not None
487- if len (schema .additionalProperties .properties ) == 0 :
488- arbitrary_types_allowed_ = True
489- else :
490- raise TypeError (schema .additionalProperties )
476+ if Model .booleanFalse (schema .additionalProperties ):
477+ extra_ = "forbid"
478+ elif Model .booleanTrue (schema .additionalProperties ) or (
479+ isinstance (schema .additionalProperties , (SchemaBase , ReferenceBase ))
480+ and len (schema .additionalProperties .properties ) == 0
481+ ):
482+ """
483+ we allow arbitrary types if additionalProperties has no properties
484+ """
485+ arbitrary_types_allowed_ = True
491486
492487 if getattr (schema , "patternProperties" , None ):
493488 extra_ = "allow"
@@ -671,6 +666,41 @@ def is_nullable(schema: "SchemaType") -> bool:
671666 def is_type_any (schema : "SchemaType" ):
672667 return schema .type is None
673668
669+ @staticmethod
670+ def booleanTrue (schema : Optional [Union ["SchemaType" , bool ]]) -> bool :
671+ """
672+ ACCEPT all?
673+ :param schema:
674+ :return: True if Schema is {} or True or None
675+ """
676+ if schema is None :
677+ return True
678+ if isinstance (schema , bool ):
679+ return schema is True
680+ elif isinstance (schema , (SchemaBase , ReferenceBase )):
681+ """matches Any - {}"""
682+ return len (schema .model_fields_set ) == 0
683+ else :
684+ raise ValueError (schema )
685+
686+ @staticmethod
687+ def booleanFalse (schema : Optional [Union ["SchemaType" , bool ]]) -> bool :
688+ """
689+ REJECT all?
690+ :param schema:
691+ :return: True if Schema is {'not':{}} or False
692+ """
693+
694+ if schema is None :
695+ return False
696+ if isinstance (schema , bool ):
697+ return schema is False
698+ elif isinstance (schema , (SchemaBase , ReferenceBase )):
699+ """match {'not':{}}"""
700+ return (v := getattr (schema , "not_" , False )) and Model .booleanTrue (v )
701+ else :
702+ raise ValueError (schema )
703+
674704 @staticmethod
675705 def createField (schema : "SchemaType" , _type = None , args = None ):
676706 if args is None :
0 commit comments