diff --git a/dojo/api_v2/views.py b/dojo/api_v2/views.py index 32656a41199..cfbf5a3e265 100644 --- a/dojo/api_v2/views.py +++ b/dojo/api_v2/views.py @@ -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 diff --git a/dojo/urls.py b/dojo/urls.py index 8f1b27416d0..cde14708936 100755 --- a/dojo/urls.py +++ b/dojo/urls.py @@ -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__)