A library serializer `__init__` calls `kwargs['context']['request']` - how to skip/ignore?
See original GitHub issueDescribe the bug
We use a package called django_comments_xtd
. In it, django_comments_xtd.api.serializers.ReadCommentSerializer.__init__
calls self.request = kwargs['context']['request']
. How can I work round this or simply skip introspection of this class?
from drf_spectacular.plumbing import get_lib_doc_excludes as original_get_lib_doc_excludes
def get_lib_doc_excludes():
from django_comments_xtd.api import serializers as comment_serializers
from django_comments_xtd.api import views as comment_views
return (
original_get_lib_doc_excludes()
+ [getattr(comment_serializers, c) for c in dir(comment_serializers) if isclass(c)]
+ [getattr(comment_views, c) for c in dir(comment_views) if isclass(c)]
)
SPECTACULAR_SETTINGS = {
"GET_LIB_DOC_EXCLUDES": "path.to.above.build_docs.get_lib_doc_excludes",
}
To Reproduce pip install django_comments_xtd ./manage.py spectacular --file openapi.yml
Expected behavior
I need a way of skipping this serializer. I have tried returning the class from a custom get_lib_doc_excludes
, or all of the package’s view classes. I have tried to figure out a way with OpenApiSerializerExtension
. I have even tried monkey-patching. Apologies if I missed something.
Issue Analytics
- State:
- Created 10 months ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Exclude a path (so that it won't be visible in Swagger),about ...
(inaccessible) library code: extension and/or hooks ... A library serializer `__init__` calls `kwargs['context']['request']` - how to skip/ignore?
Read more >Tfranzel Drf-Spectacular Issues - IssueHint
A library serializer `__init__` calls `kwargs['context']['request']` - how to skip/ignore? open, 15, 2022-11-12, 2022-12-07.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Amazing thank you. Have updated my pip requirement to last commit on master:
Will post back here once this is released (will be version of drf-spectacular after 0.24.2).
I gather the extension isn’t a wholesale replacement of the class then, given even with the init fix it still raises the context KeyError on 0.24.2.
I can break packages as we only ever use
drf-spectacular
as a management command (as our API is too large to introspect live), and I only apply these fixes then, but forgot this is not standard usage.Enormous thanks for sticking with this, your help is very much appreciated, and I’ve learned several useful new things.
you also may want to use
to exclude the duplicated format endpoints.