-
-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Description
Hi @Stranger6667, Another issue that I'm running into is with Python enum's
Given the following piece of code by default the Enum is not converted to a string
from jsonschema_rs import is_valid
import orjson
from enum import Enum
class Foo(Enum):
bar = "bar"
foo = "foo"
schema = {"properties": {"foo": {"type": "string"}}}
instance = {"foo": Foo.bar}
converted = orjson.loads(orjson.dumps(instance))
print(is_valid(schema, converted)) # True
print(is_valid(schema, instance)) # ValueError: Unsupported type: 'Foo'I am thinking of two options and wondering which you would prefer
- Automatically converting Enums to their corresponding type (str, int, etc) like how orjson does it
- Creating a
stringbased interfacevalidate_str(orjson.dumps(instance))
I like the simplicity of 1 for the end user as they don't have to worry about converting their enum's with Foo.bar.value before validating.