Skip to content

Commit

Permalink
add v3.1-rc to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro100 committed Jun 4, 2024
1 parent 90bb728 commit 259d3dc
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 575 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/typescript_pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ jobs:
echo "Please update the package.json version so that your changes will be published."
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install dependencies
run: yarn

- name: Run tests
run: yarn test

3 changes: 2 additions & 1 deletion models/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ npm install gbfs-typescript-types --save-dev
```

## Versions
Currently only version 3.0 of GBFS is supported
- v3.0
- v3.1-RC

## Example Code
```typescript
Expand Down
3 changes: 2 additions & 1 deletion models/typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as v3 from './v3.0';
export * as v3 from './v3.0';
export * as v31rc from './v3.1-RC';
9 changes: 4 additions & 5 deletions models/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "gbfs-typescript-types",
"version": "1.0.4",
"version": "1.0.5",
"description": "Language Bindings for GBFS in Typescript",
"license": "Apache-2.0",
"types": "index.d.ts",
"author": "MobilityData",
"scripts": {
"generate_typescript_v3.0": "./scripts/generate_types.sh 3.0"
"postinstall": "cd ../../scripts && ./generate_typescript_models.sh",
"test": "jest"
},
"author": "MobilityData",
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"quicktype": "^23.0.145",
"ts-interface-builder": "^0.3.3",
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
Expand Down
119 changes: 119 additions & 0 deletions models/typescript/tests/v3.0.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { createCheckers } from "ts-interface-checker";

// checker model
import GbfsVersionsTI from '../v3.0/test-type-checkers/gbfs_versions-ti';
import GbfsTI from '../v3.0/test-type-checkers/gbfs-ti';
import GeofencingZonesTI from '../v3.0/test-type-checkers/geofencing_zones-ti';
import ManifestTI from '../v3.0/test-type-checkers/manifest-ti';
import StationsInformationTI from '../v3.0/test-type-checkers/station_information-ti';
import StationStatusTI from '../v3.0/test-type-checkers/station_status-ti';
import SystemAlertsTI from "../v3.0/test-type-checkers/system_alerts-ti";
import SystemInformationTI from '../v3.0/test-type-checkers/system_information-ti';
import SystemPricingPlansTI from '../v3.0/test-type-checkers/system_pricing_plans-ti'
import SystemRegionsTI from "../v3.0/test-type-checkers/system_regions-ti";
import VehicleStatusTI from "../v3.0/test-type-checkers/vehicle_status-ti";
import VehicleTypesTI from '../v3.0/test-type-checkers/vehicle_types-ti';

// checkers
const { GbfsVersions } = createCheckers(GbfsVersionsTI);
const { Gbfs } = createCheckers(GbfsTI);
const { GeofencingZones } = createCheckers(GeofencingZonesTI);
const { Manifest } = createCheckers(ManifestTI);
const { StationInformation } = createCheckers(StationsInformationTI);
const { StationStatus } = createCheckers(StationStatusTI);
const { SystemAlerts } = createCheckers(SystemAlertsTI);
const { SystemInformation } = createCheckers(SystemInformationTI);
const { SystemPricingPlans } = createCheckers(SystemPricingPlansTI);
const { SystemRegions } = createCheckers(SystemRegionsTI);
const { VehicleStatus } = createCheckers(VehicleStatusTI);
const { VehicleTypes } = createCheckers(VehicleTypesTI);

// json test data: these are gbfs with no errors for v3.0
import gbfsVersionsJson from '../../../testFixtures/v3.0/gbfs_versions.json';
import gbfsJson from '../../../testFixtures/v3.0/gbfs.json';
import geofencingZonesJson from '../../../testFixtures/v3.0/geofencing_zones.json';
import manifestJson from '../../../testFixtures/v3.0/manifest.json';
import stationInformationJson from '../../../testFixtures/v3.0/station_information.json';
import stationStatusJson from '../../../testFixtures/v3.0/station_status.json';
import systemAlertsJson from '../../../testFixtures/v3.0/system_alerts.json';
import systemInformationJson from '../../../testFixtures/v3.0/system_information.json';
import systemPricingPlansJson from '../../../testFixtures/v3.0/system_pricing_plans.json';
import systemRegionsJson from '../../../testFixtures/v3.0/system_regions.json';
import vehicleStatusJson from '../../../testFixtures/v3.0/vehicle_status.json';
import vehicleTypesJson from '../../../testFixtures/v3.0/vehicle_types.json';

