Created
October 13, 2022 18:49
-
-
Save CryceTruly/7f222b9d1275dea7c06ab2c99524e5f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import permissions | |
from drf_yasg.views import get_schema_view | |
from drf_yasg import openapi | |
from drf_yasg.generators import OpenAPISchemaGenerator | |
from rest_framework.authentication import SessionAuthentication | |
class CustomOpenAPISchemaGenerator(OpenAPISchemaGenerator): | |
def get_endpoints(self, request): | |
prev = super().get_endpoints(request) | |
group_names = [] | |
for group in request.user.groups.all(): | |
group_names.append(group.name) | |
all = prev.items() | |
if "partners" in group_names: | |
accepted_paths = ["/api/v1/auth/login/", | |
"/api/v1/currency-exchange/convert/", | |
"/api/v1/currency-exchange/exchange/", | |
"/api/v1/crypto-wallets/*/", | |
"/api/v1/transactions/avada-pay-withdraw/"] | |
results = {} | |
for path in accepted_paths: | |
for key, value in all: | |
if path == key: | |
results[key] = value | |
return results | |
return super().get_endpoints(request) | |
def get_schema(self, request=None, public=False): | |
"""Generate a :class:`.Swagger` object with custom tags""" | |
swagger = super().get_schema(request, public) | |
return swagger | |
schema_view = get_schema_view( | |
openapi.Info( | |
title="BitLipa API", | |
default_version='v1', | |
description="Open Up Your World. Be Truly Borderless", | |
terms_of_service="https://www.bitlipa.com/legal/privacy-policy", | |
contact=openapi.Contact(email="[email protected]"), | |
license=openapi.License(name="BSD License"), | |
), | |
authentication_classes=(SessionAuthentication,), | |
permission_classes=(permissions.IsAuthenticated,), | |
generator_class=CustomOpenAPISchemaGenerator | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment