API schema generator and validator for Django REST framework
Project description
What is it
API schema generator and validator for Django REST framework.
Usage
from django.urls import include, path
from rest_framework import serializers
from rest_framework.decorators import api_view
from rest_framework.routers import DefaultRouter
from rest_framework.viewsets import ViewSet
from drf_apischema import apischem
from drf_apischema.utils import api_patha
class AOut(serializers.ListSerializer):
child = serializers.IntegerField()
class BQuery(serializers.Serializer):
n = serializers.IntegerField(default=2)
class AViewSet(ViewSet):
@apischema(response=AOut)
def list(self, request):
return [1, 2, 3]
@api_view(["GET"])
@apischema(query=BQuery, transaction=False)
# def b_view(request, serializer: BQuery, data: dict):
def b_view(request, data: dict):
n: int = data["n"]
return n * n
router = DefaultRouter()
router.register("a", AViewSet, basename="a")
urlpatterns = [
api_path(
"api/",
[
path("", include(router.urls)),
path("b/", b_view),
],
)
]
settings
# settings.py
# wrap method in a transaction
DRF_APISCHEMA_TRANSACTION = True
# log SQL queries in debug mode
DRF_APISCHEMA_SQLLOGGER = True
DRF_APISCHEMA_SQLLOGGER_REINDENT = True
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
drf_apischema-0.1.10.tar.gz
(24.4 kB
view details)
Built Distribution
File details
Details for the file drf_apischema-0.1.10.tar.gz
.
File metadata
- Download URL: drf_apischema-0.1.10.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4782595fe71d466ae955d58f7d4e62a6ab8162018159a20a4bb347433fad70 |
|
MD5 | 8447af8ca07fd7686e27da2f485b2f3d |
|
BLAKE2b-256 | 19252526aaee25ef0b934df8006752e24caa555c5e307fa11e2a0c50a125cbe6 |
File details
Details for the file drf_apischema-0.1.10-py3-none-any.whl
.
File metadata
- Download URL: drf_apischema-0.1.10-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dcd7d59301bb86745de333c29f9e357e74c89e4be7522333a06d6af6ff2d963 |
|
MD5 | 145a4955f38b658e1a14a900d3b8cb94 |
|
BLAKE2b-256 | 3bd11ad515b42d3242c108ef58a81ec87fb462707c64e0b41b660da59a84fc5d |