AutoSchema schema.get_operation missing positional argument #7930
Unanswered
vabene1111
asked this question in
Potential Issue
Replies: 2 comments 3 replies
-
Did you assign your |
Beta Was this translation helpful? Give feedback.
3 replies
-
For everyone in the future looking to document query parameters with django rest framework and openapi this is a working minimal example. Thanks to DRF Team for the awesome and super fast help and cool library from rest_framework.schemas.openapi import AutoSchema
from rest_framework.schemas.utils import is_list_view
class CustomSchema(AutoSchema):
def get_path_parameters(self, path, method):
if not is_list_view(path, method, self.view):
return []
parameters = super().get_path_parameters(path, method)
parameters.append(
{
"name": 'query',
"in": "query",
"required": False,
"description": 'description',
'schema': {
'type': 'string', # TODO: integer, pattern, ...
},
}
)
return parameters
class RecipeViewSet(viewsets.ModelViewSet):
schema=CustomSchema() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Running Django
3.2
, DRF:3.12.4
, Python3.8
on Windows 10I have an api where certain list endpoints can have optional get query parameters for filtering. I want to document those properly so they show up nicely in the open api doc and redoc visualization.
I have spend the last few hours reading up on this and reverse engineering the openapi generator class and all methods involved in the generation of the docs. I also read all Issues and discussions i could find in this repo. I found the following
The
manual_fields
that were supported by coreapi have been removed in favor of overwriting theAutoSchema
methods.As instructed by @carltongibson in #6992 (comment) i did the following (simplified during debugging, neither the original nor anything in between works)
The openapi schema is generated dynamically by this url
As soon as I assign this schema to the
RecipeViewSet
I get the following error.I have tried many different variations, dumming down the Viewset by removing all but the absolutely necessary parameters and methods but nothing seems to work. Is this a bug or do i need to inherit another Class/implement another method ?
During my search i have found countless examples of people struggling to do this very simple thing: document query parameters. I think a small and clear example on how to do this would be really really helpful to a lot of people.
Thanks for the help and also thanks for this awesome framework, once some things are understood it is a real pleasure to use and does so many things just awesomly right.
Beta Was this translation helpful? Give feedback.
All reactions