Closed s-knibbs closed 4 years ago
I propose to add an argument (validate_enums: bool = True
), to the from_dict
method which will generate the schema but without any enum specifiers and validate against that. For example:
class PetType(Enum):
CAT = "cat"
DOG = "dog"
@dataclass
class Pet(JsonSchemaMixin):
name: str
type: PetType
p = Pet.from_dict({"name": "snakey", "type": "python"}, validate_enums=False)
>>> p.type
'python'
It should be possible to support deserialisation of unrecognised enum values without throwing an error so that we handle new enum members gracefully. Like protocol buffers, the underlying enum value should be left as is.