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 apischema
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 = [
path("", include(router.urls)),
path("b/", b_view),
]
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.9.tar.gz
(15.4 kB
view details)
Built Distribution
File details
Details for the file drf_apischema-0.1.9.tar.gz
.
File metadata
- Download URL: drf_apischema-0.1.9.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07e36329b7eb4e5e9362047af135a0386874a979a5565228b36da79252c8cf14 |
|
MD5 | 5a02581bba0ca79c9861d0c64ba57cc7 |
|
BLAKE2b-256 | 8e883f01c46a8f7632af26d4e517e17ce2e1960f67f752fc3c29b9ce0131210e |
File details
Details for the file drf_apischema-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: drf_apischema-0.1.9-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c893fb2180d221073b76200a55415478d649494af91821102df5532cd5e35663 |
|
MD5 | b7f9fb1054ea67c981c73e992a178539 |
|
BLAKE2b-256 | 67dce62f7ec66f26ba6d30ba21f0be4f1483eb113e90393f4417183151d1be15 |