Skip to content

Commit c53ff75

Browse files
feat: NAV-5430 Schema api /direct_stop_points (#4528)
* feat: NAV-5430 Schema api /direct_stop_points * Fix lint * Fix build * Apply suggestion from @remi-lucas-hove
1 parent 2f98e32 commit c53ff75

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2001-2026, Hove and/or its affiliates. All rights reserved.
2+
#
3+
# This file is part of Navitia,
4+
# the software to build cool stuff with public transport.
5+
#
6+
# Hope you'll enjoy and contribute to this project,
7+
# powered by Hove (www.hove.com).
8+
# Help us simplify mobility and open public transport:
9+
# a non ending quest to the responsive locomotion way of traveling!
10+
#
11+
# LICENCE: This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU Affero General Public License as published by
13+
# the Free Software Foundation, either version 3 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Affero General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Affero General Public License
22+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
#
24+
# Stay tuned using
25+
# twitter @navitia
26+
# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org
27+
# https://groups.google.com/d/forum/navitia
28+
# www.navitia.io
29+
30+
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
31+
from jormungandr.interfaces.v1.serializer.direct_stop_points import DirectStopPointsSerializer
32+
33+
34+
class DirectStopPoints(ResourceUri):
35+
def __init__(self, *args, **kwargs):
36+
ResourceUri.__init__(self, output_type_serializer=DirectStopPointsSerializer, *args, **kwargs)
37+
parser_get = self.parsers["get"]
38+
parser_get.add_argument(
39+
"stop_point_id",
40+
type=str,
41+
required=True,
42+
help="Id of the stop point from where we want to access others stop points",
43+
)
44+
parser_get.add_argument(
45+
"line_id", type=str, required=True, help="Id of the line from where we want to access stop points"
46+
)
47+
48+
def options(self, **kwargs):
49+
return self.api_description(**kwargs)
50+
51+
def get(self, region=None, lon=None, lat=None, uri=None):
52+
pass
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) 2001-2026, Hove and/or its affiliates. All rights reserved.
2+
#
3+
# This file is part of Navitia,
4+
# the software to build cool stuff with public transport.
5+
#
6+
# Hope you'll enjoy and contribute to this project,
7+
# powered by Hove (www.hove.com).
8+
# Help us simplify mobility and open public transport:
9+
# a non ending quest to the responsive locomotion way of traveling!
10+
#
11+
# LICENCE: This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU Affero General Public License as published by
13+
# the Free Software Foundation, either version 3 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Affero General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Affero General Public License
22+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
#
24+
# Stay tuned using
25+
# twitter @navitia
26+
# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org
27+
# https://groups.google.com/d/forum/navitia
28+
# www.navitia.io
29+
30+
from __future__ import absolute_import
31+
import serpy
32+
from jormungandr.interfaces.v1.serializer import jsonschema
33+
34+
35+
accessible_stop_point_schema = {
36+
"type": "object",
37+
"properties": {
38+
"id": {"type": "string"},
39+
},
40+
}
41+
42+
direct_stop_points_result_schema = {
43+
"type": "object",
44+
"properties": {
45+
"from_stop_point_id": {"type": "string"},
46+
"accessible_stop_points": {
47+
"type": "array",
48+
"items": accessible_stop_point_schema,
49+
},
50+
},
51+
}
52+
53+
54+
class AccessibleStopPointSerializer(serpy.DictSerializer):
55+
id = serpy.StrField(display_none=True)
56+
57+
58+
class DirectStopPointsResultSerializer(serpy.DictSerializer):
59+
from_stop_point_id = serpy.StrField(display_none=True)
60+
accessible_stop_points = AccessibleStopPointSerializer(many=True, display_none=True)
61+
62+
63+
class DirectStopPointsSerializer(serpy.DictSerializer):
64+
direct_stop_points = jsonschema.MethodField(
65+
schema_metadata=direct_stop_points_result_schema,
66+
display_none=True,
67+
)
68+
69+
def get_direct_stop_points(self, obj):
70+
return DirectStopPointsResultSerializer(obj.get('direct_stop_points', {})).data

source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
opg_status,
5757
opg_excluded_zones,
5858
backends_status,
59+
direct_stop_points,
5960
)
6061
from werkzeug.routing import BaseConverter, FloatConverter, PathConverter
6162
from jormungandr.modules_loader import AModule
@@ -376,5 +377,11 @@ def setup(self):
376377
endpoint='obstacles_nearby',
377378
)
378379

380+
self.add_resource(
381+
direct_stop_points.DirectStopPoints,
382+
region + 'direct_stop_points',
383+
endpoint='direct_stop_points',
384+
)
385+
379386
self.add_resource(users.User, "/users", endpoint='users')
380387
self.add_resource(JSONSchema.Schema, '/schema', endpoint="schema")

0 commit comments

Comments
 (0)