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

API urls without versions #71

Open
bigblind opened this issue Oct 20, 2017 · 2 comments · May be fixed by #122
Open

API urls without versions #71

bigblind opened this issue Oct 20, 2017 · 2 comments · May be fixed by #122
Milestone

Comments

@bigblind
Copy link

I know versioning your APIs is a good practice, but is there a way to use this library without putting a version in the URL, just like this:

url(r'^api/docs/', include('drf_openapi.urls')),
@dnsdev
Copy link

dnsdev commented Oct 20, 2017

Hey,

here is a quick workaround that is working for me:
add a url like
url(r'^schema(?P<version>[0-9.]*)/', MySchemaViewWOV.as_view(), name='api_schema')
and a view like

from rest_framework import permissions

from drf_openapi.views import SchemaView


class MySchemaViewWOV(SchemaView):
    permission_classes = (permissions.AllowAny,)

    def get(self, request, version=None):
        return super(MySchemaViewWOV, self).get(request, '1.0')

Of course, set your permissions to fit your needs.

This will allow usages like
http://localhost:8000/schema/ but also http://localhost:8000/schema1.4/ etc.
But the view will always return the 1.0 version. The version URL parameter is necessary for reverse urls in the drf_openapi templates.

@limdauto limdauto added this to the v2.0 milestone Dec 17, 2017
trik added a commit to gnucoop/drf_openapi that referenced this issue Feb 2, 2018
@trik trik linked a pull request Feb 2, 2018 that will close this issue
trik added a commit to gnucoop/drf_openapi that referenced this issue Feb 6, 2018
@romantolkachyov
Copy link

Another way to fix is to pass version param:

urlpatterns = [
    path("", include('drf_openapi.urls'), {'version': '1.0'}),
]

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

Successfully merging a pull request may close this issue.

4 participants