Skip to content

Commit

Permalink
Url structure changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjohnson committed Oct 19, 2024
1 parent ff0b53d commit c769682
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 140 deletions.
4 changes: 3 additions & 1 deletion api/schema_generator.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
'''
8 changes: 8 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from rest_framework import routers
from django.conf.urls import include
from django.urls import path

from api import views

Expand All @@ -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))
]
126 changes: 1 addition & 125 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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']
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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__'
Expand 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
Expand All @@ -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__'
Expand 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
Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion api_v2/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
]
17 changes: 4 additions & 13 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit c769682

Please sign in to comment.