drf-spectacular 的 extend_schema 不工作

drf-spectacular's extend_schema not working

我最近在我的项目中从 drf-yasg 迁移到 drf-spectacular,但是 @extend_schema 装饰器似乎没有向我生成的模式添加任何信息:

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

这是生成的架构的相关部分:

 /search/fetch/:
    post:
      operationId: searchFetchCreate
      description: ''
      tags:
      - search
      security:
      - jwtAuth: []
      responses:
        '200':
          description: No response body

这里有一些额外的上下文信息:

router = routers.DefaultRouter()
router.register(r'search', views.SearchView, basename='search')

urlpatterns = [
    path('', include(router.urls), name="search"),
]
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
[...]

这是由于 methods=['post'], 而不是 @extend_schema 中的 methods=['POST'],