Skip to content
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

Enum key/value description #952

Merged
merged 2 commits into from
Mar 3, 2023
Merged

Enum key/value description #952

merged 2 commits into from
Mar 3, 2023

Conversation

tfranzel
Copy link
Owner

@tfranzel tfranzel commented Mar 2, 2023

add optional (default on) feature to show enum key/value listing in description string like outlined in #403.

related issues: #337 #403 #105 #563

@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02 🎉

Comparison is base (eeb8a11) 98.61% compared to head (cb47399) 98.63%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #952      +/-   ##
==========================================
+ Coverage   98.61%   98.63%   +0.02%     
==========================================
  Files          68       68              
  Lines        8074     8126      +52     
==========================================
+ Hits         7962     8015      +53     
+ Misses        112      111       -1     
Impacted Files Coverage Δ
drf_spectacular/contrib/django_filters.py 91.50% <100.00%> (+1.79%) ⬆️
drf_spectacular/hooks.py 100.00% <100.00%> (ø)
drf_spectacular/openapi.py 97.62% <100.00%> (+<0.01%) ⬆️
drf_spectacular/plumbing.py 97.29% <100.00%> (+0.01%) ⬆️
tests/contrib/test_django_filters.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tfranzel tfranzel merged commit e98b0c6 into master Mar 3, 2023
@tfranzel tfranzel deleted the enum_desc branch March 3, 2023 19:30
return append_meta(build_choice_field(field), meta)
schema = build_choice_field(field)
if 'description' in meta:
meta['description'] = meta['description'] + '\n\n' + schema.pop('description')
Copy link

@HansAarneLiblik HansAarneLiblik Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates a KeyError if schema does not have description. You need to use schema.pop('description', None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tfranzel this is breaking our current build, because we set "ENUM_GENERATE_CHOICE_DESCRIPTION": False

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, can't seem do a release without a .1 apparently.

You need to use schema.pop('description', None)

would lead to a None str concat TypeError, but I get the point.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will wait for the release until tonight to see whether something else will come up.

if prop_schema.get('description', '').startswith('*'):
enum_schema['description'] = prop_schema.pop('description')
elif '\n\n*' in prop_schema.get('description', ''):
_, _, post = prop_schema['description'].partition('\n\n*')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apology for commenting on merging MR, @tfranzel .

Just a question about these changes...

We have a serializer with field (choices) and it has help_text. Unfortunately this help text is not preserved in the description of the enum due to this line. How we can preserve this description along with choices?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sshishov, the help_text should still be there in the serializer component (NOT the enum component as it belongs to the field). This could otherwise lead confusing descriptions actually belonging somewhere else.

If that is not the case, please open new issue with a reproduction and full example. thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants