fix: Union type on components (#4137)

* 🐛 (type_extraction.py): fix condition to correctly handle UnionType objects in type extraction process

* ✨ (test_schema.py): add support for additional data types and nested structures in post_process_type function to improve type handling and flexibility

* ✅ (test_schema.py): add additional test cases for post_process_type function to cover various Union types and combinations for better test coverage and accuracy
This commit is contained in:
Cristhian Zanforlin Lousa 2024-10-14 18:02:15 -03:00 • committed by GitHub
commit db2c12183c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 59 additions and 4 deletions

View file

@ -55,7 +55,9 @@ def post_process_type(_type):
# If the return type is not a Union, then we just return it as a list
inner_type = _type[0] if isinstance(_type, list) else _type
if not hasattr(inner_type, "__origin__") or inner_type.__origin__ != Union:
if (not hasattr(inner_type, "__origin__") or inner_type.__origin__ != Union) and (
not hasattr(inner_type, "__class__") or inner_type.__class__.__name__ != "UnionType"
):
return _type if isinstance(_type, list) else [_type]
# If the return type is a Union, then we need to parse it
_type = extract_union_types_from_generic_alias(_type)