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

Swagger refactor #1516

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions gateway/api/v1/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Files view api for V1.
"""

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import permissions
from rest_framework.decorators import action

from api.permissions import IsOwner
from api import views
Expand All @@ -14,3 +17,77 @@ class FilesViewSet(views.FilesViewSet):
"""

permission_classes = [permissions.IsAuthenticated, IsOwner]

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
def list(self, request):
return super().list(request)

@swagger_auto_schema(
operation_description="Download a specific file",
manual_parameters=[
openapi.Parameter(
"file",
openapi.IN_QUERY,
description="file name",
type=openapi.TYPE_STRING,
required=True,
),
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
@action(methods=["GET"], detail=False)
def download(self, request):
return super().download(request)

@swagger_auto_schema(
operation_description="Deletes file uploaded or produced by the programs",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(
type=openapi.TYPE_STRING, description="file name"
),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["DELETE"], detail=False)
def delete(self, request):
return super().delete(request)

@swagger_auto_schema(
operation_description="Upload selected file",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(type=openapi.TYPE_FILE, description="file name"),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["POST"], detail=False)
def upload(self, request):
return super().upload(request)
61 changes: 0 additions & 61 deletions gateway/api/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import os
from wsgiref.util import FileWrapper

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from django.conf import settings
from django.http import StreamingHttpResponse

Expand Down Expand Up @@ -69,18 +67,6 @@ def check_user_has_provider(self, user, provider_name):
"""check if user has the provider"""
return provider_name in self.list_user_providers(user)

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
def list(self, request):
"""List of available for user files."""
response = Response(
Expand Down Expand Up @@ -115,25 +101,6 @@ def list(self, request):

return Response({"results": files})

@swagger_auto_schema(
operation_description="List of available for user files",
manual_parameters=[
openapi.Parameter(
"file",
openapi.IN_QUERY,
description="file name",
type=openapi.TYPE_STRING,
required=True,
),
openapi.Parameter(
"provider",
openapi.IN_QUERY,
description="provider name",
type=openapi.TYPE_STRING,
required=False,
),
],
)
@action(methods=["GET"], detail=False)
def download(self, request): # pylint: disable=invalid-name
"""Download selected file."""
Expand Down Expand Up @@ -179,21 +146,6 @@ def download(self, request): # pylint: disable=invalid-name
response["Content-Disposition"] = f"attachment; filename={filename}"
return response

@swagger_auto_schema(
operation_description="Deletes file uploaded or produced by the programs",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(
type=openapi.TYPE_STRING, description="file name"
),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["DELETE"], detail=False)
def delete(self, request): # pylint: disable=invalid-name
"""Deletes file uploaded or produced by the programs,"""
Expand Down Expand Up @@ -230,19 +182,6 @@ def delete(self, request): # pylint: disable=invalid-name
)
return response

@swagger_auto_schema(
operation_description="Upload selected file",
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"file": openapi.Schema(type=openapi.TYPE_FILE, description="file name"),
"provider": openapi.Schema(
type=openapi.TYPE_STRING, description="provider name"
),
},
required=["file"],
),
)
@action(methods=["POST"], detail=False)
def upload(self, request): # pylint: disable=invalid-name
"""Upload selected file."""
Expand Down