Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drf_spectacular OpenAPI schema warnings #1067

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pulpcore/app/views/repair.py
Expand Up @@ -8,6 +8,10 @@


class RepairView(APIView):
def get_serializer_class(self):
"""Get serializer class."""
return AsyncOperationResponseSerializer

@extend_schema(
description=(
"Trigger an asynchronous task that checks for missing "
Expand Down
8 changes: 8 additions & 0 deletions pulpcore/app/viewsets/task.py
Expand Up @@ -100,6 +100,14 @@ class TaskViewSet(
],
}

def get_queryset(self):
"""Get queryset."""
if self.request is None:
# https://github.com/carltongibson/django-filter/issues/966#issuecomment-639739206
return Task.objects.none()

return Task.objects.all()

@extend_schema(
description="This operation cancels a task.",
summary="Cancel a task",
Expand Down
10 changes: 7 additions & 3 deletions pulpcore/openapi/__init__.py
Expand Up @@ -170,7 +170,13 @@ def _get_serializer_name(self, serializer, direction):
Get serializer name.
"""
name = super()._get_serializer_name(serializer, direction)
if direction == "request":
if "RepositoryVersion" in name:
prefix = self.view.parent_viewset.queryset.model._meta.app_label
name = prefix.title() + name
pulp_model_alias = getattr(self.view, "pulp_model_alias", None)
if pulp_model_alias:
name = pulp_model_alias
if direction == "request" and "Request" in name:
name = name[:-7]
elif direction == "response" and "Response" not in name:
name = name + "Response"
Expand Down Expand Up @@ -439,8 +445,6 @@ def get_schema(self, request=None, public=False):
paths=self.parse(request, public),
components=self.registry.build(spectacular_settings.APPEND_COMPONENTS),
)
for hook in spectacular_settings.POSTPROCESSING_HOOKS:
result = hook(result=result, generator=self, request=request, public=public)

# Basically I'm doing it to get pulp logo at redoc page
result["info"]["x-logo"] = {
Expand Down