Skip to content

Commit

Permalink
OpenAPI schema: Use renderer with small size by default (#8973)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik authored Nov 15, 2023
1 parent df82b0c commit b37d77d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,25 @@
extend_schema,
extend_schema_view,
)
from drf_spectacular.views import SpectacularAPIView
from drf_spectacular.renderers import OpenApiJsonRenderer2
from dojo.authorization.roles_permissions import Permissions
from dojo.user.utils import get_configuration_permissions_codenames

logger = logging.getLogger(__name__)


class DojoOpenApiJsonRenderer(OpenApiJsonRenderer2):
def get_indent(self, accepted_media_type, renderer_context):
if accepted_media_type and 'indent' in accepted_media_type:
return super().get_indent(accepted_media_type, renderer_context)
return renderer_context.get('indent', None)


class DojoSpectacularAPIView(SpectacularAPIView):
renderer_classes = [DojoOpenApiJsonRenderer] + SpectacularAPIView.renderer_classes


# Authorization: authenticated users
class RoleViewSet(
mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet
Expand Down
3 changes: 2 additions & 1 deletion dojo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
from dojo.components.urls import urlpatterns as component_urls
from dojo.regulations.urls import urlpatterns as regulations
from dojo.announcement.urls import urlpatterns as announcement_urls
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from drf_spectacular.views import SpectacularSwaggerView
from dojo.api_v2.views import DojoSpectacularAPIView as SpectacularAPIView

import logging
logger = logging.getLogger(__name__)
Expand Down

0 comments on commit b37d77d

Please sign in to comment.