axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.42k stars 439 forks source link

APIs are not shown in swagger ui on custom permission class #843

Open mashahabi15 opened 1 year ago

mashahabi15 commented 1 year ago

Hello. I have set up drf-yasg on my drf project. I have an issue using login required APIs. I've wrote a custom permission class called MyCustomPerm which inherits from BasePermission and overrides has_permission method. This method reads authorization header and authenticates it against JWT and sets user phone_number on request, then returns True/False considering the fact that user is authenticated or not. The problem is that Swagger UI doesn't show the APIs that have this permission class:

    permission_classes = [
        MyCustomPerm,
    ]

(My views are class based) How can I do that? Thank you very much.

shahabbasi commented 1 year ago

Adding public=True to swagger initiation will solve the problem. like below:

    schema_view = get_schema_view(
        openapi.Info(
            title="Sample",
            default_version='v1',
        ),
        url="",
        public=True,
    )