Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

All urls are not mapped by swagger #562

Closed
verisadmin opened this issue Oct 12, 2016 · 6 comments
Closed

All urls are not mapped by swagger #562

verisadmin opened this issue Oct 12, 2016 · 6 comments

Comments

@verisadmin
Copy link

verisadmin commented Oct 12, 2016

I just started using swagger for my API documentation. I followed your docs , but more then half of the urls were excluded by swagger.

Also the urls which swagger mapped to browser are not working properly, like there is no body part to test the end points. If you click Try it out! it will send the request with blank params (no body to edit request params). see image attached below

I am using APIView and I think may be this is the issue

class UserSignUp(APIView):
    """
    """
    serializer_class = serializers.UserSignUpSerializer
    permission_classes = (permissions.AnonymousVerisUser, )

    def get_serializer_class(self):
        return self.serializer_class

    def post(self, request, *args, **kwargs):
        """
        """
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        return Response(response, status=status.HTTP_200_OK)

swagger ui 2

@verisadmin verisadmin changed the title some urls are excludd by default by swagger All urls are not mapped by swagger Oct 12, 2016
@verisadmin
Copy link
Author

I think I found something relevant here, swagger only mapping those APIs which are accessible via anonymous user. As I have used permissions to block unauthorized access so swagger is bloacking all those APIs which need an auth user. So is there any setting which needs to be disable because I can pass token in API header to authenticate user.

@marcgibbons
Copy link
Owner

@verisadmin By passing in the request object into the schema generator, the permissions on each view are enforced. By removing the request object from the get_schema method, the user context is ignored, and all routes will be published by the generator.

However, if you authenticate, you should see the routes you have access to as that user.

For more details:
http://www.django-rest-framework.org/api-guide/schemas/#using-schemagenerator

@verisadmin
Copy link
Author

@marcgibbons Thx a lot. It works .

One more thing I am using token Authentication. And I have custom token key for that (not usual token in DRF). I use following code in headers.

Authorization customtoken 3f921d0941d5b64f431c3d6605b82df11a6b9da1

So basically I need to update headers somehow . Below are my swagger settings but still I din't have any way to add custom headers while hitting api endpoint.

SWAGGER_SETTINGS = {
    'USE_SESSION_AUTH': False,
    'SECURITY_DEFINITIONS': {
        'oauth2': {
            'type': 'apiKey',
            'description': 'Personal API Key authorization',
            'name': 'Authorization',
            'in': 'header',
        }
    },
    'APIS_SORTER': 'alpha',
    # "JSON_EDITOR": True,
    "SHOW_REQUEST_HEADERS": True,
    "VALIDATOR_URL": False,
    "api_key": 'veristoken fbe16f3a4c292c774c54', # An API key
}

@verisadmin
Copy link
Author

After reading docs I found that we can define token from authorize button , But authorize button is not getting rendered for me.
Below are updated setting and schema view function :

@api_view(['GET'])
@permission_classes([AllowAny,])
@renderer_classes([SwaggerUIRenderer, OpenAPIRenderer, ])
def schema_view(request):
    generator = schemas.SchemaGenerator(title='Veris API')
    return response.Response(generator.get_schema())
SWAGGER_SETTINGS = {
    "SUPPORTED_SUBMIT_METHOD": ['get', 'post', 'put', 'delete', ],
    'USE_SESSION_AUTH': False,
    "LOGIN_URL": "/",
    "LOGOUT_URL": "/",
    'SECURITY_DEFINITIONS': {
        'api_key': {
            'type': 'apiKey',
            'description': 'Personal API Key authorization',
            'name': 'Authorization',
            'in': 'header',
        }
    },
    'APIS_SORTER': 'alpha',
    "SHOW_REQUEST_HEADERS": True,
    "VALIDATOR_URL": None,
    'api_key': 'veristoken fbe16f3a4c292c774c54', # An API key
}

I also followed #535 but no success.

@verisadmin
Copy link
Author

@marcgibbons It was the version issue.

If version is 2.0.6 , no authorize button as soon as downgraded to 2.0.5 , authorize button appears.

@marcgibbons
Copy link
Owner

@verisadmin Yup, this regressed in 2.0.6. Fixing and will release shortly. Thanks!

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

No branches or pull requests

2 participants