As per the DRF documentation I started using ViewSet and have implemented list, retrieve, create, update and destroy
actions. I have another APIView for which I was able to write schema (ManualSchema) and when I navigate to /docs/
I am able to the documentation as well as live endpoint for interaction.
I wish to create separate schema for each of the viewset action. I tried writing one but it doesn't show up so I think I am missing something.
Here is the code:
class Clients(viewsets.ViewSet):
'''
Clients is DRF viewset which implements `create`, `update`, `read` actions by implementing create, update, list and retrieve functions respectively.
'''
list_schema = schemas.ManualSchema(fields=[
coreapi.Field(
'status',
required=False,
location='query',
description='Accepted values are `active`, `inactive`'
),
],
description='Clients list',
encoding='application/x-www-form-urlencoded')
@action(detail=True, schema=list_schema)
def list(self, request):
'''Logic for listing'''
def retrieve(self, request, oid=None):
'''Logic for retrieval'''
create_schema = schemas.ManualSchema(fields=[
coreapi.Field(
'name',
required=False,
location='body',
),
coreapi.Field(
'location',
required=False,
location='body',
),
],
description='Clients list',
encoding='application/x-www-form-urlencoded')
@action(detail=True, schema=create_schema)
def create(self, request):
'''Logic for creation'''
I think what you are trying to do is not possible. The
ViewSet
does not provide any method handlers, hence, you cannot use the@action
decorator on the methodscreate
andlist
, as they are existing routes.