Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django rest framework 将文档添加到generics.retrieveapieview';检索';方法';s查询参数_Django Rest Framework_Drf Yasg - Fatal编程技术网

Django rest framework 将文档添加到generics.retrieveapieview';检索';方法';s查询参数

Django rest framework 将文档添加到generics.retrieveapieview';检索';方法';s查询参数,django-rest-framework,drf-yasg,Django Rest Framework,Drf Yasg,我有一个简单的视图,它将“email”作为一个查询参数,我希望将其记录在OpenAPI自动生成的模式中。到目前为止,我尝试在API视图类定义上应用method\u decorator和swagger\u auto\u schema,但没有成功: from drf_yasg.utils import swagger_auto_schema from drf_yasg import openapi from django.utils.decorators import method_decorato

我有一个简单的视图,它将“email”作为一个查询参数,我希望将其记录在OpenAPI自动生成的模式中。到目前为止,我尝试在API视图类定义上应用
method\u decorator
swagger\u auto\u schema
,但没有成功:

from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
from django.utils.decorators import method_decorator


@method_decorator(name='retrieve', decorator=swagger_auto_schema(manual_parameters=[
    openapi.Parameter('email', openapi.IN_QUERY, description="Email to be checked", type=openapi.TYPE_STRING)]))
class EmailCheckView(generics.RetrieveAPIView):
    serializer_class = EmailCheckSerializer

    def get_queryset(self):
        email = self.request.query_params.get('email', None)
        if not email:
            raise Http404
        return User.objects.filter(email=self.kwargs['email'])
自动生成的模型只包含来自序列化程序的主体信息。你知道怎么了吗

DRF:3.12.2

drf yasg:1.20.0

我的招摇过市模式添加到URL.py中,带有:

from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
   openapi.Info(
      title="My API",
      default_version='v1',
      description="",
   ),
   public=True,
   permission_classes=[permissions.AllowAny],
)

urlpatterns = [
    ...
    path('docs/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    ...
] 
改变


@method\u装饰器(
name=“get”#这里有零钱
decorator=swagger\u auto\u模式(
手动参数=[
参数(
“电子邮件”,
openapi.IN_查询,
description=“要检查的电子邮件”,
type=openapi.type\u字符串,
)
]
),
)
类EmailCheckView(泛型.RetrieveAppView):
serializer\u class=EmailCheckSerializer
def get_queryset(自我):
email=self.request.query_params.get(“email”,无)
如果不是电子邮件:
提高Http404
返回User.objects.filter(email=self.kwargs[“email”])
注意:我不确定问题是否属于
方法修饰符(…)
drf yasg
本身

name='retrieve'
name='get'
@method_decorator(
    name="get", # change is here
    decorator=swagger_auto_schema(
        manual_parameters=[
            openapi.Parameter(
                "email",
                openapi.IN_QUERY,
                description="Email to be checked",
                type=openapi.TYPE_STRING,
            )
        ]
    ),
)
class EmailCheckView(generics.RetrieveAPIView):
    serializer_class = EmailCheckSerializer

    def get_queryset(self):
        email = self.request.query_params.get("email", None)
        if not email:
            raise Http404
        return User.objects.filter(email=self.kwargs["email"])