Skip to content

Commit

Permalink
Initial drf-yasg to drf-spectacular migration (#48)
Browse files Browse the repository at this point in the history
* Initial drf-yasg to drf-spectacular migration

* Edit descriptions

* Install drf_spectacular

* Trailing slash

---------

Co-authored-by: Bane Sullivan <[email protected]>
  • Loading branch information
jzmiller1 and banesullivan authored Feb 22, 2023
1 parent 9491546 commit eb0a201
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 228 deletions.
13 changes: 12 additions & 1 deletion demo/myimages/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'drf_yasg',
'drf_spectacular',
'django_large_image',
]

Expand Down Expand Up @@ -129,3 +129,14 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

SPECTACULAR_SETTINGS = {
'TITLE': 'Django Large Image API',
'DESCRIPTION': 'Django Large Image Demo',
'CONTACT': {'email': '[email protected]'},
'LICENSE': {'name': 'Apache 2.0'},
}
29 changes: 5 additions & 24 deletions demo/myimages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
"""
from django.contrib import admin
from django.urls import include, path, re_path
from django.urls import include, path
from django.views.generic.base import RedirectView
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from myimages.imagefiles.viewsets import ImageFileDetailViewSet
from rest_framework import permissions
from rest_framework.routers import SimpleRouter

router = SimpleRouter(trailing_slash=False)
Expand All @@ -32,26 +30,9 @@
path(r'', RedirectView.as_view(url='admin/', permanent=False), name='index'),
] + router.urls

schema_view = get_schema_view(
openapi.Info(
title='Resonant GeoData API',
default_version='v1',
description='Resonant GeoData',
# terms_of_service='https://www.google.com/policies/terms/',
contact=openapi.Contact(email='[email protected]'),
license=openapi.License(name='Apache 2.0'),
),
public=True,
permission_classes=(permissions.AllowAny,),
patterns=urlpatterns,
)

urlpatterns += [
re_path(
r'^swagger(?P<format>\.json|\.yaml)$',
schema_view.without_ui(cache_timeout=0),
name='schema-json',
),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('schema/', SpectacularAPIView.as_view(), name='schema'),
path('swagger/', SpectacularSwaggerView.as_view(), name='schema-swagger-ui'),
path('redoc/', SpectacularRedocView.as_view(), name='schema-redoc'),
]
66 changes: 33 additions & 33 deletions django_large_image/rest/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import HttpResponse
from drf_yasg.utils import swagger_auto_schema
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.request import Request
Expand All @@ -21,10 +21,10 @@


class DataMixin(LargeImageMixinBase):
@swagger_auto_schema(
method='GET',
operation_summary=thumbnail_summary,
manual_parameters=thumbnail_parameters,
@extend_schema(
methods=['GET'],
summary=thumbnail_summary,
parameters=thumbnail_parameters,
)
@action(
detail=False,
Expand All @@ -41,10 +41,10 @@ def thumbnail(
thumb_data, mime_type = source.getThumbnail(encoding=encoding, width=width, height=height)
return HttpResponse(thumb_data, content_type=mime_type)

@swagger_auto_schema(
method='GET',
operation_summary=region_summary,
manual_parameters=region_parameters + params.STYLE,
@extend_schema(
methods=['GET'],
summary=region_summary,
parameters=region_parameters + params.STYLE,
)
@action(
detail=False,
Expand Down Expand Up @@ -85,10 +85,10 @@ def region(self, request: Request, pk: int = None, fmt: str = 'tiff', **kwargs)
tile_binary = open(path, 'rb')
return HttpResponse(tile_binary, content_type=mime_type)

@swagger_auto_schema(
method='GET',
operation_summary=pixel_summary,
manual_parameters=pixel_parameters,
@extend_schema(
methods=['GET'],
summary=pixel_summary,
parameters=pixel_parameters,
)
@action(detail=False, url_path='data/pixel')
def pixel(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand All @@ -98,10 +98,10 @@ def pixel(self, request: Request, pk: int = None, **kwargs) -> Response:
metadata = source.getPixel(region={'left': left, 'top': top, 'units': 'pixels'})
return Response(metadata)

@swagger_auto_schema(
method='GET',
operation_summary=histogram_summary,
manual_parameters=histogram_parameters,
@extend_schema(
methods=['GET'],
summary=histogram_summary,
parameters=histogram_parameters,
)
@action(detail=False, url_path='data/histogram')
def histogram(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand All @@ -128,10 +128,10 @@ def histogram(self, request: Request, pk: int = None, **kwargs) -> Response:


class DataDetailMixin(DataMixin):
@swagger_auto_schema(
method='GET',
operation_summary=thumbnail_summary,
manual_parameters=thumbnail_parameters,
@extend_schema(
methods=['GET'],
summary=thumbnail_summary,
parameters=thumbnail_parameters,
)
@action(
detail=True,
Expand All @@ -143,10 +143,10 @@ def thumbnail(
) -> HttpResponse:
return super().thumbnail(request, pk, fmt)

@swagger_auto_schema(
method='GET',
operation_summary=region_summary,
manual_parameters=region_parameters + params.STYLE,
@extend_schema(
methods=['GET'],
summary=region_summary,
parameters=region_parameters + params.STYLE,
)
@action(
detail=True,
Expand All @@ -156,19 +156,19 @@ def thumbnail(
def region(self, request: Request, pk: int = None, fmt: str = 'tiff', **kwargs) -> HttpResponse:
return super().region(request, pk, fmt)

@swagger_auto_schema(
method='GET',
operation_summary=pixel_summary,
manual_parameters=pixel_parameters,
@extend_schema(
methods=['GET'],
summary=pixel_summary,
parameters=pixel_parameters,
)
@action(detail=True, url_path='data/pixel')
def pixel(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().pixel(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=histogram_summary,
manual_parameters=histogram_parameters,
@extend_schema(
methods=['GET'],
summary=histogram_summary,
parameters=histogram_parameters,
)
@action(detail=True, url_path='data/histogram')
def histogram(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand Down
94 changes: 47 additions & 47 deletions django_large_image/rest/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import pathlib

from drf_yasg.utils import swagger_auto_schema
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action
from rest_framework.exceptions import APIException, ValidationError
from rest_framework.request import Request
Expand Down Expand Up @@ -33,43 +33,43 @@


class MetaDataMixin(LargeImageMixinBase):
@swagger_auto_schema(
method='GET',
operation_summary=metadata_summary,
manual_parameters=metadata_parameters,
@extend_schema(
methods=['GET'],
summary=metadata_summary,
parameters=metadata_parameters,
)
@action(detail=False, url_path='info/metadata')
def metadata(self, request: Request, pk: int = None, **kwargs) -> Response:
source = self.get_tile_source(request, pk, style=False)
metadata = tilesource.get_metadata(source)
return Response(metadata)

@swagger_auto_schema(
method='GET',
operation_summary=metadata_internal_summary,
manual_parameters=metadata_internal_parameters,
@extend_schema(
methods=['GET'],
summary=metadata_internal_summary,
parameters=metadata_internal_parameters,
)
@action(detail=False, url_path='info/metadata_internal')
def metadata_internal(self, request: Request, pk: int = None, **kwargs) -> Response:
source = self.get_tile_source(request, pk, style=False)
metadata = tilesource.get_metadata_internal(source)
return Response(metadata)

@swagger_auto_schema(
method='GET',
operation_summary=bands_summary,
manual_parameters=bands_parameters,
@extend_schema(
methods=['GET'],
summary=bands_summary,
parameters=bands_parameters,
)
@action(detail=False, url_path='info/bands')
def bands(self, request: Request, pk: int = None, **kwargs) -> Response:
source = self.get_tile_source(request, pk, style=False)
metadata = source.getBandInformation()
return Response(metadata)

@swagger_auto_schema(
method='GET',
operation_summary=bands_summary,
manual_parameters=band_parameters,
@extend_schema(
methods=['GET'],
summary=bands_summary,
parameters=band_parameters,
)
@action(detail=False, url_path='info/band')
def band(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand All @@ -79,20 +79,20 @@ def band(self, request: Request, pk: int = None, **kwargs) -> Response:
metadata = source.getOneBandInformation(band)
return Response(metadata)

@swagger_auto_schema(
method='GET',
operation_summary=frames_summary,
manual_parameters=frames_parameters,
@extend_schema(
methods=['GET'],
summary=frames_summary,
parameters=frames_parameters,
)
@action(detail=False, url_path='info/frames')
def frames(self, request: Request, pk: int = None, **kwargs) -> Response:
source = self.get_tile_source(request, pk, style=False)
data = tilesource.get_frames(source)
return Response(data)

@swagger_auto_schema(
method='GET',
operation_summary=tiffdump_summary,
@extend_schema(
methods=['GET'],
summary=tiffdump_summary,
)
@action(detail=False, url_path='info/tiffdump')
def tiffdump(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand All @@ -118,54 +118,54 @@ def tiffdump(self, request: Request, pk: int = None, **kwargs) -> Response:


class MetaDataDetailMixin(MetaDataMixin):
@swagger_auto_schema(
method='GET',
operation_summary=metadata_summary,
manual_parameters=metadata_parameters,
@extend_schema(
methods=['GET'],
summary=metadata_summary,
parameters=metadata_parameters,
)
@action(detail=True, url_path='info/metadata')
def metadata(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().metadata(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=metadata_internal_summary,
manual_parameters=metadata_internal_parameters,
@extend_schema(
methods=['GET'],
summary=metadata_internal_summary,
parameters=metadata_internal_parameters,
)
@action(detail=True, url_path='info/metadata_internal')
def metadata_internal(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().metadata_internal(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=bands_summary,
manual_parameters=bands_parameters,
@extend_schema(
methods=['GET'],
summary=bands_summary,
parameters=bands_parameters,
)
@action(detail=True, url_path='info/bands')
def bands(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().bands(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=bands_summary,
manual_parameters=band_parameters,
@extend_schema(
methods=['GET'],
summary=bands_summary,
parameters=band_parameters,
)
@action(detail=True, url_path='info/band')
def band(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().band(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=frames_summary,
manual_parameters=frames_parameters,
@extend_schema(
methods=['GET'],
summary=frames_summary,
parameters=frames_parameters,
)
@action(detail=True, url_path='info/frames')
def frames(self, request: Request, pk: int = None, **kwargs) -> Response:
return super().frames(request, pk)

@swagger_auto_schema(
method='GET',
operation_summary=tiffdump_summary,
@extend_schema(
methods=['GET'],
summary=tiffdump_summary,
)
@action(detail=True, url_path='info/tiffdump')
def tiffdump(self, request: Request, pk: int = None, **kwargs) -> Response:
Expand Down
Loading

0 comments on commit eb0a201

Please sign in to comment.