diff --git a/api/schema_generator.py b/api/schema_generator.py index 384529d8..f88961a0 100644 --- a/api/schema_generator.py +++ b/api/schema_generator.py @@ -1,4 +1,4 @@ -from rest_framework.schemas.openapi import SchemaGenerator +'''from rest_framework.schemas.openapi import SchemaGenerator from rest_framework.schemas.openapi import AutoSchema # Adds additional metadata onto an OAS operation. Attach this to your view and provide the necessary constructor args. @@ -21,6 +21,7 @@ def get_operation(self, path, method): oldOperation = super().get_operation(path, method) # I can't find a version of DRF that support summaries + if path.startswith('/v1/'): return oldOperation oldOperation['summary'] = self.extra_info['summary'][path] # Future versions of DRF support tags @@ -61,3 +62,4 @@ def get_schema(self, *args, **kwargs): # This isn't a real endpoint, so we remove it from the schema schema['paths'].pop('/search/{id}/') return schema +''' \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index a1e67170..28de6484 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,4 +1,6 @@ from rest_framework import routers +from django.conf.urls import include +from django.urls import path from api import views @@ -18,3 +20,9 @@ router.register(r'magicitems',views.MagicItemViewSet) router.register(r'weapons',views.WeaponViewSet) router.register(r'armor',views.ArmorViewSet) + +urlpatterns = [ + path('', include(router.urls)), #Consider removing this after a while. + path('version/', views.get_version, name="version"), + path('v1/', include(router.urls)) + ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index 3df3a695..32a905a2 100644 --- a/api/views.py +++ b/api/views.py @@ -7,7 +7,7 @@ from api import models from api import serializers from api import filters -from api.schema_generator import CustomSchema +#from api.schema_generator import CustomSchema class ManifestViewSet(viewsets.ReadOnlyModelViewSet): @@ -28,13 +28,6 @@ class ManifestViewSet(viewsets.ReadOnlyModelViewSet): automatically downloads data from Open5e, you can periodically check the manifests to determine whether your data is out of date. """ - schema = CustomSchema( - summary={ - '/manifest/': 'List Manifests', - '/manifest/{id}/': 'Retrieve Manifest', - }, - tags=['Manifests'], - ) queryset = models.Manifest.objects.all().order_by("pk") serializer_class = serializers.ManifestSerializer @@ -102,18 +95,6 @@ class DocumentViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of documents. retrieve: API endpoint for returning a particular document. """ - schema = CustomSchema( - summary={ - '/documents/': 'List Documents', - '/documents/{id}/': 'Retrieve Document', - }, - tags=['Documents'], - query={ - 'slug': 'A short, human readable string uniquely identifying this document', - 'title': 'A short descriptive title of this document', - 'organization': 'The organization that published the document', - 'license': 'The license under which the document is published', - }) queryset = models.Document.objects.all().order_by("pk") serializer_class = serializers.DocumentSerializer search_fields = ['title', 'desc'] @@ -130,13 +111,6 @@ class SpellViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of spells. retrieve: API endpoint for returning a particular spell. """ - schema = CustomSchema( - summary={ - '/spells/': 'List Spells', - '/spells/{slug}/': 'Retrieve Spell', - }, - tags=['Spells'] - ) queryset = models.Spell.objects.all().order_by("pk") filterset_class=filters.SpellFilter serializer_class = serializers.SpellSerializer @@ -163,13 +137,6 @@ class SpellListViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of spell lists. retrieve: API endpoint for returning a particular spell list. """ - schema = CustomSchema( - summary={ - '/spelllist/': 'List Spell Lists', - '/spelllist/{slug}/': 'Retrieve Spell List', - }, - tags=['SpellList'] - ) queryset = models.SpellList.objects.all().order_by("pk") serializer_class = serializers.SpellListSerializer filterset_class = filters.SpellListFilter @@ -181,13 +148,6 @@ class MonsterViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of monsters. retrieve: API endpoint for returning a particular monster. """ - schema = CustomSchema( - summary={ - '/monsters/': 'List Monsters', - '/monsters/{slug}/': 'Retrieve Monster', - }, - tags=['Monsters'] - ) queryset = models.Monster.objects.all().order_by("pk") filterset_class = filters.MonsterFilter @@ -199,13 +159,6 @@ class BackgroundViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of backgrounds. retrieve: API endpoint for returning a particular background. """ - schema = CustomSchema( - summary={ - '/backgrounds/': 'List Backgrounds', - '/backgrounds/{slug}/': 'Retrieve Background', - }, - tags=['Backgrounds'] - ) queryset = models.Background.objects.all().order_by("pk") serializer_class = serializers.BackgroundSerializer ordering_fields = '__all__' @@ -219,13 +172,6 @@ class PlaneViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of planes. retrieve: API endpoint for returning a particular plane. """ - schema = CustomSchema( - summary={ - '/planes/': 'List Planes', - '/planes/{slug}/': 'Retrieve Plane', - }, - tags=['Planes'] - ) queryset = models.Plane.objects.all().order_by("pk") serializer_class = serializers.PlaneSerializer filterset_class = filters.PlaneFilter @@ -237,13 +183,6 @@ class SectionViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of sections. retrieve: API endpoint for returning a particular section. """ - schema = CustomSchema( - summary={ - '/sections/': 'List Sections', - '/sections/{slug}/': 'Retrieve Section', - }, - tags=['Sections'] - ) queryset = models.Section.objects.all().order_by("pk") serializer_class = serializers.SectionSerializer ordering_fields = '__all__' @@ -257,13 +196,6 @@ class FeatViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of feats. retrieve: API endpoint for returning a particular feat. """ - schema = CustomSchema( - summary={ - '/feats/': 'List Feats', - '/feats/{slug}/': 'Retrieve Feat', - }, - tags=['Feats'] - ) queryset = models.Feat.objects.all().order_by("pk") serializer_class = serializers.FeatSerializer filterset_class = filters.FeatFilter @@ -275,13 +207,6 @@ class ConditionViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of conditions. retrieve: API endpoint for returning a particular condition. """ - schema = CustomSchema( - summary={ - '/conditions/': 'List Conditions', - '/conditions/{slug}/': 'Retrieve Condition', - }, - tags=['Conditions'] - ) queryset = models.Condition.objects.all().order_by("pk") serializer_class = serializers.ConditionSerializer search_fields = ['name', 'desc'] @@ -293,13 +218,6 @@ class RaceViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of races. retrieve: API endpoint for returning a particular race. """ - schema = CustomSchema( - summary={ - '/races/': 'List Races', - '/races/{slug}/': 'Retrieve Race', - }, - tags=['Races'] - ) queryset = models.Race.objects.all().order_by("pk") serializer_class = serializers.RaceSerializer filterset_class = filters.RaceFilter @@ -312,13 +230,6 @@ class SubraceViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint that allows viewing of Subraces. retrieve: API endpoint for returning a particular subrace. """ - schema = CustomSchema( - summary={ - '/subraces/': 'List Subraces', - '/subraces/{slug}/': 'Retrieve Subrace', - }, - tags=['Subraces'] - ) queryset = models.Subrace.objects.all().order_by("pk") serializer_class = serializers.SubraceSerializer search_fields = ['name', 'desc'] @@ -333,13 +244,6 @@ class CharClassViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of classes and archetypes. retrieve: API endpoint for returning a particular class or archetype. """ - schema = CustomSchema( - summary={ - '/classes/': 'List Classes', - '/classes/{slug}/': 'Retrieve Class', - }, - tags=['Classes'] - ) queryset = models.CharClass.objects.all().order_by("pk") serializer_class = serializers.CharClassSerializer filterset_class = filters.CharClassFilter @@ -352,13 +256,6 @@ class ArchetypeViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint that allows viewing of Archetypes. retrieve: API endpoint for returning a particular archetype. """ - schema = CustomSchema( - summary={ - '/archetypes/': 'List Archetypes', - '/archetypes/{slug}/': 'Retrieve Archetype', - }, - tags=['Archetypes'] - ) queryset = models.Archetype.objects.all().order_by("pk") serializer_class = serializers.ArchetypeSerializer search_fields = ['name', 'desc'] @@ -373,13 +270,6 @@ class MagicItemViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of magic items. retrieve: API endpoint for returning a particular magic item. """ - schema = CustomSchema( - summary={ - '/magicitems/': 'List Magic Items', - '/magicitems/{slug}/': 'Retrieve Magic Item', - }, - tags=['Magic Items'] - ) queryset = models.MagicItem.objects.all().order_by("pk") serializer_class = serializers.MagicItemSerializer filterset_class = filters.MagicItemFilter @@ -391,13 +281,6 @@ class WeaponViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of weapons. retrieve: API endpoint for returning a particular weapon. """ - schema = CustomSchema( - summary={ - '/weapons/': 'List Weapons', - '/weapons/{slug}/': 'Retrieve Weapon', - }, - tags=['Weapons'] - ) queryset = models.Weapon.objects.all().order_by("pk") serializer_class = serializers.WeaponSerializer filterset_class = filters.WeaponFilter @@ -409,13 +292,6 @@ class ArmorViewSet(viewsets.ReadOnlyModelViewSet): list: API endpoint for returning a list of armor. retrieve: API endpoint for returning a particular armor. """ - schema = CustomSchema( - summary={ - '/armor/': 'List Armor', - '/armor/{slug}/': 'Retrieve Armor', - }, - tags=['Armor'] - ) queryset = models.Armor.objects.all().order_by("pk") serializer_class = serializers.ArmorSerializer filterset_class = filters.ArmorFilter diff --git a/api_v2/urls.py b/api_v2/urls.py index 7c496d0f..249bad31 100644 --- a/api_v2/urls.py +++ b/api_v2/urls.py @@ -1,4 +1,5 @@ - +from django.conf.urls import include +from django.urls import path from rest_framework import routers from api_v2 import views @@ -35,3 +36,9 @@ search_router = routers.DefaultRouter() search_router.register('',views.SearchResultViewSet, basename='search') + +urlpatterns = [ + path('v2/', include(router.urls)), + path('v2/search/', include(search_router.urls)), + path('v2/enums/', views.get_enums, name="enums") +] diff --git a/server/urls.py b/server/urls.py index e35b88b4..a1f75932 100644 --- a/server/urls.py +++ b/server/urls.py @@ -15,25 +15,16 @@ """ from django.conf.urls import include - -from django.contrib import admin from django.urls import path +from django.contrib import admin from django.conf import settings from api import urls as v1_urls -from api.views import get_version from api_v2 import urls as v2_urls -from api_v2.views import get_enums -urlpatterns = [ - path('', include(v1_urls.router.urls)), - path('version/', get_version, name="version"), - path('v1/', include(v1_urls.router.urls)), - - path('v2/', include(v2_urls.router.urls)), - path('v2/search/', include(v2_urls.search_router.urls)), - path('v2/enums/', get_enums, name="enums") -] +urlpatterns = [] +urlpatterns+=v1_urls.urlpatterns +urlpatterns+=v2_urls.urlpatterns if settings.DEBUG is True: urlpatterns.append(path('admin/', admin.site.urls))