Skip to main content

Django APIView decorator create Api Doc

Project description

djangoapiviewdoc

根据装饰器生成api文档

版本<=1.1.0

# settings.py
from apiview_doc.decorator import ApiDoc

APIDOC_DECORATOR = ApiDoc()

# views.py
from project_name.settings import APIDOC_DECORATOR
from rest_framework.generics import GenericAPIView


class PersonLoginAPIView(GenericAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户名、密码登录
    @date:      2021/11/29 17:09
    """

    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/login', summary = '用户登录')
    @APIDOC_DECORATOR.ApiParams(value = 'username', require = True, type = 'string', desc = '用户名')
    @APIDOC_DECORATOR.ApiParams(value = 'password', require = True, type = 'string', desc = '密码')
    def post(self, request, *args, **kwargs):
        pass


# url.py
from apiview_doc.decorator import api_doc
from views import PersonLoginAPIView


def docs(request):
    context = api_doc()

    return render(request, 'apiview_doc/docs/index.html', context)


urlpatterns = [
    path('login', PersonLoginAPIView.as_view()),
    path('docs', docs),
]

启动项目访问 “/docs”

img.png

版本 >= 1.1.0

# settings.py
from apiview_doc.decorator import ApiDoc
from apiview_doc.openapi import ApiImplicitParam, ApiTag, ApiParameters, ApiOperation, ApiDataType, ApiParamType

# views.py
from rest_framework.generics import GenericAPIView


class PersonLoginAPIView(GenericAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户名、密码登录
    @date:      2021/11/29 17:09
    """

    @ApiTag(name = 'user', description = '用户管理')
    @ApiOperation(method = 'POST', path = 'user/login', summary = '用户登录')
    @ApiParameters(params = [
        ApiImplicitParam(description = '用户名', name = 'username', required = True, paramType = ApiParamType.Body,
                         dataType = ApiDataType.String),
        ApiImplicitParam(description = '密码', name = 'password', required = True, paramType = ApiParamType.Body,
                         dataType = ApiDataType.String),
    ])
    def post(self, request, *args, **kwargs):
        pass


# url.py
from views import PersonLoginAPIView
from apiview_doc.openapi import OpenApi, api_info_list

openapi = OpenApi(
    paths = api_info_list()
)


def get_openapi_docs_url(request):
    context = openapi.__dict__

    return render(request, 'apiview_doc/openapi/index.html', context)

urlpatterns = [
    path('login', PersonLoginAPIView.as_view()),
    path('redocs', get_openapi_docs_url),
]

启动项目访问 “/docs”

img_3.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangoapiviewdoc-1.1.2.tar.gz (471.4 kB view details)

Uploaded Source

File details

Details for the file djangoapiviewdoc-1.1.2.tar.gz.

File metadata

  • Download URL: djangoapiviewdoc-1.1.2.tar.gz
  • Upload date:
  • Size: 471.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for djangoapiviewdoc-1.1.2.tar.gz
Algorithm Hash digest
SHA256 c93988eccbdad1e555ee7c411d9ba3737211430610ff0fd92a33e2a8e3247a5c
MD5 8ee3cf9a5ab0653ea5615681f42034fa
BLAKE2b-256 11036299d4fb64fa2a25fcdd463ca3061a3f2cacb9ac1c1e330e154cc4b68473

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page