Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

improve versioning schemes support #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drf_openapi/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_links(self, request=None):
for path, method, view in view_endpoints:
if not self.has_view_permissions(path, method, view):
continue
link = self.get_link(path, method, view, version=getattr(request, 'version', None))
link = self.get_link(path, method, view, version=self.version)
subpath = path[len(prefix):]
keys = self.get_keys(subpath, method, view)
try:
Expand Down
6 changes: 4 additions & 2 deletions drf_openapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def decorator(view_method):
view_method.response_serializer = response_serializer

@wraps(view_method)
def wrapper(instance, request, version=None, *args, **kwargs):
def wrapper(instance, request, *args, **kwargs):
version, _ = instance.determine_version(request, *args, **kwargs)

if request_serializer and issubclass(request_serializer, VersionedSerializers):
instance.request_serializer = request_serializer.get(version)
else:
Expand All @@ -24,7 +26,7 @@ def wrapper(instance, request, version=None, *args, **kwargs):
else:
instance.response_serializer = response_serializer

response = view_method(instance, request, version=version, *args, **kwargs)
response = view_method(instance, request, *args, **kwargs)
if validate_response:
response_validator = instance.response_serializer(data=response.data)
response_validator.is_valid(raise_exception=True)
Expand Down
3 changes: 2 additions & 1 deletion drf_openapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SchemaView(APIView):
url = ''
title = 'API Documentation'

def get(self, request, version):
def get(self, request, *args, **kwargs):
version, _ = self.determine_version(request, *args, **kwargs)
generator = OpenApiSchemaGenerator(
version=version,
url=self.url,
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SnippetList(APIView):
"""

@view_config(response_serializer=SnippetSerializer)
def get(self, request, version, format=None):
def get(self, request, version=None, format=None):
res = self.response_serializer(data=_FAKE_SNIPPETS, many=True)
res.is_valid(raise_exception=True)
return Response(res.validated_data)
Expand Down