API: add documentation tags.

master
Tom Hacohen 4 years ago
parent 15988235f2
commit 9f26ecf276

@ -13,8 +13,8 @@ from fastapi import FastAPI, Request
from .exceptions import CustomHttpException
from .authentication import authentication_router
from .collection import collection_router
from . import member # noqa
from .collection import collection_router, item_router
from .member import member_router
from .invitation import invitation_incoming_router, invitation_outgoing_router
from .msgpack import MsgpackResponse
@ -23,6 +23,8 @@ VERSION = "v1"
BASE_PATH = f"/api/{VERSION}"
app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication")
app.include_router(collection_router, prefix=f"{BASE_PATH}/collection")
app.include_router(item_router, prefix=f"{BASE_PATH}/collection")
app.include_router(member_router, prefix=f"{BASE_PATH}/collection")
app.include_router(invitation_incoming_router, prefix=f"{BASE_PATH}/invitation/incoming")
app.include_router(invitation_outgoing_router, prefix=f"{BASE_PATH}/invitation/outgoing")
if settings.DEBUG:

@ -33,7 +33,7 @@ User = get_user_model()
token_scheme = APIKeyHeader(name="Authorization")
AUTO_REFRESH = True
MIN_REFRESH_INTERVAL = 60
authentication_router = APIRouter(route_class=MsgpackRoute)
authentication_router = APIRouter(route_class=MsgpackRoute, tags=["authentication"])
@dataclasses.dataclass(frozen=True)

@ -7,7 +7,7 @@ from django.core.files.base import ContentFile
from django.db import transaction
from django.db.models import Q
from django.db.models import QuerySet
from fastapi import APIRouter, Depends, status, Request
from fastapi import APIRouter, Depends, status
from pydantic import BaseModel
from django_etebase import models
@ -18,7 +18,8 @@ from .stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_st
from .utils import get_object_or_404, Context, Prefetch, PrefetchQuery, is_collection_admin
User = get_user_model()
collection_router = APIRouter(route_class=MsgpackRoute)
collection_router = APIRouter(route_class=MsgpackRoute, tags=["collection"])
item_router = APIRouter(route_class=MsgpackRoute, tags=["item"])
default_queryset: QuerySet = models.Collection.objects.all()
default_item_queryset: QuerySet = models.CollectionItem.objects.all()
@ -378,7 +379,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val
return instance
@collection_router.get("/{collection_uid}/item/{item_uid}/")
@item_router.get("/{collection_uid}/item/{item_uid}/")
def item_get(
item_uid: str,
queryset: QuerySet = Depends(get_item_queryset),
@ -407,7 +408,7 @@ def item_list_common(
return MsgpackResponse(content=ret)
@collection_router.get("/{collection_uid}/item/")
@item_router.get("/{collection_uid}/item/")
async def item_list(
queryset: QuerySet = Depends(get_item_queryset),
stoken: t.Optional[str] = None,
@ -439,7 +440,7 @@ def item_bulk_common(data: ItemBatchIn, user: User, stoken: t.Optional[str], uid
return MsgpackResponse({})
@collection_router.get("/{collection_uid}/item/{item_uid}/revision/")
@item_router.get("/{collection_uid}/item/{item_uid}/revision/")
def item_revisions(
item_uid: str,
limit: int = 50,
@ -475,7 +476,7 @@ def item_revisions(
return MsgpackResponse(ret)
@collection_router.post("/{collection_uid}/item/fetch_updates/")
@item_router.post("/{collection_uid}/item/fetch_updates/")
def fetch_updates(
data: t.List[CollectionItemBulkGetIn],
stoken: t.Optional[str] = None,
@ -509,14 +510,14 @@ def fetch_updates(
return MsgpackResponse(ret)
@collection_router.post("/{collection_uid}/item/transaction/", dependencies=[Depends(has_write_access)])
@item_router.post("/{collection_uid}/item/transaction/", dependencies=[Depends(has_write_access)])
def item_transaction(
collection_uid: str, data: ItemBatchIn, stoken: t.Optional[str] = None, user: User = Depends(get_authenticated_user)
):
return item_bulk_common(data, user, stoken, collection_uid, validate_etag=True)
@collection_router.post("/{collection_uid}/item/batch/", dependencies=[Depends(has_write_access)])
@item_router.post("/{collection_uid}/item/batch/", dependencies=[Depends(has_write_access)])
def item_batch(
collection_uid: str, data: ItemBatchIn, stoken: t.Optional[str] = None, user: User = Depends(get_authenticated_user)
):

@ -14,8 +14,8 @@ from .msgpack import MsgpackRoute, MsgpackResponse
from .utils import get_object_or_404, Context, is_collection_admin
User = get_user_model()
invitation_incoming_router = APIRouter(route_class=MsgpackRoute)
invitation_outgoing_router = APIRouter(route_class=MsgpackRoute)
invitation_incoming_router = APIRouter(route_class=MsgpackRoute, tags=["incoming invitation"])
invitation_outgoing_router = APIRouter(route_class=MsgpackRoute, tags=["outgoing invitation"])
default_queryset: QuerySet = models.CollectionInvitation.objects.all()

@ -3,18 +3,19 @@ import typing as t
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import QuerySet
from fastapi import Depends, status
from fastapi import APIRouter, Depends, status
from pydantic import BaseModel
from django_etebase import models
from .authentication import get_authenticated_user
from .msgpack import MsgpackResponse
from .msgpack import MsgpackRoute, MsgpackResponse
from .utils import get_object_or_404
from .stoken_handler import filter_by_stoken_and_limit
from .collection import collection_router, get_collection, verify_collection_admin
from .collection import get_collection, verify_collection_admin
User = get_user_model()
member_router = APIRouter(route_class=MsgpackRoute, tags=["member"])
default_queryset: QuerySet = models.CollectionMember.objects.all()
@ -48,7 +49,7 @@ class MemberListResponse(BaseModel):
done: bool
@collection_router.get(
@member_router.get(
"/{collection_uid}/member/", response_model=MemberListResponse, dependencies=[Depends(verify_collection_admin)]
)
def member_list(
@ -70,7 +71,7 @@ def member_list(
return MsgpackResponse(ret)
@collection_router.delete(
@member_router.delete(
"/{collection_uid}/member/{username}/",
status_code=status.HTTP_204_NO_CONTENT,
dependencies=[Depends(verify_collection_admin)],
@ -81,7 +82,7 @@ def member_delete(
obj.revoke()
@collection_router.patch(
@member_router.patch(
"/{collection_uid}/member/{username}/",
status_code=status.HTTP_204_NO_CONTENT,
dependencies=[Depends(verify_collection_admin)],
@ -98,7 +99,7 @@ def member_patch(
instance.save()
@collection_router.post(
@member_router.post(
"/{collection_uid}/member/leave/",
status_code=status.HTTP_204_NO_CONTENT,
)

@ -8,7 +8,7 @@ from django_etebase.utils import get_user_queryset, CallbackContext
from etebase_fastapi.authentication import SignupIn, signup_save
from etebase_fastapi.msgpack import MsgpackRoute
test_reset_view_router = APIRouter(route_class=MsgpackRoute)
test_reset_view_router = APIRouter(route_class=MsgpackRoute, tags=["test helpers"])
User = get_user_model()

Loading…
Cancel
Save