All Projects → iMakedonsky → Drf Autodocs

iMakedonsky / Drf Autodocs

Licence: bsd-2-clause
Ultimately automated DRF documentation rendering(UNMAINTAINED)

Projects that are alternatives of or similar to Drf Autodocs

Pdoc
API Documentation for Python Projects
Stars: ✭ 853 (+940.24%)
Mutual labels:  api, api-documentation, documentation, documentation-tool, documentation-generator
Jsdoc To Markdown
Generate markdown documentation from jsdoc-annotated javascript
Stars: ✭ 1,199 (+1362.2%)
Mutual labels:  api-documentation, documentation, documentation-tool, documentation-generator
Rest Api
Learn how to build your own REST API with Python, Django, and the Django Rest Framework.
Stars: ✭ 232 (+182.93%)
Mutual labels:  api, rest-api, django, django-rest-framework
Zeal
Offline documentation browser inspired by Dash
Stars: ✭ 9,164 (+11075.61%)
Mutual labels:  api, api-documentation, documentation, documentation-tool
Drf Yasg
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
Stars: ✭ 2,523 (+2976.83%)
Mutual labels:  rest-api, documentation-generator, django, django-rest-framework
Awesome Documentation Tools
🔥 📚 All the tools, processes and resources you need to create an awesome API & Project documentation
Stars: ✭ 138 (+68.29%)
Mutual labels:  api, api-documentation, documentation, documentation-tool
Best Of Web Python
🏆 A ranked list of awesome python libraries for web development. Updated weekly.
Stars: ✭ 1,118 (+1263.41%)
Mutual labels:  api, rest-api, django, django-rest-framework
Hexo Theme Doc
A documentation theme for the Hexo blog framework
Stars: ✭ 222 (+170.73%)
Mutual labels:  api, api-documentation, documentation, documentation-tool
Pdoc
🐍 ➡️ 📜 Auto-generate API documentation for Python projects
Stars: ✭ 604 (+636.59%)
Mutual labels:  api-documentation, documentation, documentation-tool, documentation-generator
E Commerce 2 django
Guest register, user register, user login, user logout, account home page, product view history, change password, reset password, change name, send activation email when register, resend activation email, add shipping address, add billing address, add nickname to the addresses, edit shipping address, edit billing address, view list of your addresses, reuse shipping addresses when order products, reuse billing addresses when ordeer products, show sales analytics if staff or admin only using -chart.js-, get analytics data with Ajax, receive marketing email, change if user will receive marketing email or not by admin, send contact message with Ajax, products list, product detail, download product detail as a PDF file, download digital product files -if the user purchased that digital product only-, orders list, list of digital products files, order detail, download order detail as a PDF file, verify order ownership with Ajax -to secure order detail page-, show cart products, add or remove product from cart, checkout page, thanks page when order placed successfully, add or reuse payment method, add or reuse payment method with Ajax, search products by title, search products by description, search products by price, search products by tag title, write tags for products -by admin only-, auto fill contact email, full name if user logged in.
Stars: ✭ 20 (-75.61%)
Mutual labels:  api, rest-api, django
Djangorestframework Book
Django REST framework 3 中文文档, API参考, 最佳实践指南
Stars: ✭ 28 (-65.85%)
Mutual labels:  rest-api, django, django-rest-framework
Ara
ARA Records Ansible and makes it easier to understand and troubleshoot.
Stars: ✭ 1,176 (+1334.15%)
Mutual labels:  api, django, django-rest-framework
Project Dashboard With Django
Agile Project Management dashboard with Django REST and Vue.js
Stars: ✭ 25 (-69.51%)
Mutual labels:  rest-api, django, django-rest-framework
Postgraduation
University management platform dedicated for post-graduation in computer science field using django rest framework.
Stars: ✭ 35 (-57.32%)
Mutual labels:  api, django, django-rest-framework
Platform Documentation
Core Platform API Documentation & Tutorials
Stars: ✭ 25 (-69.51%)
Mutual labels:  api, api-documentation, documentation
Django rest example
Django/DRF rest application example.
Stars: ✭ 17 (-79.27%)
Mutual labels:  api, django, django-rest-framework
Django Rest Pandas
📊📈 Serves up Pandas dataframes via the Django REST Framework for use in client-side (i.e. d3.js) visualizations and offline analysis (e.g. Excel)
Stars: ✭ 1,030 (+1156.1%)
Mutual labels:  rest-api, django, django-rest-framework
App
Fast and searchable Ruby docs
Stars: ✭ 47 (-42.68%)
Mutual labels:  documentation, documentation-tool, documentation-generator
Rest Hapi
🚀 A RESTful API generator for Node.js
Stars: ✭ 1,102 (+1243.9%)
Mutual labels:  api, rest-api, documentation
Cookiecutter Django Rest
Build best practiced apis fast with Python3
Stars: ✭ 1,108 (+1251.22%)
Mutual labels:  api, rest-api, django

