@@ -113,7 +113,6 @@ class _PropertyInfo:
113113 type_ : str
114114
115115 root : Any = None
116- anno : pydantic .Field = None
117116 config : dict [str , Any ] = dataclasses .field (default_factory = dict )
118117 properties : dict [str , _PropertyInfo ] = dataclasses .field (
119118 default_factory = lambda : collections .defaultdict (lambda : _ClassInfo ._PropertyInfo ())
@@ -258,17 +257,10 @@ def collapse(cls, type_name, items: list["_ClassInfo"]) -> type[BaseModel]:
258257 r = [i .model () for i in items ]
259258
260259 if len (r ) > 1 :
261- # Annotations are collected, last element has all of them
262- # ru: object = Annotated[Union[tuple(r)], items[-1].anno]
263- v = list ()
264- for i in range (len (items )):
265- v .append (Annotated [r [i ], items [i ].anno ])
266- ru = Annotated [Union [tuple (v )], Field (default = None )]
260+ ru = Annotated [Union [tuple (r )], Field (default = None )]
267261 m : type [RootModel ] = create_model (type_name , __base__ = (ConfiguredRootModel [ru ],), __module__ = me .__name__ )
268262 elif len (r ) == 1 :
269263 m : type [BaseModel ] = cast (type [BaseModel ], r [0 ])
270- if items [0 ].anno :
271- m = Annotated [m , items [0 ].anno ]
272264 if not is_basemodel (m ):
273265 m = create_model (type_name , __base__ = (ConfiguredRootModel [m ],), __module__ = me .__name__ )
274266 else : # == 0
@@ -336,8 +328,10 @@ def createClassInfo(
336328 for primitive types the anyOf/oneOf is taken care of in Model.createAnnotation
337329 """
338330 if typing .get_origin (_t := Model .createAnnotation (schema , _type = _type )) != Literal :
339- classinfo .anno = Model .createField (schema , _type = _type , args = args )
340- classinfo .root = _t
331+ classinfo .root = Annotated [_t , Model .createField (schema , _type = _type , args = args )]
332+ else :
333+ classinfo .root = _t
334+
341335 elif _type == "array" :
342336 """anyOf/oneOf is taken care in in createAnnotation"""
343337 classinfo .root = Model .createAnnotation (schema , _type = "array" )
@@ -364,8 +358,10 @@ def createClassInfo(
364358 if _type in Model .types (i )
365359 )
366360 if schema .discriminator and schema .discriminator .mapping :
367- classinfo .root = Union [t ]
368- classinfo .anno = Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
361+ classinfo .root = Annotated [
362+ Union [t ], Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
363+ ]
364+
369365 else :
370366 if len (t ):
371367 classinfo .root = Union [t ]
@@ -381,8 +377,9 @@ def createClassInfo(
381377 if _type in Model .types (i )
382378 )
383379 if schema .discriminator and schema .discriminator .mapping :
384- classinfo .root = Union [t ]
385- classinfo .anno = Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
380+ classinfo .root = Annotated [
381+ Union [t ], Field (discriminator = Model .nameof (schema .discriminator .propertyName ))
382+ ]
386383 else :
387384 if len (t ):
388385 classinfo .root = Union [t ]
@@ -458,8 +455,8 @@ def validate_patternProperties(self_):
458455 """
459456 assert isinstance (schema , v20 .Schema )
460457 schema_ = v20 .Schema (type = "string" , format = "binary" )
461- classinfo . root = Model .createAnnotation (schema_ , _type = "string" )
462- classinfo .anno = Model .createField (schema_ , _type = "string" , args = None )
458+ _t = Model .createAnnotation (schema_ , _type = "string" )
459+ classinfo .root = Annotated [ _t , Model .createField (schema_ , _type = "string" , args = None )]
463460 else :
464461 raise ValueError (_type )
465462
0 commit comments