0
@extend_schema(                                                                                                                    
    request=MyRequestSerializer,                                                                             
    responses={200: MyResponseSerializer(many=True),                                                         
               204: None,                                                                                    
               },                                                                                            
    examples=[                                                                                               
       OpenApiExample(                                                                                       
           '204',                                                                                            
           status_codes=['204'],                                                                             
           summary="My documentation summary",                                                               
           description="My documentation description",                                                       
          response_only=True,                                                                                
       ),                                                                                                    
   ....]                                                                                                     
)

这是我尝试过的,但我得到的是 在此处输入图像描述

4

1 回答 1

1

drf-spectacular版本0.15.1增加了该OpenApiResponse功能。此片段来自测试用例:

from drf_spectacular.utils import OpenApiResponse, extend_schema

@extend_schema(
    description='creation description', 
    responses={
        201: OpenApiResponse(response=int, description='creation with int response.'),
        204: OpenApiResponse(description='creation with no response.'),
        223: None,
})
于 2021-04-21T07:44:15.390 回答