-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new feature Issue: Enum -> enum list transformed into key: value
intead of just key for models.IntegerChoices and models.TextChoices
#563
Comments
Hi @IvanSaldoZ, I absolutely get where you are coming from. Unfortunately, your solution might look acceptable in Swagger, but is ultimately broken by design. Swagger would create invalid example values and code generators would likely also be broken. As per specification, your custom string would be interpreted as the actual enum value, which is of course incorrect. Essentially this has been an open issue in OpenAPI and JSON Schema for years now. Anything we would come up with would be a hack with little to no support in the tooling ecosystem. Duplicate of #337, proposal PR #403 Upstream isuses: OAI/OpenAPI-Specification#681 |
Hi, @tfranzel, thank you for your reply. Very sad to hear that. Acutally in my case Swagger and Redoc works fine with this tweak (hack). Maybe if the flow will go further and the yaml file will be proccessed by another software - it will be broken. But not in my case. Is it possible to implement this feature with the flag something like "ENUM_KEY_VAL_ENABLED_NON_SAFE" is equal to False by default. And those who wants to use this tweak will use it, but the rest programmers will dont even know about it and nothing will be broken. You will really, i mean REALLY help to a lot of managers, frontenders, QAs and of course backenders with their daily work if something like this will be in the package. Thank you! |
Hey @IvanSaldoZ, I hear you. Given we already have a big set of complicated settings, I would rather not add this. But mainly because this "feature" violates OpenAPI 3 in several ways, even it other tools tolerate it. At this point we do not intend to ship options that produce an invalid OpenAPI 3 schema. I would recommend for you to write a postprocessing hook that does this transformation: https://drf-spectacular.readthedocs.io/en/latest/customization.html#step-6-postprocessing-hooks |
Thanks to @valentijnscholten for the first attempt in #403
Thanks to @valentijnscholten for the first attempt in #403
Please, extend you app with the following:
plumbing.py
This will add new feature:
Enum -> enum list transformed into
key: value
intead of just key for models.IntegerChoices and models.TextChoices choices classesThis will very be helpful when viewing the Enum parameters in Swagger and Redoc. Thank you!
The text was updated successfully, but these errors were encountered: