marcgibbons / django-rest-swagger

Swagger Documentation Generator for Django REST Framework: deprecated
https://marcgibbons.com/django-rest-swagger/
BSD 2-Clause "Simplified" License
2.59k stars 602 forks source link

How to add oauth2/token endpoint #632

Open dimitrismakris opened 7 years ago

dimitrismakris commented 7 years ago

I'm using django-rest-swagger version 2.1.1. I used the oauth2_provider.urls to build the oauth2/token endpoint like this:

urlpatterns = [
    url(r'^oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]

The issue is that the Swagger don't detect it as endpoint so it's missing form my openapi.json file.

What can I do to this endpoint in order to be able to detected by Swagger?

marcgibbons commented 7 years ago

Django REST doesn't render schema for these as I don't believe that they are APIViews. It is possible to override the document generated by the schema generated to include additional "links".

See: http://www.django-rest-framework.org/api-guide/schemas/#schemagenerator

jarussi-luizalabs commented 6 years ago

@dimitrismakris I'm not sure if this is the best way to achieve this but I did something like this:

from oauth2_provider.views import TokenView
from rest_framework.views import APIView

class TokenAPIView(TokenView, APIView):
    def post(self, *args, **kwargs):
        """ DOCS """
        return super().post(*args, **kwargs)

You may have to change permissions or authorizations .. but it should make possible to create your docs. Hope it helps