Search code examples
pythondjangodjango-rest-frameworkdrf-spectacular

drf-spectacular: Add description to HTTP_204


@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,                                                                                
       ),                                                                                                    
   ....]                                                                                                     
)

This is what I have tried, but what I get is enter image description here


Solution

  • the new drf-spectacular version 0.15.1 added the OpenApiResponse feature. this snippet is from the test cases:

    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,
    })