Open jisaacstone opened 2 years ago
I am also trying to use enum names instead of values (it would be a more sensible default, imo). The problem is that enums are handled as a special case in a different order for encode, decode, and schemas. A FieldEncoder works for encode and decode because the field encoders are checked before the enum special case. For schemas, the enum case is checked first, so any enum field encoder is never reached.
I think all that needs to change for this to work is to process the field encoders first in _get_field_schema
. You would still need to register the encoder for each enum type. It would be great if there was a way to register a FieldEncoder
for a type and all subtypes as well, but the field encoders would have to receive the subtype as an argument.
I have an Enum where the numeric values are used internally, but the string values are used in the API calls.
I have solved this by using the FieldEncoder class. But it breaks when I call
from_dict
with validate=True.Seems to be because MyClass._field_encoders[field.type].json_schema is different than MyClass._get_field_schema(field, schema_options)
Example: