-
Notifications
You must be signed in to change notification settings - Fork 270
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
NullEnum reference generated for nullable enumerated fields #235
Comments
hi @rvinzent, this has come up before. According to the Open API documentation, this is actually the proper way to do it. the https://swagger.io/docs/specification/data-models/enums/ we also found out that some client generator have trouble with this "correct" modelling. for that case we created a setting to disable the null/blank enums (#185, 05e4b90): does that make sense? |
Yes! Thank you for the explanation and the fix! |
Hi, the problem with setting Thanks |
hi @idesoto-rover, so we support the correct way (True), the wrong way (False). i suppose you ask this due to client generation. which client target do you use? the generator targets are very picky with this stuff. have you evaluated that the single definition actually produces the desired outcome? i did some testing myself back then but i don't have notes on it anymore. |
Hi, the issue I'm having is with a validation library that fails to validate this correctly because a valid value is matching both branches of the |
To me it would more sense if with |
@valentijnscholten i'm not sure what you mean exactly. with
otherwise you would have to generate 4 different variations of the same Enum. you cannot simply add we could add another option to generate those 4 but it wouldn't be pretty either. |
Yeah, the code I am working with doesn't understand Curious: Why would it need 4 variations, I can only think of 2. One with |
those are the 4 possible variations that DRF allows out of the box:
and the naming would even be more horrendous: and adding stuff on demand is not a good idea either. lets say |
What I meant was that the most compatible way is to not use components at all for enums. Could result in a bit of duplication, but might be preferable for some, or even needed to make client generation (or validation as mentioned above) work. I understand that the current way is "the official way", just dealing with some code here that can't handle it. |
if you don't want the enum extraction functionality you can simply turn it off. this painstakingly created postprocessing hook is purely optional and not part of the core generator. # Postprocessing functions that run at the end of schema generation.
# must satisfy interface result = hook(generator, request, public, result)
'POSTPROCESSING_HOOKS': [
'drf_spectacular.hooks.postprocess_schema_enums'
], just disable the hook. that should give you what you asked for. 'POSTPROCESSING_HOOKS': [] |
Thanks, I didn't realize we could turn it off. But it helps a lot. |
Describe the bug
When using a nullable
ChoiceField
field, a weirdNullEnum
reference is generated, and this causes issues with auto-generated client modules. While it renders a correct payload in the Swagger UI, it does not play nicely with code generation tools.To Reproduce
Expected behavior
No
NullEnum
reference should be generated, and the following should be produced.The text was updated successfully, but these errors were encountered: