If available, use docstrings from properties for field descriptions #954
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
supersedes #698
@spookylukey sry this took so long. Thanks for your excellent input and PR. Finally cutting down on the backlog. I had to work this through properly due to the potentially large impact.
I saw a couple of issues with your implementation, but overall liked the idea. My only gripe is that this would potentially leak more (potentially sensitive) info into the schema than expected. I mean this may pull docstrings from objects that are not necessarily related to DRF (e.g.
SubObject
). Just saying this might come as a surprise to some users, but we advice to check the schema diff on update anyway.Here are the issues I attempted to fix:
functools.partial
as we do inget_type_hints
gettattr
orcleandoc
directly. There are more complications to this and we already solved those in our own get_doc. You probably used a multi-line comment becausecleandoc
will not clean that up properly 😄. That is a solved issue withget_doc
.SerializerMethodField
methods, which is most likely the more common use-case. Added a test for it.I'll go ahead and merge this, but if there is anything missing, please don't hesitate to pick this up again. Next round will be fast, I promise 😄