Skip to content

Code Based API document builder for Django REST Framework & Swagger

License

Notifications You must be signed in to change notification settings

koyouhun/drf_swagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DRF Swagger

Code Based API document builder

Overview

Install

  1. python 2.7, python 3.6

  2. install package

pip install drf_swagger
  1. add django setting.py INSTALLED_APPS
INSTALLED_APPS = [
    # Your apps
    'rest_framework', # need django rest framework
    'drf_swagger',    # Add drf_swagger
]
  1. DRF Swagger contains swagger UI static files
(Your app directory)$ python manage.py collectstatic

Example

from django.http import HttpResponse
from django.contrib.auth.models import User
from rest_framework import viewsets, serializers
from drf_swagger import drf_request, drf_response

class ViewSetTest(viewsets.ViewSet):
    lookup_field = 'view_set'

    @drf_request(RootSerializer)
    @drf_response(RootSerializer)
    def update(self, request, view_set):
        """
        summary: test summary
        parameters:
            - name: test_param
              in: query
              type: string
              description: Only 'name, in, type' is required
              example: test example
              required: true
        """
        return HttpResponse("!@3123")

class RootSerializer(serializers.ModelSerializer):
    id = serializers.CharField(
        help_text='user pk: 46887',
        required=True
    )
    class Meta:
        model = User
        fields = (
            'email',
            'id'
        )

example-img

Quick Start

Warning

  • For security, override SwaggerView and add login

Future Work

  • login/security setting