Skip to content

Commit

Permalink
Impove swagger generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanning9 committed Jun 18, 2024
1 parent da6030c commit c9448a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jasmin_services/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ def get_queryset(self):
@drf_spectacular.utils.extend_schema_view(
list=drf_spectacular.utils.extend_schema(
parameters=[
drf_spectacular.utils.OpenApiParameter(
name="user_username",
required=True,
type=str,
location=drf_spectacular.utils.OpenApiParameter.PATH,
),
drf_spectacular.utils.OpenApiParameter(
name="service",
required=False,
Expand Down Expand Up @@ -204,6 +210,11 @@ class UserGrantsViewSet(rf_mixins.ListModelMixin, rf_viewsets.GenericViewSet):
filterset_class = filters.UserGrantsFilter

def get_queryset(self):
# If we are generating swagger definitions, return the correct
# queryset to allow types to be infered without error.
if getattr(self, "swagger_fake_view", False):
return models.Grant.objects.none()

queryset = models.Grant.objects.filter(
access__user__username=self.kwargs["user_username"],
revoked=False,
Expand Down

0 comments on commit c9448a0

Please sign in to comment.