Hi DRFers,
I have a model like this:
class Job(Model):
class JobState(IntEnum):
RECEIVED = 0
PROCESSING = 1
DONE = 2
FAILED = 3
@classmethod
def choices(cls: Any) -> List[Tuple[int, str]]:
return [(key.value, key.name) for key in cls]
state = IntegerField(
choices=JobState.choices(),
default=JobState.RECEIVED,
)
I have a ModelSerializer:
class JobSerializer(serializers.ModelSerializer):
class Meta:
model = Job
fields = [
"state",
]
How do I get the OpenAPI schema to show the _names_ of the fields, not the enum values?
My schema generates to:
| "state": { |
| "enum": [ |
| 0, |
| 1, |
| 2, |
| 3 |
| ], |
| "type": "integer", |
| "minimum": -2147483648, |
| "maximum": 2147483647 |
| }, |
Any ideas on how to make the enum use the name, not the value?
Thanks!
-Adam