@@ -320,7 +320,6 @@ def validate(self):
320320 for prop , val in six .iteritems (self ._properties ):
321321 if val is None :
322322 continue
323-
324323 if isinstance (val , ProtocolBase ):
325324 val .validate ()
326325 elif getattr (val , "isLiteralClass" , None ) is True :
@@ -502,9 +501,22 @@ def construct(self, uri, *args, **kw):
502501
503502 def _construct (self , uri , clsdata , parent = (ProtocolBase ,), ** kw ):
504503 if "anyOf" in clsdata :
505- raise NotImplementedError ("anyOf is not supported as bare property" )
504+ if kw .get ("any_of" , None ) is None :
505+ raise NotImplementedError (
506+ "anyOf is not supported as bare property (workarounds available by setting any_of flag)"
507+ )
508+ if kw ["any_of" ] == "use-first" :
509+ # Patch so the first anyOf becomes a single oneOf
510+ clsdata ["oneOf" ] = [
511+ clsdata ["anyOf" ].pop (0 ),
512+ ]
513+ del clsdata ["anyOf" ]
514+ else :
515+ raise NotImplementedError (
516+ f"anyOf workaround is not a recognized type (any_of = { kw ['any_of' ]} )"
517+ )
506518
507- elif "oneOf" in clsdata :
519+ if "oneOf" in clsdata :
508520 """If this object itself has a 'oneOf' designation,
509521 then construct a TypeProxy.
510522 """
@@ -561,7 +573,7 @@ def _construct(self, uri, clsdata, parent=(ProtocolBase,), **kw):
561573 uri ,
562574 item_constraint = clsdata_copy .pop ("items" ),
563575 classbuilder = self ,
564- ** clsdata_copy
576+ ** clsdata_copy ,
565577 )
566578 return self .resolved [uri ]
567579
@@ -699,6 +711,7 @@ def _build_object(self, nm, clsdata, parents, **kw):
699711 else :
700712 uri = "{0}/{1}_{2}" .format (nm , prop , "<anonymous_field>" )
701713 try :
714+ # NOTE: Currently anyOf workaround is applied on import, not here for serialization
702715 if "oneOf" in detail ["items" ]:
703716 typ = TypeProxy (
704717 self .construct_objects (
0 commit comments