Django restframework custom schema
Project description
Django restframework schema
This package is a schema for django restframework.
How to use
Installation
$ pip install django-rest-coreapi-schema
$ pip install -e git+https://github.com/emilioag/django_rest_coreapi_schema.git#egg=django_rest_coreapi_schema
Configuration
django settings
Add the next configuration in your settings.py file.
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'django_rest_coreapi_schema.schema.CoreAPIAutoSchema',
}
Restframework docs (urls)
Add to your urls.py the restframework docs
from django.conf.urls import url
from rest_framework.documentation import include_docs_urls
urlpatterns = [
url(r'^docs/', include_docs_urls(title='My API title', description='API description', public=False)),
]
Create your serializers
from rest_framework import serializers
class UserSerializer(serializers.Serializer):
email = serializers.CharField(
required=False,
help_text="User email")
address = serializers.CharField(
required=False,
help_text="User address")
class FilterSerializer(serializers.Serializer):
order = serializers.ChoiceField(
required=False,
choices=[("asc", "Asc"), ("desc", "desc")],
help_text="Order")
username = serializers.CharField(
required=False,
help_text="Username pattern")
class PathSerializer(serializers.Serializer):
username = serializers.CharField(
required=True,
help_text="Username")
Create your pagination
from rest_framework.pagination import PageNumberPagination
class LargeResultsSetPagination(PageNumberPagination):
page_size = 1000
page_size_query_param = 'page_size'
max_page_size = 10000
Create your view
Documenting path variables
You have to use the class variable: queryset
from django_rest_coreapi_schema.views import DocumentedBaseView
class UserView(DocumentedBaseView):
queryset = PathSerializer
Url args
You have to use the class variables: filter_backends and filter_fields
filter_backends is a list of serializers which contains all the possible url args.
filter_fields is a list of arg names that will be appear in the coreapi documentation.
from django_rest_coreapi_schema.views import DocumentedBaseView
class UserListView(DocumentedBaseView):
filter_backends = [FilterSerializer]
filter_fields = ('order', 'username')
Body
Http put, post, etc. body.
from django_rest_coreapi_schema.views import DocumentedBaseView
class UserView(DocumentedBaseView):
body_serializer_class = UserSerializer
Pagination (for large results)
from django_rest_coreapi_schema.views import DocumentedBaseView
class UserListView(DocumentedBaseView):
pagination_class = LargeResultsSetPagination
You can see a whole example in examples/restAPI folder inside this repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_rest_coreapi_schema-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | caf2cdbfb93cdc456b7744dc06ad8a62fc66de42f0931e96b0f988d33d697a84 |
|
MD5 | 4d73285155e1d4fde13f134bf9920494 |
|
BLAKE2b-256 | d17fd14d9df74df988284d70ca260f4c7512bf0f08e44836b63138b6cb2f937e |
Close
Hashes for django_rest_coreapi_schema-0.1.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c17575e48d43eda2d2817bf8848262e1317c11eb97b7efa0886b574fee69982 |
|
MD5 | 793a2b9390de9686fefdfc7d78c02f92 |
|
BLAKE2b-256 | 4091488d4bf0b437bceee5163bb2387c1a317869953dfaf59573d4a849db7f6a |