Skip to content

Commit 9d8dd8c

Browse files
authored
feat: add gbfs endpoint to the GBFSVersion entity (#1163)
1 parent da2f19c commit 9d8dd8c

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

functions-python/gbfs_validator/src/gbfs_data_processor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ def extract_gbfs_endpoints(
118118
except AttributeError:
119119
language = None
120120
endpoints += GBFSEndpoint.from_dict(feed_match.value, language)
121+
122+
# If the autodiscovery endpoint is not listed then add it
123+
if not any(endpoint.name == "gbfs" for endpoint in endpoints):
124+
endpoints += GBFSEndpoint.from_dict(
125+
[{"name": "gbfs", "url": gbfs_json_url}], None
126+
)
127+
121128
unique_endpoints = list(
122129
{
123130
f"{endpoint.name}, {endpoint.language or ''}": endpoint
@@ -277,9 +284,9 @@ def update_or_create_gbfs_endpoint(
277284
features: List[str],
278285
) -> Gbfsendpoint:
279286
"""Update or create a GBFS endpoint entity."""
280-
formatted_id = (
281-
f"{self.stable_id}_{version}_{endpoint.name}_{endpoint.language or ''}"
282-
)
287+
formatted_id = f"{self.stable_id}_{version}_{endpoint.name}"
288+
if endpoint.language:
289+
formatted_id += f"_{endpoint.language}"
283290
gbfs_endpoint_orm = (
284291
db_session.query(Gbfsendpoint)
285292
.filter(Gbfsendpoint.id == formatted_id)

functions-python/gbfs_validator/tests/test_gbfs_data_processor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,10 @@ def test_fetch_gbfs_files(
243243
# Validate versions
244244
self.assertEqual(len(gbfs_feed.gbfsversions), 2)
245245
versions = [version.version for version in gbfs_feed.gbfsversions]
246+
# Validate that autodiscovery url endpoint is added to all versions
247+
for gbfs_version in gbfs_feed.gbfsversions:
248+
assert any(
249+
endpoint.name == "gbfs" for endpoint in gbfs_version.gbfsendpoints
250+
)
246251
self.assertIn("2.2", versions)
247252
self.assertIn("2.1", versions)

liquibase/changelog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@
5353
<!-- Materialized view updated. Used Feed.official field as official status. -->
5454
<include file="changes/feat_1083.sql" relativeToChangelogFile="true"/>
5555
<include file="changes/feat_1132.sql" relativeToChangelogFile="true"/>
56+
<include file="changes/feat_1124.sql" relativeToChangelogFile="true"/>
5657
</databaseChangeLog>

liquibase/changes/feat_1124.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Insert a GbfsEndpoint row to GbfsVersions that miss the gbfs(autodiscovery) endpoint
2+
INSERT INTO GbfsEndpoint (id, gbfs_version_id, url, name, is_feature)
3+
SELECT
4+
Feed.stable_id || '_' || GbfsVersion.version AS id,
5+
GbfsVersion.id AS gbfs_version_id,
6+
GbfsVersion.url AS url,
7+
'gbfs' AS name,
8+
false AS is_feature -- gbfs file is not a feature, see https://github.com/MobilityData/mobility-feed-api/issues/1125
9+
FROM GbfsVersion
10+
JOIN GbfsFeed ON GbfsVersion.feed_id = GbfsFeed.id
11+
JOIN Feed ON GbfsFeed.id = Feed.id
12+
WHERE NOT EXISTS (
13+
SELECT 1
14+
FROM GbfsEndpoint
15+
WHERE GbfsEndpoint.gbfs_version_id = GbfsVersion.id
16+
AND GbfsEndpoint.name = 'gbfs'
17+
);

0 commit comments

Comments
 (0)