marcgibbons / django-rest-swagger

Swagger Documentation Generator for Django REST Framework: deprecated
https://marcgibbons.com/django-rest-swagger/
BSD 2-Clause "Simplified" License
2.59k stars 599 forks source link

Method docstrings not included in generated docs #537

Closed jwineinger closed 7 years ago

jwineinger commented 8 years ago

I recently upgraded from 0.3.5 to 2.0.4. Previously, docstrings on view methods (MyView.get) would be included in the swagger generated docs, but with the new version I don't get any docs included. It does seem to introspect serializer fields and such, but the docstrings help users of the API understand what an endpoint does and when to use it. Is there any way to get those included with the current release?

jwineinger commented 8 years ago

Looks like django-rest-framework doesn't support it yet =P

https://github.com/tomchristie/django-rest-framework/issues/4241

Add descriptions to schema generation, and document use of describe.

tawanda commented 8 years ago

I also have this problem, the old version of rest swagger imported doc strings, and also showed dictionaries in the doc string nicely formatted, Is there an option to manually include them?

NickStefan commented 8 years ago

Also looking for a solution

tomatotiger commented 8 years ago

I also have this problem

alexmicrosrv commented 8 years ago

Also the same problem. But when I make a GET request with the DRF API, docstrings appear on top of the result page. So it's a posible django-rest-swagger problem ?

blurrcat commented 8 years ago

It seems this project has nothing to do with the problem. The schema generation part is now(restframework 3.4+) done by restframework and this project merely uses generated coreapi objects to render swagger.json.

jwineinger commented 8 years ago

This project will have to implement it with DRF supports it. I did a quick hack to my local DRF to include the docstrings, verified that they are output in the XHR request, but did not appear in the django-rest-swagger front-end.

blurrcat commented 8 years ago

As a quick workaround, try the following:

class SchemaGenerator(schemas.SchemaGenerator):
    def get_link(self, path, method, callback, view):
        # link is an instance of `coreapi.Link`
        link = super(
            SchemaGenerator, self).get_link(path, method, callback, view)
        action = self.get_action(path, method, callback)
        func = getattr(view, action, None)
        if func:
            link._description = func.__doc__
        return link
jwineinger commented 8 years ago

Yeah, that was the quick hack I did. Seems like something similar to this could be used to workaround #536 as well. Seems like swagger uses the "tags" list that is output so we'd just need to munge that a bit

paulosuzart commented 8 years ago

I think it also doesn't support the Generic Views doc strings.

c-bata commented 8 years ago

@paulosuzart Yeah, that's right. It requires a further discussion on django-rest-framework repository. https://github.com/tomchristie/django-rest-framework/issues/4444

abondar commented 8 years ago

@paulosuzart For generic views you can see my attempt in https://github.com/tomchristie/django-rest-framework/issues/4444

marcgibbons commented 7 years ago

Docstring introspection is now provided in DRF 3.5+. Closing out.