[英]drf-spectacular's extend_schema not working
I recently migrated from drf-yasg
to drf-spectacular
on my project, but the @extend_schema
decorator does not seems to add any information to my generated schema:我最近在我的项目中从drf-yasg
迁移到drf-spectacular
,但@extend_schema
装饰器似乎没有向我生成的模式添加任何信息:
views.py
class SearchView(GenericViewSet):
serializer_class = serializers.CriterionSerializer
@extend_schema(
methods=['post'],
summary="Find patients according to search query.",
description="Search for patients related to Documents found with the given query.",
request=PolymorphicProxySerializer(
component_name='Criterion',
serializers=[
serializers.TextCriterionSerializer, serializers.GroupCriterionSerializer,
],
resource_type_field_name='type',
)
)
@action(detail=False, methods=['POST'])
def fetch(self, request):
serializer = serializers.CriterionSerializer(data=request.data)
if not serializer.is_valid(raise_exception=True):
return Response(serializer.errors, status=400)
return serializers.PatientDocumentSerializer(
serializer.create(serializer.validated_data).fetch(), context={'request': request},
many=True
).data
And here's the relevant part of the generated schema:这是生成的架构的相关部分:
/search/fetch/:
post:
operationId: searchFetchCreate
description: ''
tags:
- search
security:
- jwtAuth: []
responses:
'200':
description: No response body
Here some additional information for context:这里有一些关于上下文的附加信息:
urls.py
router = routers.DefaultRouter()
router.register(r'search', views.SearchView, basename='search')
urlpatterns = [
path('', include(router.urls), name="search"),
]
SPECTUACULAR_SETTINGS
SPECTACULAR_SETTINGS = {
'TITLE': 'API',
'VERSION': '1.0.0',
'CAMELIZE_NAMES': True,
'COMPONENT_SPLIT_REQUEST': True,
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
'SWAGGER_UI_SETTINGS': {
'deepLinking': True,
'filter': True,
'displayRequestDuration': True,
'syntaxHighlight.activate': True,
'syntaxHighlight.theme': 'monokai',
},
}
$ pip3 show django drf-spectacular
Name: Django
Version: 2.2.13
[...]
---
Name: drf-spectacular
Version: 0.17.1
[...]
This was due to methods=['post'],
instead of methods=['POST'],
inside @extend_schema
.这是由于@extend_schema
内部的methods=['post'],
而不是methods=['POST'],
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.