GithubHelp home page GithubHelp logo

tonioo / djagger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from royhzq/djagger

0.0 0.0 0.0 130 KB

OpenAPI 3 schema generator for Django and Django Rest Framework based on pydantic

License: MIT License

Python 99.11% HTML 0.89%

djagger's Introduction

🗡️Djagger - OpenAPI schema generator for Django using pydantic

Package Badge Pypi Badge

Automated OpenAPI documentation generator for Django. Djagger provides you with a clean and straightforward way to generate a comprehensive API documentation of your Django project by utilizing pydantic to create schema objects for your views.

Example Django project using Djagger:

Generated API documentation from the example project:

Djagger repo:

Full Documentation:

Djagger is designed to be:

🧾 Comprehensive - Every aspect of your API should be document-able straight from your views, to the full extent of the OpenAPi 3.0 specification.

👐 Unintrusive - Integrate easily with your existing Django project. Djagger can document vanilla Django views (function-based and class-based views), as well as any Django REST framework views. As long as you are using Django's default URL routing, you are good to go. You do not need to redesign your APIs for better documentation.

🍭 Easy - Djagger uses pure, unadulterated pydantic models to generate schemas. If you have used pydantic, there is no learning curve. If you have not heard of pydantic, it is a powerful data validation library that is pretty straightforward to pickup (like dataclasses). Check it out here. Either way, documenting your APIs will feel less like a chore.

Quickstart

Install using pip

pip install djagger

Add djagger to your INSTALLED_APPS setting in your Django project like this:

INSTALLED_APPS = [
    ...
    'djagger',
]

Include the djagger URLconf in your project urls.py like this if you want to use the built-in document views.

urlpatterns = [
    ...
    path('djagger/', include('djagger.urls')),
]

Note

  • To see the generated documentation, use the route /djagger/api/docs. Djagger uses Redoc as the default client generator.
  • To get the generated JSON schema file, use the route /djagger/schema.json.

Examples

Example GET Endpoint

from rest_framework.views import APIView
from rest_framework.response import Response
from pydantic import BaseModel as Schema
import datetime


class ArticleDetailSchema(Schema):
    created : datetime.datetime
    title : str
    author : str
    content : str


class RandomArticleAPI(APIView):
    """Return a random article from the Blog"""

    response_schema = ArticleDetailSchema

    def get(self, request):
        ...
        return Response({})

Generated documentation

UserDetailsAPI Redoc

Example POST Endpoint

from rest_framework.views import APIView
from rest_framework.response import Response
from pydantic import BaseModel as Schema, Field
import datetime


class ArticleDetailSchema(Schema):
    created : datetime.datetime
    title : str
    author : str
    content : str

class ArticleCreateSchema(Schema):
    """POST schema for blog article creation"""
    title : str = Field(description="Title of Blog article")
    content : str = Field(description="Blog article content")


class ArticleCreateAPI(APIView):

    request_schema = ArticleCreateSchema
    response_schema = ArticleDetailSchema

    def post(self, request):
        ...
        return Response({})

Generated documentation

CreateItemAPI Redoc

For more involved examples, check out the example project and the API documentation generated from that project.

Documentation & Support

  • Read the full documentation for Djagger: https://djagger-docs.netlify.app
  • This project is in continuous development. If you have any questions or would like to contribute, please email [email protected]
  • If you want to support this project, do give it a ⭐ on github!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.