Skip to content

Commit

Permalink
Merge branch 'master' into feat/validator-summary-function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Dec 14, 2023
2 parents 2a65ed7 + d81912f commit 50f351e
Show file tree
Hide file tree
Showing 130 changed files with 7,180 additions and 11,863 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/new-issue-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: New Issue Template
about: 'Please use this template for all new issues.'
---

### **If you are new to the GBFS Validator, please introduce yourself (name and organization/link to GBFS). It’s helpful to know who we're chatting with!**
### If you are new to the GBFS Validator, please introduce yourself (name and organization/link to GBFS). It’s helpful to know who we're chatting with!

### **What is the issue and _why_ is it an issue?**
### What is the issue and _why_ is it an issue?

### **Please describe some potential solutions you have considered (even if they aren’t related to GBFS).**
### Please describe some potential solutions you have considered (even if they aren’t related to GBFS).
5 changes: 5 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ jobs:

steps:
- uses: actions/checkout@v3.4.0

- uses: actions/setup-node@v3
with:
node-version: 18

- name: setup node-gyp
run: npm install -g node-gyp@latest

- name: Run tests
run: yarn install && yarn workspaces run test
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The function is only compatible with Netlify Function (https://www.netlify.com/p

- check-systems

Check-systems is a CLI tool to validate the whole “systems.csv” from https://github.com/NABSA/gbfs locally
Check-systems is a CLI tool to validate the whole “systems.csv” from https://github.com/MobilityData/gbfs locally

# Code convention

Expand Down
10 changes: 5 additions & 5 deletions RULES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This project validates feeds up to version 3.0-RC of the [JSON Schemas](https://github.com/MobilityData/gbfs-json-schema).
This project validates feeds up to version 3.0-RC2 of the [JSON Schemas](https://github.com/MobilityData/gbfs-json-schema).
# Files presence
The validator will flag any missing file. It will inform the user if the missing file is required or not, as per the conditions in the GBFS version that it detects.

Expand All @@ -18,12 +18,12 @@ The validator will check for the presence of the files depending on the options
<img width="350" alt="tick boxes" src="https://user-images.githubusercontent.com/63653518/156194900-bab75f85-f681-43a4-84d3-08c9d6fed4df.png">


The Validator also checks the conditional requirement of the file `vehicle_types.json`: as per the [official GBFS specification](https://github.com/NABSA/gbfs/blob/master/gbfs.md#vehicle_typesjson), it is required of systems that include information about vehicle types in the `vehicle_status.json file`.
The Validator also checks the conditional requirement of the file `vehicle_types.json`: as per the [official GBFS specification](https://github.com/MobilityData/gbfs/blob/master/gbfs.md#vehicle_typesjson), it is required of systems that include information about vehicle types in the `vehicle_status.json file`.


# Fields presence and field types
## Required fields
Each file in GBFS has to be structured in a specific [output format](https://github.com/NABSA/gbfs/blob/master/gbfs.md#output-format).
Each file in GBFS has to be structured in a specific [output format](https://github.com/MobilityData/gbfs/blob/master/gbfs.md#output-format).
All the fields that are described as **required** in GBFS will be checked by the validator.
Some fields are required only if the parent field is defined, and this is considered a **conditionally required** field.

Expand Down Expand Up @@ -68,8 +68,8 @@ The following conditions are all covered by this validator:
`current_range_meters`

- **conditions that are not covered by this validator**
`num_docks_available` in station_status.json`: because it depends on something that isn't defined in the GBFS files: the docking capacity. See the official GBFS spec about this field [here](https://github.com/NABSA/gbfs/blob/master/gbfs.md#station_statusjson).\
`vehicle_docks_available` in station_status.json`: because it depends on something that isn't defined in the GBFS files: *REQUIRED in feeds where [...] certain docks are only able to accept certain vehicle types.* See the official GBFS spec about this field [here](https://github.com/NABSA/gbfs/blob/master/gbfs.md#station_statusjson).\
`num_docks_available` in station_status.json`: because it depends on something that isn't defined in the GBFS files: the docking capacity. See the official GBFS spec about this field [here](https://github.com/MobilityData/gbfs/blob/master/gbfs.md#station_statusjson).\
`vehicle_docks_available` in station_status.json`: because it depends on something that isn't defined in the GBFS files: *REQUIRED in feeds where [...] certain docks are only able to accept certain vehicle types.* See the official GBFS spec about this field [here](https://github.com/MobilityData/gbfs/blob/master/gbfs.md#station_statusjson).\
`system_id` in `free_bike_status.json`

## Field types
Expand Down
2 changes: 1 addition & 1 deletion check-systems/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# check-systems

Download systems.csv from https://github.com/NABSA/gbfs
Download systems.csv from https://github.com/MobilityData/gbfs

`node check-systems/index.js systems.csv`
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fastify = require('fastify')

const version = '3.0-RC'
const last_updated = 1566224400
const last_updated_fresh = Math.floor(Date.now() / 1000) - 30
const version = '3.0-RC2'
const last_updated = '2019-08-19T10:20:00-04:00'
const last_updated_fresh = new Date().toISOString()

class MockRequests {
entry_points() {
Expand All @@ -12,7 +12,8 @@ class MockRequests {
gbfs_versions: this.gbfs_versions,
system_information: this.system_information,
vehicle_types: this.vehicle_types,
station_status: this.station_status
station_status: this.station_status,
vehicle_status: this.vehicle_status
}
}

Expand All @@ -27,7 +28,7 @@ class MockRequests {
system_id: 'example_berlin',
versions: [
{
version: '3.0-RC',
version: '3.0-RC2',
url: `${basePath}/gbfs.json`
}
]
Expand Down Expand Up @@ -69,7 +70,7 @@ class MockRequests {
data: {
versions: [
{
version: '3.0-RC',
version: '3.0-RC2',
url: `${basePath}/gbfs.json`
}
]
Expand Down Expand Up @@ -161,7 +162,7 @@ class MockRequests {
vehicles: [
{
vehicle_id: 'bike1',
last_reported: 1609866109,
last_reported: last_updated,
lat: 12.345678,
lon: 56.789012,
is_reserved: false,
Expand All @@ -170,7 +171,7 @@ class MockRequests {
},
{
vehicle_id: 'car1',
last_reported: 1609866109,
last_reported: last_updated,
lat: 12.345678,
lon: 56.789012,
is_reserved: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fastify = require('fastify')

const version = '3.0-RC'
const last_updated = 1566224400
const version = '3.0-RC2'
const last_updated = '2019-08-19T10:20:00-04:00'

const last_updated_fresh = Math.floor(Date.now() / 1000) - 30
const last_updated_fresh = new Date().toISOString()

class MockRequests {
entry_points() {
Expand Down Expand Up @@ -34,7 +34,7 @@ class MockRequests {
system_id: 'example_berlin',
versions: [
{
version: '3.0-RC',
version: '3.0-RC2',
url: `${basePath}/gbfs.json`
}
]
Expand Down Expand Up @@ -104,7 +104,7 @@ class MockRequests {
data: {
versions: [
{
version: '3.0-RC',
version: '3.0-RC2',
url: `${basePath}/gbfs.json`
}
]
Expand Down Expand Up @@ -227,7 +227,7 @@ class MockRequests {
cargo_volume_capacity: 50,
cargo_load_capacity: 100,
propulsion_type: 'electric',
eco_label: [
eco_labels: [
{
country_code: 'FR',
eco_sticker: 'critair_1'
Expand Down Expand Up @@ -330,23 +330,23 @@ class MockRequests {
parking_hoop: false,
contact_phone: '+33109874321',
capacity: 10,
vehicle_type_area_capacity: [
vehicle_types_capacity: [
{
vehicle_type_id: 'abc123',
vehicle_type_ids: ['abc123'],
count: 7
},
{
vehicle_type_id: 'def456',
vehicle_type_ids: ['def456'],
count: 3
}
],
vehicle_type_dock_capacity: [
vehicle_docks_capacity: [
{
vehicle_type_id: 'abc123',
vehicle_type_ids: ['abc123'],
count: 7
},
{
vehicle_type_id: 'def456',
vehicle_type_ids: ['def456'],
count: 3
}
],
Expand Down Expand Up @@ -376,7 +376,7 @@ class MockRequests {
is_installed: true,
is_renting: true,
is_returning: true,
last_reported: 1609866125,
last_reported: last_updated,
num_docks_available: 3,
num_docks_disabled: 1,
vehicle_docks_available: [
Expand Down Expand Up @@ -407,7 +407,7 @@ class MockRequests {
is_installed: true,
is_renting: true,
is_returning: true,
last_reported: 1609866106,
last_reported: last_updated,
num_docks_available: 8,
num_docks_disabled: 1,
vehicle_docks_available: [
Expand Down Expand Up @@ -459,7 +459,7 @@ class MockRequests {
web: 'https://www.example.com/app?sid=1234567890'
},
vehicle_type_id: 'biketype1',
last_reported: 1609866109
last_reported: last_updated
},
{
vehicle_id: 'car1',
Expand All @@ -468,7 +468,7 @@ class MockRequests {
is_reserved: false,
is_disabled: false,
vehicle_type_id: 'cartype1',
last_reported: 1609866109,
last_reported: last_updated,
current_range_meters: 10000,
current_fuel_percent: 0.5,
station_id: 'station1',
Expand Down Expand Up @@ -627,8 +627,8 @@ class MockRequests {
type: 'station_closure',
times: [
{
start: 1604448000,
end: 1604674800
start: last_updated,
end: last_updated_fresh
}
],
station_ids: ['123', '456', '789'],
Expand Down Expand Up @@ -658,7 +658,7 @@ class MockRequests {
language: 'en'
}
],
last_updated: 1604198100
last_updated
}
]
}
Expand Down Expand Up @@ -706,11 +706,11 @@ class MockRequests {
language: 'en'
}
],
start: 1593878400,
end: 1593907260,
start: last_updated,
end: last_updated_fresh,
rules: [
{
vehicle_type_id: ['moped1', 'car1'],
vehicle_type_ids: ['moped1', 'car1'],
ride_start_allowed: false,
ride_end_allowed: false,
ride_through_allowed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('default feed', () => {
let gbfsFeedServer

beforeAll(async () => {
const { MockRequests } = require('./fixtures/v3.0-RC/default')
const { MockRequests } = require('./fixtures/v3.0-RC2/default')
let mockRequests = new MockRequests()

gbfsFeedServer = mockRequests.build()
Expand All @@ -50,7 +50,7 @@ describe('default feed', () => {
return gbfs.validation().then(result => {
expect(result).toMatchObject({
summary: expect.objectContaining({
version: { detected: '3.0-RC', validated: '3.0-RC' },
version: { detected: '3.0-RC2', validated: '3.0-RC2' },
validatorVersion: '1.0.0',
hasErrors: false
}),
Expand All @@ -64,7 +64,7 @@ describe('invalid feed', () => {
let gbfsFeedServer

beforeAll(async () => {
const { MockRequests } = require('./fixtures/v3.0-RC/default')
const { MockRequests } = require('./fixtures/v3.0-RC2/default')
class InvalidMockRequests extends MockRequests {
system_information(...args) {
const json = super.system_information(...args)
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('invalid feed', () => {
return gbfs.validation().then(result => {
expect(result).toMatchObject({
summary: expect.objectContaining({
version: { detected: '3.0-RC', validated: '3.0-RC' },
version: { detected: '3.0-RC2', validated: '3.0-RC2' },
validatorVersion: '1.0.0',
hasErrors: true,
errorsCount: 1
Expand All @@ -116,7 +116,7 @@ describe('exaustive feed', () => {
let gbfsFeedServer

beforeAll(async () => {
const { MockRequests } = require('./fixtures/v3.0-RC/exaustive')
const { MockRequests } = require('./fixtures/v3.0-RC2/exaustive')

let mockRequests = new MockRequests()

Expand All @@ -142,7 +142,7 @@ describe('exaustive feed', () => {

expect(result).toMatchObject({
summary: expect.objectContaining({
version: { detected: '3.0-RC', validated: '3.0-RC' },
version: { detected: '3.0-RC2', validated: '3.0-RC2' },
validatorVersion: '1.0.0',
hasErrors: false
}),
Expand Down
8 changes: 7 additions & 1 deletion gbfs-validator/gbfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,13 @@ class GBFS {
const body = await got.get(manifestUrl, this.gotOptions).json()

files.push({
body,
body: [
{
body,
exists: true,
url: manifestUrl
}
],
required: true,
type: 'manifest'
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = ({ vehicleTypes }) => {
const res = {
const partial = {
$id: 'required_vehicle_type_id.json#'
}

Expand All @@ -8,10 +8,10 @@ module.exports = ({ vehicleTypes }) => {
)

if (motorVehicleTypes.length) {
res.$merge = {
partial.$merge = {
source: {
$ref:
'https://github.com/NABSA/gbfs/blob/v2.1/gbfs.md#free_bike_statusjson'
'https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#free_bike_statusjson'
},
with: {
properties: {
Expand Down Expand Up @@ -46,10 +46,10 @@ module.exports = ({ vehicleTypes }) => {
}
}

res.$patch = {
partial.$patch = {
source: {
$ref:
'https://github.com/NABSA/gbfs/blob/v2.1/gbfs.md#free_bike_statusjson'
'https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#free_bike_statusjson'
},
with: [
{
Expand All @@ -60,5 +60,5 @@ module.exports = ({ vehicleTypes }) => {
]
}

return res
return partial
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = ({ vehicleTypes }) => {
$merge: {
source: {
$ref:
'https://github.com/NABSA/gbfs/blob/v2.1/gbfs.md#station_statusjson'
'https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#station_statusjson'
},
with: {
properties: {
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = ({ vehicleTypes }) => {
$patch: {
source: {
$ref:
'https://github.com/NABSA/gbfs/blob/v2.1/gbfs.md#station_statusjson'
'https://github.com/MobilityData/gbfs/blob/v2.1/gbfs.md#station_statusjson'
},
with: [
{
Expand Down
Loading

0 comments on commit 50f351e

Please sign in to comment.