Skip to content

Commit ec97e25

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

19 files changed

+611
-5
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/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export * as v3 from './v3.0';
2-
export * as v31rc from './v3.1-RC';
1+
export * as v23 from "./v2.3";
2+
export * as v3 from "./v3.0";
3+
export * as v31rc from "./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",

models/typescript/tests/v2.3.spec.ts

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+
}

testFixtures/v2.3/gbfs_versions.json

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+
}

0 commit comments

Comments
 (0)