Skip to content

Commit 1303766

Browse files
committed
add 2.3 typescript models
1 parent 747c717 commit 1303766

18 files changed

+608
-3
lines changed

models/typescript/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
v2.3/*
2+
!v2.3/index.d.ts
13
v3.0/*
24
!v3.0/index.d.ts
35
v3.1-RC/*

models/typescript/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
},
1212
"files": [
1313
"index.d.ts",
14-
"v3.1-RC",
15-
"v3.0"
14+
"v2.3",
15+
"v3.0",
16+
"v3.1-RC"
1617
],
1718
"devDependencies": {
1819
"@types/jest": "^29.5.12",
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { createCheckers } from "ts-interface-checker";
2+
3+
// checker model
4+
import FreeBikeStatusTI from "../v2.3/test-type-checkers/free_bike_status-ti";
5+
import GbfsVersionsTI from "../v2.3/test-type-checkers/gbfs_versions-ti";
6+
import GbfsTI from "../v2.3/test-type-checkers/gbfs-ti";
7+
import GeofencingZonesTI from "../v2.3/test-type-checkers/geofencing_zones-ti";
8+
import StationsInformationTI from "../v2.3/test-type-checkers/station_information-ti";
9+
import StationStatusTI from "../v2.3/test-type-checkers/station_status-ti";
10+
import SystemAlertsTI from "../v2.3/test-type-checkers/system_alerts-ti";
11+
import SystemCalendarTI from "../v2.3/test-type-checkers/system_calendar-ti";
12+
import SystemHoursTI from "../v2.3/test-type-checkers/system_hours-ti";
13+
import SystemInformationTI from "../v2.3/test-type-checkers/system_information-ti";
14+
import SystemPricingPlansTI from "../v2.3/test-type-checkers/system_pricing_plans-ti";
15+
import SystemRegionsTI from "../v2.3/test-type-checkers/system_regions-ti";
16+
import VehicleTypesTI from "../v2.3/test-type-checkers/vehicle_types-ti";
17+
18+
// checkers
19+
const { FreeBikeStatus } = createCheckers(FreeBikeStatusTI);
20+
const { GbfsVersions } = createCheckers(GbfsVersionsTI);
21+
const { Gbfs } = createCheckers(GbfsTI);
22+
const { GeofencingZones } = createCheckers(GeofencingZonesTI);
23+
const { StationInformation } = createCheckers(StationsInformationTI);
24+
const { StationStatus } = createCheckers(StationStatusTI);
25+
const { SystemAlerts } = createCheckers(SystemAlertsTI);
26+
const { SystemCalendar } = createCheckers(SystemCalendarTI);
27+
const { SystemHours } = createCheckers(SystemHoursTI);
28+
const { SystemInformation } = createCheckers(SystemInformationTI);
29+
const { SystemPricingPlans } = createCheckers(SystemPricingPlansTI);
30+
const { SystemRegions } = createCheckers(SystemRegionsTI);
31+
const { VehicleTypes } = createCheckers(VehicleTypesTI);
32+
33+
// json test data: these are gbfs with no errors for v2.3
34+
import freeBikeStatusJson from "../../../testFixtures/v2.3/free_bike_status.json";
35+
import gbfsVersionsJson from "../../../testFixtures/v2.3/gbfs_versions.json";
36+
import gbfsJson from "../../../testFixtures/v2.3/gbfs.json";
37+
import geofencingZonesJson from "../../../testFixtures/v2.3/geofencing_zones.json";
38+
import stationInformationJson from "../../../testFixtures/v2.3/station_information.json";
39+
import stationStatusJson from "../../../testFixtures/v2.3/station_status.json";
40+
import systemAlertsJson from "../../../testFixtures/v2.3/system_alerts.json";
41+
import systemCalendarJson from "../../../testFixtures/v2.3/system_calendar.json";
42+
import systemHoursJson from "../../../testFixtures/v2.3/system_hours.json";
43+
import systemInformationJson from "../../../testFixtures/v2.3/system_information.json";
44+
import systemPricingPlansJson from "../../../testFixtures/v2.3/system_pricing_plans.json";
45+
import systemRegionsJson from "../../../testFixtures/v2.3/system_regions.json";
46+
import vehicleTypesJson from "../../../testFixtures/v2.3/vehicle_types.json";
47+
48+
// Date objects cannot be represented in JSON
49+
// Manual checks for dates are required
50+
describe("GBFS Validator v2.3", () => {
51+
it("should check if gbfs_versions is valid", () => {
52+
expect(() => {
53+
GbfsVersions.check(gbfsVersionsJson);
54+
}).not.toThrow();
55+
});
56+
57+
it("should check if gbfs is valid", () => {
58+
expect(() => {
59+
Gbfs.check(gbfsJson);
60+
}).not.toThrow();
61+
});
62+
63+
it("should check if geofencing_zones is valid", () => {
64+
expect(() => {
65+
GeofencingZones.check(geofencingZonesJson);
66+
}).not.toThrow();
67+
});
68+
69+
it("should check if station_information is valid", () => {
70+
expect(() => {
71+
StationInformation.check(stationInformationJson);
72+
}).not.toThrow();
73+
});
74+
75+
it("should check if station_status is valid", () => {
76+
expect(() => {
77+
StationStatus.check(stationStatusJson);
78+
}).not.toThrow();
79+
});
80+
81+
it("should check if system_alerts is valid", () => {
82+
expect(() => {
83+
SystemAlerts.check(systemAlertsJson);
84+
}).not.toThrow();
85+
});
86+
87+
it("should check if system_information is valid", () => {
88+
expect(() => {
89+
SystemCalendar.check(systemCalendarJson);
90+
}).not.toThrow();
91+
});
92+
93+
it("should check if system_information is valid", () => {
94+
expect(() => {
95+
SystemHours.check(systemHoursJson);
96+
}).not.toThrow();
97+
});
98+
99+
it("should check if system_information is valid", () => {
100+
expect(() => {
101+
SystemInformation.check(systemInformationJson);
102+
}).not.toThrow();
103+
});
104+
105+
it("should check if system_pricing_plans is valid", () => {
106+
expect(() => {
107+
SystemPricingPlans.check(systemPricingPlansJson);
108+
}).not.toThrow();
109+
});
110+
111+
it("should check if system_regions is valid", () => {
112+
expect(() => {
113+
SystemRegions.check(systemRegionsJson);
114+
}).not.toThrow();
115+
});
116+
117+
it("should check if vehicle_status is valida", () => {
118+
expect(() => {
119+
FreeBikeStatus.check(freeBikeStatusJson);
120+
}).not.toThrow();
121+
});
122+
123+
it("should check if vehicle_types is valid", () => {
124+
expect(() => {
125+
VehicleTypes.check(vehicleTypesJson);
126+
}).not.toThrow();
127+
});
128+
});

models/typescript/v2.3/index.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Exports auto generated files
2+
3+
export { FreeBikeStatus } from "./free_bike_status";
4+
export { GbfsVersions } from "./gbfs_versions";
5+
export { Gbfs } from "./gbfs";
6+
export { GeofencingZones } from "./geofencing_zones";
7+
export { StationInformation } from "./station_information";
8+
export { StationStatus } from "./station_status";
9+
export { SystemAlerts } from "./system_alerts";
10+
export { SystemCalendar } from "./system_calendar";
11+
export { SystemHours } from "./system_hours";
12+
export { SystemInformation } from "./system_information";
13+
export { SystemPricingPlans } from "./system_pricing_plans";
14+
export { SystemRegions } from "./system_regions";
15+
export { VehicleTypes } from "./vehicle_types";

scripts/generate_typescript_models.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ gbfs_version="v$1" #$1 is the first argument passed to the script (the version n
1010
parent_dir="$(dirname "$(dirname "$0")")"
1111
copyright_file="$parent_dir/copyright.txt"
1212

13-
gbfs_versions=("v3.0" "v3.1-RC")
13+
gbfs_versions=("v2.3" "v3.0" "v3.1-RC")
1414

1515
for gbfs_version in "${gbfs_versions[@]}"; do
1616
echo "gbfs_version: $gbfs_version"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"last_updated": 1606857968,
3+
"ttl": 300,
4+
"version": "2.3",
5+
"data": {
6+
"bikes": [
7+
{
8+
"bike_id": "TST:Scooter:1234",
9+
"lat": 59.91465759277344,
10+
"lon": 10.760470390319824,
11+
"is_reserved": false,
12+
"is_disabled": true,
13+
"vehicle_type_id": "TST:VehicleType:Scooter",
14+
"current_range_meters": 1431.2,
15+
"pricing_plan_id": "TST:PricingPlan:Basic",
16+
"rental_uris": {
17+
"android": "test://rentme/TST:Scooter:1234",
18+
"ios": "test://rentme/TST:Scooter:1234",
19+
"web": "https://test.com/rentme/TST:Scooter:1234"
20+
}
21+
}
22+
]
23+
}
24+
}

testFixtures/v2.3/gbfs.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"last_updated": 1606727710,
3+
"ttl": 300,
4+
"version": "2.3",
5+
"data": {
6+
"en": {
7+
"feeds": [
8+
{
9+
"name": "gbfs_versions",
10+
"url": "https://test.com/gbfs_versions"
11+
},
12+
{
13+
"name": "system_information",
14+
"url": "https://test.com/system_information"
15+
},
16+
{
17+
"name": "vehicle_types",
18+
"url": "https://test.com/vehicle_types"
19+
},
20+
{
21+
"name": "station_information",
22+
"url": "https://test.com/station_information"
23+
},
24+
{
25+
"name": "station_status",
26+
"url": "https://test.com/station_status"
27+
},
28+
{
29+
"name": "free_bike_status",
30+
"url": "https://test.com/free_bike_status"
31+
},
32+
{
33+
"name": "system_regions",
34+
"url": "https://test.com/system_regions"
35+
},
36+
{
37+
"name": "system_pricing_plans",
38+
"url": "https://test.com/system_pricing_plans"
39+
},
40+
{
41+
"name": "system_hours",
42+
"url": "https://test.com/system_hours"
43+
},
44+
{
45+
"name": "system_calendar",
46+
"url": "https://test.com/system_calendar"
47+
},
48+
{
49+
"name": "system_alerts",
50+
"url": "https://test.com/system_alerts"
51+
},
52+
{
53+
"name": "geofencing_zones",
54+
"url": "https://test.com/geofencing_zones"
55+
}
56+
]
57+
}
58+
}
59+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"last_updated": 1434054678,
3+
"ttl": 0,
4+
"version": "2.3",
5+
"data": {
6+
"versions": [
7+
{
8+
"version": "2.2",
9+
"url": "https://test.com/gbfs.json"
10+
}
11+
]
12+
}
13+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"last_updated": 1434054678,
3+
"ttl": 0,
4+
"version": "2.3",
5+
"data": {
6+
"geofencing_zones": {
7+
"type": "FeatureCollection",
8+
"features": [
9+
{
10+
"type": "Feature",
11+
"properties": {
12+
"name": "Nes",
13+
"rules": [
14+
{
15+
"vehicle_type_ids": ["TST:VehicleType:CityBike"],
16+
"ride_allowed": true,
17+
"ride_through_allowed": false,
18+
"maximum_speed_kph": 20
19+
}
20+
]
21+
},
22+
"geometry": {
23+
"type": "MultiPolygon",
24+
"coordinates": [
25+
[
26+
[
27+
[11.53037789067, 60.13740063434],
28+
[11.53372523957, 60.13598476211],
29+
[11.544177, 60.132072],
30+
[11.555332, 60.126844],
31+
[11.567186, 60.112231],
32+
[11.56403794135, 60.10918526319],
33+
[11.5629827195, 60.10773004658],
34+
[11.559217, 60.101878],
35+
[11.55869921547, 60.1018221676],
36+
[11.55847, 60.101506],
37+
[11.55581995556, 60.10123306033],
38+
[11.555637, 60.101056],
39+
[11.49821, 60.095299],
40+
[11.46896, 60.07201],
41+
[11.465957, 60.063589],
42+
[11.476578, 60.059879],
43+
[11.467241, 60.045013],
44+
[11.436058, 60.032524],
45+
[11.394385, 60.029916],
46+
[11.38968940258, 60.03265856905],
47+
[11.375861, 60.030292],
48+
[11.365442, 60.024714],
49+
[11.342163, 60.03279],
50+
[11.325316, 60.033807],
51+
[11.31339, 60.049798],
52+
[11.294868, 60.063006],
53+
[11.306277, 60.071862],
54+
[11.325134, 60.077875],
55+
[11.3179, 60.093846],
56+
[11.33319, 60.108785],
57+
[11.332603, 60.128479],
58+
[11.347831, 60.138723],
59+
[11.32735488653, 60.13999842085],
60+
[11.32497308493, 60.14556400031],
61+
[11.32493016958, 60.14790318539],
62+
[11.3246405071, 60.14881370558],
63+
[11.3217544502, 60.14920087268],
64+
[11.32161497533, 60.15038904672],
65+
[11.32253764987, 60.15125678982],
66+
[11.32308482051, 60.15271988181],
67+
[11.3271295917, 60.15647876853],
68+
[11.32802007437, 60.1609739234],
69+
[11.32733336449, 60.1687562641],
70+
[11.31669035912, 60.17985540754],
71+
[11.29737845421, 60.18267228561],
72+
[11.30046835899, 60.19009744236],
73+
[11.32081023216, 60.19607048737],
74+
[11.32132521629, 60.19820345431],
75+
[11.31720534325, 60.19944051162],
76+
[11.31566039085, 60.20404707345],
77+
[11.31428709984, 60.20660599502],
78+
[11.30793562889, 60.21197908067],
79+
[11.29720679283, 60.21342881013],
80+
[11.29205695152, 60.22250948067],
81+
[11.27961150169, 60.21641334548],
82+
[11.25377646446, 60.25220658872],
83+
[11.30664816856, 60.2682156618],
84+
[11.31445876122, 60.2603824128],
85+
[11.328425, 60.265399],
86+
[11.344468, 60.265328],
87+
[11.382948, 60.253896],
88+
[11.415655, 60.237796],
89+
[11.432291, 60.221773],
90+
[11.437049, 60.22409],
91+
[11.421506, 60.247612],
92+
[11.437835, 60.261601],
93+
[11.412849, 60.285637],
94+
[11.417028, 60.305307],
95+
[11.444868, 60.325789],
96+
[11.515287, 60.304312],
97+
[11.601261, 60.267216],
98+
[11.598781, 60.244722],
99+
[11.584431, 60.236376],
100+
[11.58390281439, 60.20433493011],
101+
[11.58154247046, 60.20230899341],
102+
[11.58229348898, 60.20020828485],
103+
[11.5798902297, 60.20017629332],
104+
[11.5793537879, 60.19961110456],
105+
[11.57785175085, 60.19900324918],
106+
[11.57600639105, 60.19744623492],
107+
[11.57697198629, 60.19644373459],
108+
[11.560396, 60.179793],
109+
[11.5646123457, 60.17349518201],
110+
[11.57135005474, 60.17688886704],
111+
[11.586852, 60.169218],
112+
[11.58838, 60.162737],
113+
[11.554175, 60.14945],
114+
[11.53037789067, 60.13740063434]
115+
]
116+
]
117+
]
118+
}
119+
}
120+
]
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)