|
7 | 7 | from ... import schema as oai
|
8 | 8 | from ... import utils
|
9 | 9 | from ..errors import ParseError, PropertyError
|
| 10 | +from .enum_property import EnumProperty |
10 | 11 | from .property import Property
|
11 | 12 | from .schemas import Class, Schemas, parse_reference_path
|
12 | 13 |
|
@@ -49,15 +50,32 @@ def get_imports(self, *, prefix: str) -> Set[str]:
|
49 | 50 |
|
50 | 51 |
|
51 | 52 | def _merge_properties(first: Property, second: Property) -> Union[Property, PropertyError]:
|
52 |
| - if first.__class__ != second.__class__: |
53 |
| - return PropertyError(header="Cannot merge properties", detail="Properties are two different types") |
54 | 53 | nullable = first.nullable and second.nullable
|
55 | 54 | required = first.required or second.required
|
56 |
| - first = attr.evolve(first, nullable=nullable, required=required) |
57 |
| - second = attr.evolve(second, nullable=nullable, required=required) |
58 |
| - if first != second: |
59 |
| - return PropertyError(header="Cannot merge properties", detail="Properties has conflicting values") |
60 |
| - return first |
| 55 | + |
| 56 | + if first.__class__ == second.__class__: |
| 57 | + first = attr.evolve(first, nullable=nullable, required=required) |
| 58 | + second = attr.evolve(second, nullable=nullable, required=required) |
| 59 | + if first != second: |
| 60 | + return PropertyError(header="Cannot merge properties", detail="Properties has conflicting values") |
| 61 | + return first |
| 62 | + elif first.__class__.__name__ == "StringProperty" and second.__class__ == EnumProperty and second.value_type == str: |
| 63 | + second = attr.evolve(second, nullable=nullable, required=required) |
| 64 | + return second |
| 65 | + elif second.__class__.__name__ == "StringProperty" and first.__class__ == EnumProperty and first.value_type == str: |
| 66 | + first = attr.evolve(first, nullable=nullable, required=required) |
| 67 | + return first |
| 68 | + elif first.__class__.__name__ == "IntProperty" and second.__class__ == EnumProperty and second.value_type == int: |
| 69 | + second = attr.evolve(second, nullable=nullable, required=required) |
| 70 | + return second |
| 71 | + elif second.__class__.__name__ == "IntProperty" and first.__class__ == EnumProperty and first.value_type == int: |
| 72 | + first = attr.evolve(first, nullable=nullable, required=required) |
| 73 | + return first |
| 74 | + else: |
| 75 | + return PropertyError( |
| 76 | + header="Cannot merge properties", |
| 77 | + detail=f"{first.__class__}, {second.__class__}Properties have incompatible types", |
| 78 | + ) |
61 | 79 |
|
62 | 80 |
|
63 | 81 | class _PropertyData(NamedTuple):
|
|
0 commit comments