THIS REPO IS NO LONGER MAINTAINED. PLEASE CONSIDER OTHER AUTOMATED DOCUMENTATION PACKAGES

Django REST framework auto docs

Automated api documentation renderer

Features:

  • optional response_serializer_class, if output serializer is different from input serializer
  • fully-documented functional views
  • tree-like structure
  • Docstrings:
  • markdown
  • preserve space & newlines
  • formatting with nice syntax
  • Fields:
  • different fields for request/response, based on read-/write-only attributes and whether response_serializer_class presented or not
  • choices rendering
  • help_text rendering (to specify SerializerMethodField output, etc)
  • Endpoint properties:
  • filter_backends
  • authentication_classes
  • permission_classes
  • extra url params(GET params)

What isn't supported yet:

  • viewsets
  • possibility to try in browser

Samples

Whole structure:

whole structure

Single node:

single node

Choices:

choices

Nested items:

nested items

Docstring formatting:

@format_docstring(request_example, response_example=response_example)
class BookReadUpdateHandler(RetrieveUpdateAPIView):
    """
    Wow, this magic decorator allows us to:
        1) Keep clean & short docstring
        2) Insert additional data in it, like request/response examples

    Request: {}
    Response: {response_example}
    """

help text

Installation

In virtualenv:

pip install drf_autodocs

In settings:

INSTALLED_APPS = [
    ...
    'drf_autodocs',
    ...
]

In your urls:

urlpatterns = [
    ...
    url(r'^', include('drf_autodocs.urls')),
]

That's already enough for swagger-like docs, result available on

localhost:8000/docs/

If you want functional views support and some more features, read below.

Usage

Tree-like structure

Tree-like structure is built from url prefixes. To make your endpoints grouped by some category, you must include your urls within other url. There are, generally, 2 ways to achieve it:

Example 1:

university_urlpatterns = [
    url(r'^lecturers/', university_views.LecturersHandler.as_view(), name='lecturers'),
    url(r'^lecturers/(?P<pk>\d+)/$', university_views.LecturerUpdateHandler.as_view(), name='lecturer_read_update'),
    url(r'^universities/', university_views.UniversitiesHandler.as_view(), name='universities'),
]

urlpatterns = [
    url(r'^library/', include(library_urlpatterns, namespace='library')),
    url(r'^university/', include(university_urlpatterns, namespace='university')),
]

Example 2:

urlpatterns = [
    url(r'^library/', include(library_urlpatterns, namespace='library')),
    url(r'^university/', include([
        url(r'^lecturers/', university_views.LecturersHandler.as_view(), name='lecturers'),
        url(r'^lecturers/(?P<pk>\d+)/$', university_views.LecturerUpdateHandler.as_view(), name='lecturer_read_update'),
        url(r'^universities/', university_views.UniversitiesHandler.as_view(), name='universities')
    ], namespace='university')),
]

