Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2.3 typescript models #157

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions models/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v2.3/*
!v2.3/index.d.ts
v3.0/*
!v3.0/index.d.ts
v3.1-RC/*
Expand Down
5 changes: 3 additions & 2 deletions models/typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as v3 from './v3.0';
export * as v31rc from './v3.1-RC';
export * as v23 from "./v2.3";
export * as v3 from "./v3.0";
export * as v31rc from "./v3.1-RC";
5 changes: 3 additions & 2 deletions models/typescript/package.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! You'll need to bump the version in the package.json from 1.0.9 to 1.0.10 to trigger publishing to npmjs.com, otherwise it's good to go!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
},
"files": [
"index.d.ts",
"v3.1-RC",
"v3.0"
"v2.3",
"v3.0",
"v3.1-RC"
],
"devDependencies": {
"@types/jest": "^29.5.12",
Expand Down
128 changes: 128 additions & 0 deletions models/typescript/tests/v2.3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { createCheckers } from "ts-interface-checker";

// checker model
import FreeBikeStatusTI from "../v2.3/test-type-checkers/free_bike_status-ti";
import GbfsVersionsTI from "../v2.3/test-type-checkers/gbfs_versions-ti";
import GbfsTI from "../v2.3/test-type-checkers/gbfs-ti";
import GeofencingZonesTI from "../v2.3/test-type-checkers/geofencing_zones-ti";
import StationsInformationTI from "../v2.3/test-type-checkers/station_information-ti";
import StationStatusTI from "../v2.3/test-type-checkers/station_status-ti";
import SystemAlertsTI from "../v2.3/test-type-checkers/system_alerts-ti";
import SystemCalendarTI from "../v2.3/test-type-checkers/system_calendar-ti";
import SystemHoursTI from "../v2.3/test-type-checkers/system_hours-ti";
import SystemInformationTI from "../v2.3/test-type-checkers/system_information-ti";
import SystemPricingPlansTI from "../v2.3/test-type-checkers/system_pricing_plans-ti";
import SystemRegionsTI from "../v2.3/test-type-checkers/system_regions-ti";
import VehicleTypesTI from "../v2.3/test-type-checkers/vehicle_types-ti";

// checkers
const { FreeBikeStatus } = createCheckers(FreeBikeStatusTI);
const { GbfsVersions } = createCheckers(GbfsVersionsTI);
const { Gbfs } = createCheckers(GbfsTI);
const { GeofencingZones } = createCheckers(GeofencingZonesTI);
const { StationInformation } = createCheckers(StationsInformationTI);
const { StationStatus } = createCheckers(StationStatusTI);
const { SystemAlerts } = createCheckers(SystemAlertsTI);
const { SystemCalendar } = createCheckers(SystemCalendarTI);
const { SystemHours } = createCheckers(SystemHoursTI);
const { SystemInformation } = createCheckers(SystemInformationTI);
const { SystemPricingPlans } = createCheckers(SystemPricingPlansTI);
const { SystemRegions } = createCheckers(SystemRegionsTI);
const { VehicleTypes } = createCheckers(VehicleTypesTI);

// json test data: these are gbfs with no errors for v2.3
import freeBikeStatusJson from "../../../testFixtures/v2.3/free_bike_status.json";
import gbfsVersionsJson from "../../../testFixtures/v2.3/gbfs_versions.json";
import gbfsJson from "../../../testFixtures/v2.3/gbfs.json";
import geofencingZonesJson from "../../../testFixtures/v2.3/geofencing_zones.json";
import stationInformationJson from "../../../testFixtures/v2.3/station_information.json";
import stationStatusJson from "../../../testFixtures/v2.3/station_status.json";
import systemAlertsJson from "../../../testFixtures/v2.3/system_alerts.json";
import systemCalendarJson from "../../../testFixtures/v2.3/system_calendar.json";
import systemHoursJson from "../../../testFixtures/v2.3/system_hours.json";
import systemInformationJson from "../../../testFixtures/v2.3/system_information.json";
import systemPricingPlansJson from "../../../testFixtures/v2.3/system_pricing_plans.json";
import systemRegionsJson from "../../../testFixtures/v2.3/system_regions.json";
import vehicleTypesJson from "../../../testFixtures/v2.3/vehicle_types.json";

// Date objects cannot be represented in JSON
// Manual checks for dates are required
describe("GBFS Validator v2.3", () => {
it("should check if gbfs_versions is valid", () => {
expect(() => {
GbfsVersions.check(gbfsVersionsJson);
}).not.toThrow();
});

it("should check if gbfs is valid", () => {
expect(() => {
Gbfs.check(gbfsJson);
}).not.toThrow();
});

it("should check if geofencing_zones is valid", () => {
expect(() => {
GeofencingZones.check(geofencingZonesJson);
}).not.toThrow();
});

it("should check if station_information is valid", () => {
expect(() => {
StationInformation.check(stationInformationJson);
}).not.toThrow();
});

it("should check if station_status is valid", () => {
expect(() => {
StationStatus.check(stationStatusJson);
}).not.toThrow();
});

it("should check if system_alerts is valid", () => {
expect(() => {
SystemAlerts.check(systemAlertsJson);
}).not.toThrow();
});

it("should check if system_information is valid", () => {
expect(() => {
SystemCalendar.check(systemCalendarJson);
}).not.toThrow();
});

it("should check if system_information is valid", () => {
expect(() => {
SystemHours.check(systemHoursJson);
}).not.toThrow();
});

it("should check if system_information is valid", () => {
expect(() => {
SystemInformation.check(systemInformationJson);
}).not.toThrow();
});

it("should check if system_pricing_plans is valid", () => {
expect(() => {
SystemPricingPlans.check(systemPricingPlansJson);
}).not.toThrow();
});

it("should check if system_regions is valid", () => {
expect(() => {
SystemRegions.check(systemRegionsJson);
}).not.toThrow();
});

it("should check if vehicle_status is valida", () => {
expect(() => {
FreeBikeStatus.check(freeBikeStatusJson);
}).not.toThrow();
});

it("should check if vehicle_types is valid", () => {
expect(() => {
VehicleTypes.check(vehicleTypesJson);
}).not.toThrow();
});
});
15 changes: 15 additions & 0 deletions models/typescript/v2.3/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Exports auto generated files

export { FreeBikeStatus } from "./free_bike_status";
export { GbfsVersions } from "./gbfs_versions";
export { Gbfs } from "./gbfs";
export { GeofencingZones } from "./geofencing_zones";
export { StationInformation } from "./station_information";
export { StationStatus } from "./station_status";
export { SystemAlerts } from "./system_alerts";
export { SystemCalendar } from "./system_calendar";
export { SystemHours } from "./system_hours";
export { SystemInformation } from "./system_information";
export { SystemPricingPlans } from "./system_pricing_plans";
export { SystemRegions } from "./system_regions";
export { VehicleTypes } from "./vehicle_types";
2 changes: 1 addition & 1 deletion scripts/generate_typescript_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gbfs_version="v$1" #$1 is the first argument passed to the script (the version n
parent_dir="$(dirname "$(dirname "$0")")"
copyright_file="$parent_dir/copyright.txt"

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

for gbfs_version in "${gbfs_versions[@]}"; do
echo "gbfs_version: $gbfs_version"
Expand Down
24 changes: 24 additions & 0 deletions testFixtures/v2.3/free_bike_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"last_updated": 1606857968,
"ttl": 300,
"version": "2.3",
"data": {
"bikes": [
{
"bike_id": "TST:Scooter:1234",
"lat": 59.91465759277344,
"lon": 10.760470390319824,
"is_reserved": false,
"is_disabled": true,
"vehicle_type_id": "TST:VehicleType:Scooter",
"current_range_meters": 1431.2,
"pricing_plan_id": "TST:PricingPlan:Basic",
"rental_uris": {
"android": "test://rentme/TST:Scooter:1234",
"ios": "test://rentme/TST:Scooter:1234",
"web": "https://test.com/rentme/TST:Scooter:1234"
}
}
]
}
}
59 changes: 59 additions & 0 deletions testFixtures/v2.3/gbfs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"last_updated": 1606727710,
"ttl": 300,
"version": "2.3",
"data": {
"en": {
"feeds": [
{
"name": "gbfs_versions",
"url": "https://test.com/gbfs_versions"
},
{
"name": "system_information",
"url": "https://test.com/system_information"
},
{
"name": "vehicle_types",
"url": "https://test.com/vehicle_types"
},
{
"name": "station_information",
"url": "https://test.com/station_information"
},
{
"name": "station_status",
"url": "https://test.com/station_status"
},
{
"name": "free_bike_status",
"url": "https://test.com/free_bike_status"
},
{
"name": "system_regions",
"url": "https://test.com/system_regions"
},
{
"name": "system_pricing_plans",
"url": "https://test.com/system_pricing_plans"
},
{
"name": "system_hours",
"url": "https://test.com/system_hours"
},
{
"name": "system_calendar",
"url": "https://test.com/system_calendar"
},
{
"name": "system_alerts",
"url": "https://test.com/system_alerts"
},
{
"name": "geofencing_zones",
"url": "https://test.com/geofencing_zones"
}
]
}
}
}
13 changes: 13 additions & 0 deletions testFixtures/v2.3/gbfs_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"last_updated": 1434054678,
"ttl": 0,
"version": "2.3",
"data": {
"versions": [
{
"version": "2.2",
"url": "https://test.com/gbfs.json"
}
]
}
}
Loading