Docstring and schemas problem

50 views
Skip to first unread message

Stefano Tranquillini

unread,
Aug 28, 2019, 9:20:21 AM8/28/19
to Django REST framework
Hello all

We are trying to use the schemas and documentation but I can't get the result as I wish.

I made this dummy class

class DummyApi(generics.ListCreateAPIView,
               viewsets
.ViewSet):
   
"""
    get: List all the users.
    post: Create a new user.
    """

    serializer_class
= LogInputSerializer



   
def get_queryset(self):
       
return [dict(message='ste'), dict(message='fano')]

   
def list(self, request, *args, **kwargs):
       
"""
        I'm list
        """

        usernames
= "stefano"
       
return Response(usernames)

   
def create(self, request):
       
"""
        I'm creation
        """

        usernames
= "stefano"
       
return Response(usernames)
   

And 


router
= routers.DefaultRouter()
router
.register(r'dummy', views.DummyApi, basename='dummy')
urlpatterns
= [
    path
('', include(router.urls)),
    path
('openapi', get_schema_view(
        title
=" API",
        description
="Testing"),
         name
='openapi-schema')]

So, when I open the browser I see (where the DOCSTING IS THERE)

\

And OPTION as well


I DON'T SEE THE COMMENT OF THE METHODS CREATE AND LIST

AND THE SCHEMA  URL IGNORES NAMES AND DOCSTRING.



Do you know what I'm missing?


Jani Tiainen

unread,
Aug 30, 2019, 4:39:41 PM8/30/19
to django-res...@googlegroups.com
Hi.

In my experience schema generation is really poor in DRF specially things get interesting with anything more complex.

--
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-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/c231294a-cfeb-426b-877e-2cfd1cc1dcaf%40googlegroups.com.

Carl Nobile

unread,
Aug 30, 2019, 6:23:02 PM8/30/19
to django-res...@googlegroups.com
So I should say first that this is just my opinion. I have been working with Django for over ten years and DRF for about five years. I have never built an API that wasn't extremely customized, so I never use ViewSets because they tend to tie you into very specific defaults. I always use generic views which I tend to heavily customize and do the same to serializers. I also never use routers and set up my own `urls.py` files.

I'm not sure this will help, but here is a link to my GitHub account `inventory` project. It is not finished yet. All the new code is in the develop branch. Mybe it could help. https://github.com/cnobile2012/inventory

~Carl




--
-------------------------------------------------------------------------------
Carl J. Nobile (Software Engineer)
carl....@gmail.com
-------------------------------------------------------------------------------

Carlton Gibson

unread,
Sep 1, 2019, 3:24:39 AM9/1/19
to django-res...@googlegroups.com
Hi Stefano. 

Parsing the docstring is not yet implemented for OpenAPI schemas. There is basic parsing as part of the CoreAPI stuff which could be ported. This wouldn’t be hard I’d think, so would be a good opportunity to contribute. 

A couple of points: 
* We’re never going to do anything very complex here. Basic parsing only. Since…
* The automatic schema generation intentionally just covers the core/simple cases. Beyond that you’ll need to implement your own introspection logic. (The requirements explode otherwise, for which we don’t have the capacity.)
* Our goal is to provide the right hooks to let you override the bits you need. If you find you can’t do that, then open an issue. 

HTH.

Kind Regards,

Carlton


<Auto Generated Inline Image 1.png>\

And OPTION as well

<Auto Generated Inline Image 2.png>

I DON'T SEE THE COMMENT OF THE METHODS CREATE AND LIST

AND THE SCHEMA  URL IGNORES NAMES AND DOCSTRING.


<Auto Generated Inline Image 3.png>
Do you know what I'm missing?


--
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-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/c231294a-cfeb-426b-877e-2cfd1cc1dcaf%40googlegroups.com.
<Auto Generated Inline Image 1.png><Auto Generated Inline Image 2.png><Auto Generated Inline Image 3.png>

Reply all
Reply to author
Forward
0 new messages