Prepare for 1.1.0 (#30)
* refactor the view inspection process to be more modular and allow recursive customization * add operation_id argument to @swagger_auto_ * add inspections for min/max validators * add support for URLPathVersioning and NamespaceVersioning * integrate with djangorestframework-camel-case * fix bugs, improve tests and documentation
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from django.conf.urls import url
|
||||
from rest_framework import generics, versioning
|
||||
|
||||
from snippets.models import Snippet
|
||||
from snippets.serializers import SnippetSerializer
|
||||
|
||||
|
||||
class SnippetList(generics.ListCreateAPIView):
|
||||
"""SnippetList classdoc"""
|
||||
queryset = Snippet.objects.all()
|
||||
serializer_class = SnippetSerializer
|
||||
versioning_class = versioning.NamespaceVersioning
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""post method docstring"""
|
||||
return super(SnippetList, self).post(request, *args, **kwargs)
|
||||
|
||||
|
||||
app_name = 'test_ns_versioning'
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^$", SnippetList.as_view())
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
from django.conf.urls import url
|
||||
from rest_framework import fields
|
||||
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from .ns_version1 import SnippetList as SnippetListV1
|
||||
|
||||
|
||||
class SnippetSerializerV2(SnippetSerializer):
|
||||
v2field = fields.IntegerField(help_text="version 2.0 field")
|
||||
|
||||
class Meta:
|
||||
ref_name = 'SnippetV2'
|
||||
|
||||
|
||||
class SnippetListV2(SnippetListV1):
|
||||
serializer_class = SnippetSerializerV2
|
||||
|
||||
|
||||
app_name = 'test_ns_versioning'
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^$", SnippetListV2.as_view())
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
from django.conf.urls import url, include
|
||||
from rest_framework import versioning
|
||||
|
||||
from testproj.urls import SchemaView
|
||||
from . import ns_version1, ns_version2
|
||||
|
||||
VERSION_PREFIX_NS = r"^versioned/ns/"
|
||||
|
||||
|
||||
class VersionedSchemaView(SchemaView):
|
||||
versioning_class = versioning.NamespaceVersioning
|
||||
|
||||
|
||||
schema_patterns = [
|
||||
url(r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='ns-schema')
|
||||
]
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(VERSION_PREFIX_NS + r"v1.0/snippets/", include(ns_version1, namespace='1.0')),
|
||||
url(VERSION_PREFIX_NS + r"v2.0/snippets/", include(ns_version2, namespace='2.0')),
|
||||
url(VERSION_PREFIX_NS + r'v1.0/', include((schema_patterns, '1.0'))),
|
||||
url(VERSION_PREFIX_NS + r'v2.0/', include((schema_patterns, '2.0'))),
|
||||
]
|
||||
@@ -0,0 +1,48 @@
|
||||
from django.conf.urls import url
|
||||
from rest_framework import generics, versioning, fields
|
||||
|
||||
from snippets.models import Snippet
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from testproj.urls import SchemaView
|
||||
|
||||
|
||||
class SnippetSerializerV2(SnippetSerializer):
|
||||
v2field = fields.IntegerField(help_text="version 2.0 field")
|
||||
|
||||
class Meta:
|
||||
ref_name = 'SnippetV2'
|
||||
|
||||
|
||||
class SnippetList(generics.ListCreateAPIView):
|
||||
"""SnippetList classdoc"""
|
||||
queryset = Snippet.objects.all()
|
||||
serializer_class = SnippetSerializer
|
||||
versioning_class = versioning.URLPathVersioning
|
||||
|
||||
def get_serializer_class(self):
|
||||
context = self.get_serializer_context()
|
||||
request = context['request']
|
||||
if int(float(request.version)) >= 2:
|
||||
return SnippetSerializerV2
|
||||
else:
|
||||
return SnippetSerializer
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""post method docstring"""
|
||||
return super(SnippetList, self).post(request, *args, **kwargs)
|
||||
|
||||
|
||||
VERSION_PREFIX_URL = r"^versioned/url/v(?P<version>1.0|2.0)/"
|
||||
|
||||
|
||||
class VersionedSchemaView(SchemaView):
|
||||
versioning_class = versioning.URLPathVersioning
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(VERSION_PREFIX_URL + r"snippets/$", SnippetList.as_view()),
|
||||
url(VERSION_PREFIX_URL + r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='vschema-json'),
|
||||
]
|
||||
Reference in New Issue
Block a user