swagger란
자동으로 API 목록과 각 API의 Request Body, Query Parameter를 문서화해주며,
바로 Postman과 같이 API를 테스트해 볼 수 있는 많은 프로젝트에서 사용하는
검증된 문서화 도구입니다.
class PersonViewSet(viewsets.ReadOnlyModelViewSet):
ReadOnlyModelViewSet을 따라가보면 mixins.RetrieveModelMixin, ListModelMixin을
Mixin 하여 사용하고 있는 것을 확인할 수 있다.
그래서 PersonViewSet에 @method_decorator를 사용하려면
list와 retrieve와 관련 된 것만 사용할 수 있다.
왜냐하면 클래스로 작성되어 있기 때문이다.
아래 링크에 사용법을 자세히 설명해주고 있으니 확인해보면 좋을 거 같습니다.
@method_decorator(name='list', decorator=swagger_auto_schema(
operation_id='사람 list',
operation_description='사람 리스트 반환',
tags=['Person'],
))
@method_decorator(name='retrieve', decorator=swagger_auto_schema(
operation_id='사람 retrieve',
operation_description='사람 정보 반환',
tags=['Person'],
))
class PersonViewSet(viewsets.ReadOnlyModelViewSet):
그렇다면 list와 retieve 외에 update에도 따로 사용하고 싶은 함수가 있다고 가정하고,
@swagger_auto_schema(
method='patch',
operation_id='사람 정보 업데이트',
operation_description='사람 정보를 업데이트합니다.',
tags=['Person'],
)
@api_view(['PATCH'])
def person_update(self):
아래 링크는 swagger_auto_schema를 잘 설명해주고 있어 참고하면 좋을거같다.
'Language > Python' 카테고리의 다른 글
| List, Tuple, Dictionary, If, for, function, (0) | 2020.05.24 |
|---|---|
| Python 비동기 - Celery, Dramatiq (0) | 2020.03.05 |
| Python - unittest Mock (0) | 2020.02.20 |
| F(name), annotate(), TruncMonth() , Counter().most_common(), isinstance(objects, class) (0) | 2020.02.10 |
| 쿠키 / 세션이란 (0) | 2020.01.31 |
댓글