// Date objects cannot be represented in JSON
// Manual checks for dates are required
describe('GBFS Validator v3.0', () => {
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 manifest is valid', () => {
expect(() => {
Manifest.check(manifestJson);
}).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(() => {
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(() => {
VehicleStatus.check(vehicleStatusJson);
}).not.toThrow();
});

it('should check if vehicle_types is valid', () => {
expect(() => {
VehicleTypes.check(vehicleTypesJson);
}).not.toThrow();
});
});
119 changes: 119 additions & 0 deletions models/typescript/tests/v3.1-RC.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { createCheckers } from "ts-interface-checker";

// checker model
import GbfsVersionsTI from '../v3.1-RC/test-type-checkers/gbfs_versions-ti';
import GbfsTI from '../v3.1-RC/test-type-checkers/gbfs-ti';
import GeofencingZonesTI from '../v3.1-RC/test-type-checkers/geofencing_zones-ti';
import ManifestTI from '../v3.1-RC/test-type-checkers/manifest-ti';
import StationsInformationTI from '../v3.1-RC/test-type-checkers/station_information-ti';
import StationStatusTI from '../v3.1-RC/test-type-checkers/station_status-ti';
import SystemAlertsTI from "../v3.1-RC/test-type-checkers/system_alerts-ti";
import SystemInformationTI from '../v3.1-RC/test-type-checkers/system_information-ti';
import SystemPricingPlansTI from '../v3.1-RC/test-type-checkers/system_pricing_plans-ti'
import SystemRegionsTI from "../v3.1-RC/test-type-checkers/system_regions-ti";
import VehicleStatusTI from "../v3.1-RC/test-type-checkers/vehicle_status-ti";
import VehicleTypesTI from '../v3.1-RC/test-type-checkers/vehicle_types-ti';

// checkers
const { GbfsVersions } = createCheckers(GbfsVersionsTI);
const { Gbfs } = createCheckers(GbfsTI);
const { GeofencingZones } = createCheckers(GeofencingZonesTI);
const { Manifest } = createCheckers(ManifestTI);
const { StationInformation } = createCheckers(StationsInformationTI);
const { StationStatus } = createCheckers(StationStatusTI);
const { SystemAlerts } = createCheckers(SystemAlertsTI);
const { SystemInformation } = createCheckers(SystemInformationTI);
const { SystemPricingPlans } = createCheckers(SystemPricingPlansTI);
const { SystemRegions } = createCheckers(SystemRegionsTI);
const { VehicleStatus } = createCheckers(VehicleStatusTI);
const { VehicleTypes } = createCheckers(VehicleTypesTI);

// json test data: these are gbfs with no errors for v3.1-RC
import gbfsVersionsJson from '../../../testFixtures/v3.1-RC/gbfs_versions.json';
import gbfsJson from '../../../testFixtures/v3.1-RC/gbfs.json';
import geofencingZonesJson from '../../../testFixtures/v3.1-RC/geofencing_zones.json';
import manifestJson from '../../../testFixtures/v3.1-RC/manifest.json';
import stationInformationJson from '../../../testFixtures/v3.1-RC/station_information.json';
import stationStatusJson from '../../../testFixtures/v3.1-RC/station_status.json';
import systemAlertsJson from '../../../testFixtures/v3.1-RC/system_alerts.json';
import systemInformationJson from '../../../testFixtures/v3.1-RC/system_information.json';
import systemPricingPlansJson from '../../../testFixtures/v3.1-RC/system_pricing_plans.json';
import systemRegionsJson from '../../../testFixtures/v3.1-RC/system_regions.json';
import vehicleStatusJson from '../../../testFixtures/v3.1-RC/vehicle_status.json';
import vehicleTypesJson from '../../../testFixtures/v3.1-RC/vehicle_types.json';

// Date objects cannot be represented in JSON
// Manual checks for dates are required
describe('GBFS Validator v3.1-RC', () => {
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 manifest is valid', () => {
expect(() => {
Manifest.check(manifestJson);
}).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(() => {
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(() => {
VehicleStatus.check(vehicleStatusJson);
}).not.toThrow();
});

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

export { GbfsVersions } from './gbfs_versions';
export { Gbfs } from './gbfs';
export { GeofencingZones } from './geofencing_zones';
Expand Down
14 changes: 14 additions & 0 deletions models/typescript/v3.1-RC/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Exports auto generated files

export { GbfsVersions } from './gbfs_versions';
export { Gbfs } from './gbfs';
export { GeofencingZones } from './geofencing_zones';
export { Manifest } from './manifest';
export { StationInformation } from './station_information';
export { StationStatus } from './station_status';
export { SystemAlerts } from './system_alerts';
export { SystemInformation } from './system_information';
export { SystemPricingPlans } from './system_pricing_plans';
export { SystemRegions } from './system_regions';
export { VehicleStatus } from './vehicle_status';
export { VehicleTypes } from './vehicle_types';
Loading

0 comments on commit 259d3dc

Please sign in to comment.