@@ -258,8 +258,12 @@ def collapse(cls, type_name, items: list["_ClassInfo"]) -> type[BaseModel]:
258258 r = [i .model () for i in items ]
259259
260260 if len (r ) > 1 :
261- # FIXME - merge annotations
262- ru : object = Annotated [Union [tuple (r )], items [0 ].anno ]
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 )]
263267 m : type [RootModel ] = create_model (type_name , __base__ = (ConfiguredRootModel [ru ],), __module__ = me .__name__ )
264268 elif len (r ) == 1 :
265269 m : type [BaseModel ] = cast (type [BaseModel ], r [0 ])
@@ -303,7 +307,8 @@ def from_schema(
303307 r : list [_ClassInfo ] = list ()
304308
305309 for _type in Model .types (schema ):
306- r .append (Model .createClassInfo (schema , _type , schemanames , discriminators , extra ))
310+ args = dict ()
311+ r .append (Model .createClassInfo (schema , _type , schemanames , discriminators , extra , args ))
307312
308313 m = _ClassInfo .collapse (schema ._get_identity ("L8" ), r )
309314
@@ -317,6 +322,7 @@ def createClassInfo(
317322 schemanames : list [str ],
318323 discriminators : list ["DiscriminatorType" ],
319324 extra : list ["SchemaType" ] | None ,
325+ args : dict [str , Any ] = None ,
320326 ) -> _ClassInfo :
321327 from . import v20 , v30 , v31
322328
@@ -330,7 +336,7 @@ def createClassInfo(
330336 for primitive types the anyOf/oneOf is taken care of in Model.createAnnotation
331337 """
332338 if typing .get_origin (_t := Model .createAnnotation (schema , _type = _type )) != Literal :
333- classinfo .anno = Model .createField (schema , _type = _type , args = None )
339+ classinfo .anno = Model .createField (schema , _type = _type , args = args )
334340 classinfo .root = _t
335341 elif _type == "array" :
336342 """anyOf/oneOf is taken care in in createAnnotation"""
0 commit comments