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

Make DRF API versioning optional. #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Make DRF API versioning optional. #93

wants to merge 2 commits into from

Conversation

axnsan12
Copy link

Make drf-openapi work without enabling api versioning (i.e. without having a version parameter in the request).

Motivation:

  • not all users have versioning enabled
  • it is not always easy, desired or even possible to enable versioning
  • the readme claims that this "Can be dropped into any existing DRF project without any code change necessary."

Closes #71.

@ioga
Copy link

ioga commented Nov 29, 2017

With this PR, the version parameter is still required in the view_config decorator here: https://github.com/limdauto/drf_openapi/blob/master/drf_openapi/utils.py#L27

That can be addressed with something like this:

diff --git a/drf_openapi/utils.py b/drf_openapi/utils.py
index 786f539..49e24e5 100644
--- a/drf_openapi/utils.py
+++ b/drf_openapi/utils.py
@@ -13,7 +13,9 @@ def view_config(request_serializer=None, response_serializer=None, validate_resp
         view_method.response_serializer = response_serializer
 
         @wraps(view_method)
-        def wrapper(instance, request, version=None, *args, **kwargs):
+        def wrapper(instance, request, *args, **kwargs):
+            version = kwargs.get('version', None)
+
             if request_serializer and issubclass(request_serializer, VersionedSerializers):
                 instance.request_serializer = request_serializer.get(version)
             else:
@@ -24,7 +26,7 @@ def view_config(request_serializer=None, response_serializer=None, validate_resp
             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)

@limdauto
Copy link
Owner

Thanks. Sorry I know I have not been very active lately. I will look at this feature request this weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants