@@ -113,6 +113,7 @@ class _PropertyInfo:
113113 type_ : str
114114
115115 root : Any = None
116+ anno : pydantic .Field = None
116117 config : dict [str , Any ] = dataclasses .field (default_factory = dict )
117118 properties : dict [str , _PropertyInfo ] = dataclasses .field (
118119 default_factory = lambda : collections .defaultdict (lambda : _ClassInfo ._PropertyInfo ())
@@ -257,10 +258,13 @@ def collapse(cls, type_name, items: list["_ClassInfo"]) -> type[BaseModel]:
257258 r = [i .model () for i in items ]
258259
259260 if len (r ) > 1 :
260- ru : object = Union [tuple (r )]
261+ # FIXME - merge annotations
262+ ru : object = Annotated [Union [tuple (r )], items [0 ].anno ]
261263 m : type [RootModel ] = create_model (type_name , __base__ = (ConfiguredRootModel [ru ],), __module__ = me .__name__ )
262264 elif len (r ) == 1 :
263265 m : type [BaseModel ] = cast (type [BaseModel ], r [0 ])
266+ if items [0 ].anno :
267+ m = Annotated [m , items [0 ].anno ]
264268 if not is_basemodel (m ):
265269 m = create_model (type_name , __base__ = (ConfiguredRootModel [m ],), __module__ = me .__name__ )
266270 else : # == 0
@@ -326,9 +330,8 @@ def createClassInfo(
326330 for primitive types the anyOf/oneOf is taken care of in Model.createAnnotation
327331 """
328332 if typing .get_origin (_t := Model .createAnnotation (schema , _type = _type )) != Literal :
329- classinfo .root = Annotated [_t , Model .createField (schema , _type = _type , args = None )]
330- else :
331- classinfo .root = _t
333+ classinfo .anno = Model .createField (schema , _type = _type , args = None )
334+ classinfo .root = _t
332335 elif _type == "array" :
333336 """anyOf/oneOf is taken care in in createAnnotation"""
334337 classinfo .root = Model .createAnnotation (schema , _type = "array" )
@@ -355,9 +358,8 @@ def createClassInfo(
355358 if _type in Model .types (i )
356359 )
357360 if schema .discriminator and schema .discriminator .mapping :
358- classinfo .root = Annotated [
359- Union [t ], Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
360- ]
361+ classinfo .root = Union [t ]
362+ classinfo .anno = Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
361363 else :
362364 if len (t ):
363365 classinfo .root = Union [t ]
@@ -373,9 +375,8 @@ def createClassInfo(
373375 if _type in Model .types (i )
374376 )
375377 if schema .discriminator and schema .discriminator .mapping :
376- classinfo .root = Annotated [
377- Union [t ], Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
378- ]
378+ classinfo .root = Union [t ]
379+ classinfo .anno = Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
379380 else :
380381 if len (t ):
381382 classinfo .root = Union [t ]
@@ -451,8 +452,8 @@ def validate_patternProperties(self_):
451452 """
452453 assert isinstance (schema , v20 .Schema )
453454 schema_ = v20 .Schema (type = "string" , format = "binary" )
454- _t = Model .createAnnotation (schema_ , _type = "string" )
455- classinfo .root = Annotated [ _t , Model .createField (schema_ , _type = "string" , args = None )]
455+ classinfo . root = Model .createAnnotation (schema_ , _type = "string" )
456+ classinfo .anno = Model .createField (schema_ , _type = "string" , args = None )
456457 else :
457458 raise ValueError (_type )
458459
@@ -716,7 +717,7 @@ def booleanFalse(schema: Optional["SchemaType"]) -> bool:
716717 raise ValueError (schema )
717718
718719 @staticmethod
719- def createField (schema : "SchemaType" , _type = None , args = None ):
720+ def createField (schema : "SchemaType" , _type = None , args = None ) -> Field :
720721 if args is None :
721722 args = dict (default = getattr (schema , "default" , None ))
722723
0 commit comments