Response serializer class

Say you have a view like this:

class BookReadUpdateHandler(RetrieveUpdateAPIView):
    serializer_class = BookUpdateSerializer
    queryset = Book.objects.all()

And say this serializers' input is different from output:

class BookUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        fields = ('name', 'author')
        model = Book

    def to_representation(self, instance):
        return LibrarySerializer(instance.library)

Now to know what return format is, one must make a request. This package simplifies it via:

response_serializer_class = YourSerializer

Now your view looks like:

class BookReadUpdateHandler(RetrieveUpdateAPIView):
    """
    Shiny and nice docstring, which:
        1) allows formatting
        2) `allows markdown`
    """
    serializer_class = BookUpdateSerializer
    response_serializer_class = LibrarySerializer
    queryset = Book.objects.all()

Docstring formatting in class-based views

from .request_response_examples import request_example, response_example
from drf_autodocs.decorators import format_docstring


@format_docstring(request_example, response_example=response_example)
class BookReadUpdateHandler(RetrieveUpdateAPIView):
    """
    Wow, this magic decorator allows us to:
        1) Keep clean & short docstring
        2) Insert additional data in it, like request/response examples

    Request: {}
    Response: {response_example}
    """
    serializer_class = BookUpdateSerializer
    response_serializer_class = LibrarySerializer
    queryset = Book.objects.all()

Extra URL(GET) parameters

Please think twice before using such parameters, as they might be unneeded.

But if you really need them, here you go:

class LibrariesHandler(ListCreateAPIView):
    """
    Shiny and nice docstring, which:
        1) allows formatting
        2) `allows markdown`
    """
    extra_url_params = (('show_all', 'Bool', 'if True returns all instances and only 5 otherwise'),
                        ('some_extra_param', 'Integer', 'Something more to be included there'))

Results in:

extra_url_params

Function-based views

For functional views, decorate them with.

drf_autodocs.decorators.document_func_view

Now you can insert into view via kwargs:

  • serializer_class
  • response_serializer_class
  • filter_backends
  • authentication_classes
  • permission_classes
  • doc_format_args
  • doc_format_kwargs

Now it should look like:

from drf_autodocs.decorators import document_func_view

format_args = ['"This string\nwas inserted"',]

@document_func_view(serializer_class=BookSerializer,
                    response_serializer_class=LibrarySerializer,
                    doc_format_args=format_args)
@api_view(['GET', 'POST', 'DELETE'])
def hello_world(request):
    """
    Works for `functional` views too!
        Yeah, that thing rocks!
        And allows formatting {}
    """
    return Response('hello_world response')

Help text

This package uses default DRF field attribute help_text If you're using ModelSerializer, and model field got help_text attr, it will be transferred to your serializers' field automatically.

Example:

from rest_framework import serializers

has_books = serializers.SerializerMethodField(help_text='returns Bool')

Note that specifying help_text on serializers' field overrides the one from model

Customization

To change application look & feel, override templates and/or static files.

Root template is : templates/drf_autodocs/index.html

For additional parsers(if you want other structure than tree), inherit from

drf_autodocs.parser.BaseAPIParser

Configuration/settings

Endpoint names could use view names or url names, replacing '_' and '-' with ' ' and capitalizing output.

Default behavior is to use url names:

url(r'^books/(?P<pk>\d+)/$', library_views.BookReadUpdateHandler.as_view(), name='book_read_update'),

will result in:

url_name

If you want to use endpoint(view) names instead, do this in settings:

AUTODOCS_ENDPOINT_NAMES = "view"

Supports

  • Python 3
  • Django 1.8+
  • Django Rest Framework 3+

Credits

Thanks to django, django-REST for their awesome work, and drf-docs for source of inspiration as well as some parts of code.

Developed with care by Mashianov Oleksander at

buddhasoft

If you 👍 this, don't forget to ⭐️ it and share with friends.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].