add tons of mapdata endpoints, enhance documentation and operation IDs
This commit is contained in:
parent
7447537c4a
commit
f43d458fc4
12 changed files with 637 additions and 169 deletions
|
@ -2,19 +2,15 @@ import inspect
|
|||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import include, path, re_path
|
||||
from django.utils.functional import cached_property
|
||||
from ninja import NinjaAPI, Swagger
|
||||
from ninja.schema import NinjaGenerateJsonSchema
|
||||
from rest_framework.generics import GenericAPIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.routers import SimpleRouter
|
||||
|
||||
from c3nav.api.api import SessionViewSet
|
||||
from c3nav.api.exceptions import CustomAPIException
|
||||
from c3nav.api.newapi import auth_api_router
|
||||
from c3nav.api.newauth import APITokenAuth
|
||||
from c3nav.api.ninja import ninja_api
|
||||
from c3nav.editor.api import ChangeSetViewSet, EditorViewSet
|
||||
from c3nav.mapdata.api import (AccessRestrictionGroupViewSet, AccessRestrictionViewSet, AreaViewSet, BuildingViewSet,
|
||||
ColumnViewSet, CrossDescriptionViewSet, DoorViewSet, DynamicLocationPositionViewSet,
|
||||
|
@ -22,70 +18,27 @@ from c3nav.mapdata.api import (AccessRestrictionGroupViewSet, AccessRestrictionV
|
|||
LocationBySlugViewSet, LocationGroupCategoryViewSet, LocationGroupViewSet,
|
||||
LocationViewSet, MapViewSet, ObstacleViewSet, POIViewSet, RampViewSet, SourceViewSet,
|
||||
SpaceViewSet, StairViewSet, UpdatesViewSet)
|
||||
from c3nav.mapdata.newapi.endpoints import map_api_router
|
||||
from c3nav.mapdata.newapi.map import map_api_router
|
||||
from c3nav.mapdata.newapi.mapdata import mapdata_api_router
|
||||
from c3nav.mapdata.utils.user import can_access_editor
|
||||
from c3nav.mesh.api import FirmwareViewSet
|
||||
from c3nav.mesh.newapi import mesh_api_router
|
||||
from c3nav.routing.api import RoutingViewSet
|
||||
|
||||
description = """
|
||||
Nearly all endpoints require authentication, but guest authentication can be used.
|
||||
|
||||
API endpoints may change to add more features and properties,
|
||||
but no properties will be removed without a version change.
|
||||
""".strip()
|
||||
|
||||
ninja_api = NinjaAPI(
|
||||
title="c3nav API",
|
||||
version="v2",
|
||||
description=description,
|
||||
|
||||
docs_url="/",
|
||||
docs=Swagger(settings={
|
||||
"persistAuthorization": True,
|
||||
"defaultModelRendering": "model",
|
||||
}),
|
||||
|
||||
auth=APITokenAuth(),
|
||||
|
||||
openapi_extra={
|
||||
"tags": [
|
||||
{
|
||||
"name": "auth",
|
||||
"description": "Get and manage API access",
|
||||
},
|
||||
{
|
||||
"name": "map",
|
||||
"description": "Access the map data",
|
||||
},
|
||||
{
|
||||
"name": "mesh",
|
||||
"description": "Manage the location node mesh network",
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ninja_api.exception_handler(CustomAPIException)
|
||||
def on_invalid_token(request, exc):
|
||||
return ninja_api.create_response(request, {"detail": exc.detail}, status=exc.status_code)
|
||||
|
||||
|
||||
"""
|
||||
ugly hack: remove schema from the end of definition names
|
||||
new API (v2)
|
||||
"""
|
||||
orig_normalize_name = NinjaGenerateJsonSchema.normalize_name
|
||||
def wrap_normalize_name(self, name: str): # noqa
|
||||
return orig_normalize_name(self, name).removesuffix('Schema')
|
||||
NinjaGenerateJsonSchema.normalize_name = wrap_normalize_name # noqa
|
||||
|
||||
|
||||
ninja_api.add_router("/auth/", auth_api_router)
|
||||
ninja_api.add_router("/map/", map_api_router)
|
||||
ninja_api.add_router("/mapdata/", mapdata_api_router)
|
||||
ninja_api.add_router("/mesh/", mesh_api_router)
|
||||
|
||||
|
||||
"""
|
||||
legacy API
|
||||
"""
|
||||
router = SimpleRouter()
|
||||
|
||||
router.register(r'map', MapViewSet, basename='map')
|
||||
router.register(r'levels', LevelViewSet)
|
||||
router.register(r'buildings', BuildingViewSet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue