Skip to content

Commit

Permalink
Feat/typescript v31 rc (#130)
Browse files Browse the repository at this point in the history
v3.1-rc added to typescript
  • Loading branch information
Alessandro100 authored Jun 7, 2024
1 parent 766d6e6 commit 09aade5
Show file tree
Hide file tree
Showing 59 changed files with 1,813 additions and 4,761 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/typescript_package_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
build-publish:
name: build-publish-job
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./models/typescript

steps:
- name: Checkout repository
Expand All @@ -25,10 +22,14 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn
run: |
cd ./scripts
yarn
cd ../models/typescript
yarn
- name: Publish to npm
run: npm publish
run: cd ./models/typescript && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

22 changes: 22 additions & 0 deletions .github/workflows/typescript_pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ jobs:
echo "Please update the package.json version so that your changes will be published."
exit 1
fi
run-tests:
name: run-tests-job
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install dependencies
run: |
cd ./scripts
yarn
cd ../models/typescript
yarn
- name: Run tests
run: cd ./models/typescript && yarn test

4 changes: 2 additions & 2 deletions models/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import(
"io"
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
)
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
resp, err := http.Get(url)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
Expand All @@ -41,7 +41,7 @@ import(
"io"
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
)
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
resp, errHttp := http.Get(url)
defer resp.Body.Close()
body, errRead := io.ReadAll(resp.Body)
Expand Down
4 changes: 4 additions & 0 deletions models/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v3.0/*
!v3.0/index.d.ts
v3.1-RC/*
!v3.1-RC/index.d.ts
5 changes: 3 additions & 2 deletions 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 All @@ -30,7 +31,7 @@ import { Data as VehicleStatusData } from 'gbfs-typescript-types/v3.0/vehicle_st

let vehicleStatus: v3.VehicleStatus;
let systemInformationData: SystemInformationData;
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
const url = "https://berlin.example.tier-services.io/tier_paris/gbfs/3.0/system-information";
fetch(url).then((systemInformationResponse) => {
systemInformationResponse.json().then((systemInformationJson: SystemInformation) => {
systemInformationJson // will have access to types
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
14 changes: 0 additions & 14 deletions models/typescript/scripts/copyright.txt

This file was deleted.

43 changes: 0 additions & 43 deletions models/typescript/scripts/generate_types.sh

This file was deleted.

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();
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { createCheckers } from "ts-interface-checker";

// checker model
import GbfsVersionsTI from './ti/gbfs_versions-ti';
import GbfsTI from './ti/gbfs-ti';
import GeofencingZonesTI from './ti/geofencing_zones-ti';
import ManifestTI from './ti/manifest-ti';
import StationsInformationTI from './ti/station_information-ti';
import StationStatusTI from './ti/station_status-ti';
import SystemAlertsTI from "./ti/system_alerts-ti";
import SystemInformationTI from './ti/system_information-ti';
import SystemPricingPlansTI from './ti/system_pricing_plans-ti'
import SystemRegionsTI from "./ti/system_regions-ti";
import VehicleStatusTI from "./ti/vehicle_status-ti";
import VehicleTypesTI from './ti/vehicle_types-ti';
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);
Expand All @@ -28,23 +28,23 @@ 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';
// 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.0', () => {
describe('GBFS Validator v3.1-RC', () => {
it('should check if gbfs_versions is valid', () => {
expect(() => {
GbfsVersions.check(gbfsVersionsJson);
Expand Down
Loading

0 comments on commit 09aade5

Please sign in to comment.