Right now, Union types are encoded as oneOf in the json_schema.
This causes errors if you have a union of two types that serialize to a compatible representation.
The following code produces a validation error:
from dataclasses import dataclass
from dataclasses_jsonschema import JsonSchemaMixin
from enum import Enum
from typing import Union
class E(Enum):
A= 'a'
B= 'b'
@dataclass
class Data(JsonSchemaMixin):
field : Union[E,str] = E.A
a=Data()
a.to_dict(validate=True)
This is because E.A is serialized to 'a' which is both a valid E and a valid str.
I think the proper validation here would be to use anyOf.
What do you think?
Right now, Union types are encoded as
oneOf
in the json_schema. This causes errors if you have a union of two types that serialize to a compatible representation.The following code produces a validation error:
This is because E.A is serialized to 'a' which is both a valid
E
and a validstr
. I think the proper validation here would be to useanyOf
. What do you think?