Skip to content

Commit 09aade5

Browse files
Feat/typescript v31 rc (#130)
v3.1-rc added to typescript
1 parent 766d6e6 commit 09aade5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1813
-4761
lines changed

.github/workflows/typescript_package_publish.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
build-publish:
1111
name: build-publish-job
1212
runs-on: ubuntu-latest
13-
defaults:
14-
run:
15-
working-directory: ./models/typescript
1613

1714
steps:
1815
- name: Checkout repository
@@ -25,10 +22,14 @@ jobs:
2522
registry-url: 'https://registry.npmjs.org'
2623

2724
- name: Install dependencies
28-
run: yarn
25+
run: |
26+
cd ./scripts
27+
yarn
28+
cd ../models/typescript
29+
yarn
2930
3031
- name: Publish to npm
31-
run: npm publish
32+
run: cd ./models/typescript && npm publish
3233
env:
3334
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
3435

.github/workflows/typescript_pr_check.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ jobs:
3737
echo "Please update the package.json version so that your changes will be published."
3838
exit 1
3939
fi
40+
run-tests:
41+
name: run-tests-job
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v2
47+
48+
- name: Setup Node.js
49+
uses: actions/setup-node@v2
50+
with:
51+
node-version: '18'
52+
53+
- name: Install dependencies
54+
run: |
55+
cd ./scripts
56+
yarn
57+
cd ../models/typescript
58+
yarn
59+
60+
- name: Run tests
61+
run: cd ./models/typescript && yarn test
4062

models/golang/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import(
2222
"io"
2323
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
2424
)
25-
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
25+
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
2626
resp, err := http.Get(url)
2727
defer resp.Body.Close()
2828
body, err := io.ReadAll(resp.Body)
@@ -41,7 +41,7 @@ import(
4141
"io"
4242
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
4343
)
44-
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
44+
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
4545
resp, errHttp := http.Get(url)
4646
defer resp.Body.Close()
4747
body, errRead := io.ReadAll(resp.Body)

models/typescript/.gitignore

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

models/typescript/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ npm install gbfs-typescript-types --save-dev
1414
```
1515

1616
## Versions
17-
Currently only version 3.0 of GBFS is supported
17+
- v3.0
18+
- v3.1-RC
1819

1920
## Example Code
2021
```typescript
@@ -30,7 +31,7 @@ import { Data as VehicleStatusData } from 'gbfs-typescript-types/v3.0/vehicle_st
3031

3132
let vehicleStatus: v3.VehicleStatus;
3233
let systemInformationData: SystemInformationData;
33-
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
34+
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
3435
fetch(url).then((systemInformationResponse) => {
3536
systemInformationResponse.json().then((systemInformationJson: SystemInformation) => {
3637
systemInformationJson // will have access to types

models/typescript/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * as v3 from './v3.0';
1+
export * as v3 from './v3.0';
2+
export * as v31rc from './v3.1-RC';

models/typescript/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"name": "gbfs-typescript-types",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Language Bindings for GBFS in Typescript",
55
"license": "Apache-2.0",
66
"types": "index.d.ts",
7+
"author": "MobilityData",
78
"scripts": {
8-
"generate_typescript_v3.0": "./scripts/generate_types.sh 3.0"
9+
"postinstall": "cd ../../scripts && ./generate_typescript_models.sh",
10+
"test": "jest"
911
},
10-
"author": "MobilityData",
1112
"devDependencies": {
1213
"@types/jest": "^29.5.12",
1314
"jest": "^29.7.0",
14-
"quicktype": "^23.0.145",
15-
"ts-interface-builder": "^0.3.3",
1615
"ts-jest": "^29.1.2",
1716
"typescript": "^5.4.5"
1817
},

models/typescript/scripts/copyright.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

models/typescript/scripts/generate_types.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

models/typescript/tests/v3.0.spec.ts

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

0 commit comments

Comments
 (0)