@@ -650,3 +650,76 @@ def get_response_type(schema, version):
650650
651651def attribute_path (attribute ):
652652 return "." .join (attribute_name (a ) for a in attribute .split ("." ))
653+
654+
655+ def prepare_oneof_methods (model , get_type_func ):
656+ """
657+ Pre-compute method information for oneOf types to handle erasure collisions.
658+
659+ Returns a list of dicts with:
660+ - schema: the original oneOf schema
661+ - param_type: full parameterized type (e.g., "List<String>")
662+ - unparam_type: unparameterized type (e.g., "List")
663+ - use_factory: True if factory method needed (collision detected)
664+ - constructor_name: name for constructor/factory method
665+ - getter_name: name for getter method
666+ """
667+ # Handle both dict-style and object-style access
668+ if isinstance (model , dict ):
669+ one_of = model .get ('oneOf' , [])
670+ elif hasattr (model , 'oneOf' ):
671+ one_of = model .oneOf
672+ elif hasattr (model , 'get' ):
673+ one_of = model .get ('oneOf' , [])
674+ else :
675+ return []
676+
677+ if not one_of :
678+ return []
679+
680+ # First pass: count unparameterized types
681+ unparam_counts = {}
682+ for oneOf in one_of :
683+ param_type = get_type_func (oneOf )
684+ unparam_type = un_parameterize_type (param_type )
685+ unparam_counts [unparam_type ] = unparam_counts .get (unparam_type , 0 ) + 1
686+
687+ # Second pass: compute method names
688+ result = []
689+ for oneOf in one_of :
690+ param_type = get_type_func (oneOf )
691+ unparam_type = un_parameterize_type (param_type )
692+ has_collision = unparam_counts [unparam_type ] > 1
693+
694+ # Compute constructor/factory method name
695+ if has_collision :
696+ if param_type .startswith ('List<' ):
697+ inner_type = param_type [5 :- 1 ]
698+ constructor_name = f"from{ inner_type } List"
699+ else :
700+ safe_type = param_type .replace ('<' , '' ).replace ('>' , '' ).replace (' ' , '' ).replace (',' , '' )
701+ constructor_name = f"from{ safe_type } "
702+ else :
703+ constructor_name = None # Regular constructor
704+
705+ # Compute getter method name
706+ if has_collision :
707+ if param_type .startswith ('List<' ):
708+ inner_type = param_type [5 :- 1 ]
709+ getter_name = f"get{ inner_type } List"
710+ else :
711+ safe_type = param_type .replace ('<' , '' ).replace ('>' , '' ).replace (' ' , '' ).replace (',' , '' )
712+ getter_name = f"get{ safe_type } "
713+ else :
714+ getter_name = f"get{ unparam_type } "
715+
716+ result .append ({
717+ 'schema' : oneOf ,
718+ 'param_type' : param_type ,
719+ 'unparam_type' : unparam_type ,
720+ 'use_factory' : has_collision ,
721+ 'constructor_name' : constructor_name ,
722+ 'getter_name' : getter_name ,
723+ })
724+
725+ return result
0 commit comments