From d151bc788854c135a815e6ac2e71014a08d49442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Mon, 9 Dec 2024 15:29:30 +0100 Subject: [PATCH] serialize waytype correct --- src/c3nav/routing/api/routing.py | 8 ++++++-- src/c3nav/routing/route.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/c3nav/routing/api/routing.py b/src/c3nav/routing/api/routing.py index 2f7fed4d..2f434081 100644 --- a/src/c3nav/routing/api/routing.py +++ b/src/c3nav/routing/api/routing.py @@ -18,7 +18,7 @@ from c3nav.api.utils import NonEmptyStr from c3nav.mapdata.api.base import api_stats_clean_location_value from c3nav.mapdata.models.access import AccessPermission from c3nav.mapdata.models.locations import Position -from c3nav.mapdata.schemas.model_base import AnyLocationID, Coordinates3D +from c3nav.mapdata.schemas.model_base import AnyLocationID, Coordinates3D, TitledSchema, DjangoModelSchema from c3nav.mapdata.schemas.models import SlimLocationSchema, SpaceSchema, LevelSchema, SlimSpaceLocationSchema, \ SlimLevelLocationSchema from c3nav.mapdata.utils.cache.stats import increment_cache_key @@ -123,11 +123,15 @@ class RouteParametersSchema(BaseSchema): ) +class ShortWayTypeSchema(DjangoModelSchema): + pass + + class RouteItemSchema(BaseSchema): id: PositiveInt coordinates: Coordinates3D waytype: Union[ - Annotated[dict, APIField(title="waytype", descripiton="waytype used for this segment")], + Annotated[ShortWayTypeSchema, APIField(title="waytype", descripiton="waytype used for this segment")], Annotated[None, APIField(title="null", description="no waytype (normal walking)")], ] = APIField(None, title="waytype") space: Union[ diff --git a/src/c3nav/routing/route.py b/src/c3nav/routing/route.py index 939646d5..c5e1401e 100644 --- a/src/c3nav/routing/route.py +++ b/src/c3nav/routing/route.py @@ -6,6 +6,8 @@ import numpy as np from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ +from c3nav.routing.api.routing import ShortWayTypeSchema + def describe_location(location, locations): if location.can_describe: @@ -240,7 +242,7 @@ class RouteItem: result = OrderedDict(( ('id', self.node.pk), ('coordinates', (self.node.x, self.node.y, self.node.altitude)), - ('waytype', (self.route.router.waytypes[self.edge.waytype].serialize(detailed=False) + ('waytype', (ShortWayTypeSchema.model_validate(self.route.router.waytypes[self.edge.waytype]).model_dump() if self.edge and self.edge.waytype else None)), )) if self.waytype: