Discussion:
Question on usage of DRF, CoreJSon and CoreApi
Marc Chakiachvili
2018-06-17 00:14:42 UTC
Permalink
Hi all,

I experience some strange thing, after looking alone for a while, I must
have missed something important.

here is my question:
I use some Viewset with DRF:

class ServiceViewSet(viewsets.ReadOnlyModelViewSet):
"""
API entry point to Services (Retrieve, job submission)
"""
permission_classes = (ServiceAccessPermission,)
serializer_class = ServiceSerializer
parser_classes = (MultiPartParser, FormParser)
lookup_field = 'api_name'
lookup_url_kwarg = 'service_app_name'

def get_queryset(self):
""" retrieve available services for current request user """
return Service.objects.get_services(user=self.request.user)

def list(self, request, **kwargs):
""" List all available services """
serializer = ServiceSerializer(self.get_queryset(), many=True, context={'request': request})
return Response(serializer.data)

def retrieve(self, request, *args, **kwargs):
""" Retrieve Service details"""
service_tool = get_object_or_404(self.get_queryset(), api_name=kwargs.get('service_app_name'))
serializer = ServiceSerializer(service_tool, context={'request': request})
return Response(serializer.data)



When using CoreJson (AutoSchema), and coreapi cli

def list(self):
print(self.base_url + "schema")
services = self.client.get(self.base_url + "schema")
return self.client.action(services, ["services", "list"])


basically the response with coreJson is

schema: {
list()
}
services: {
submissions: {
jobs: {
read(service_app_name, submission_app_name)
create(service_app_name, submission_app_name, [version],
[short_description], [title], [email_to], [params])
}
submission_form(service_app_name, submission_app_name)
}
list()
read(service_app_name)
form(service_app_name)
jobs(service_app_name)
submission(service_app_name, submission_app_name)
}
...

When using the code, I have a response saying that data are not formatted
as expected....
raise ParseError('Top level node should be a document or error.')
coreapi.exceptions.ParseError: Top level node should be a document or error.

Any idea ? Is this because I use a serializer.data instead of list of
object ? but the serializer ,is set to return a list.

any help will be much appreciate !

Sources are here:
https://github.com/marcoooo/waves-api-client (this is not an actual
project, just testing things for now)

the source for the api are here
https://github.com/lirmm/waves-core/tree/debug-coreapi

Thanks a lot for any help !
Marc
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...