🗡️ Djagger - OpenAPI schema generator for Django using pydantic
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.
Djagger is designed to be:
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](https://user-images.githubusercontent.com/32057276/148027310-3248b5aa-f8a5-46d1-b044-044d001dcddd.png)
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](https://user-images.githubusercontent.com/32057276/148027403-4acca98c-e4af-4265-a9f5-c385f143be73.png)
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 royhung@protonmail.com
- If you want to support this project, do give it a
⭐ on github!