gbfs-validator icon indicating copy to clipboard operation
gbfs-validator copied to clipboard

Conditional requirements validation

Open richfab opened this issue 2 years ago • 0 comments

What is the issue and why is it an issue?

Currently, the validator cannot validate conditional requirements that apply based on a field from a different file. This can lead to errors in the feeds that cannot be identified or fixed by the producer.

This type of validation was proposed in https://github.com/MobilityData/gbfs-validator/pull/106 using imperative rules (in JavaScript). However, using schemas and patched schemas instead, would have the benefit of having the validation done by ajv and all the results as an output of ajv.

Example of conditional requirements based on a field from a different file in the GBFS spec:

default_reserve_time [in vehicle_types.json] | REQUIRED if reservation_price_per_min or reservation_price_flat_rate are defined [in system_pricing_plans.json]

image

Please describe some potential solutions you have considered (even if they aren’t related to GBFS).

Conditional requirements based on a field from a different file could be validated using JSON Schema patching #Required Properties.

As noted in https://github.com/MobilityData/gbfs-validator/issues/153#issuecomment-1806145023, a solution to reduce schema patching complexity could be to generate new schemas via a builder or a template instead of patching the main schemas.

Fields with conditional requirements based on a different file
- system_information.json#manifest_url (if manifest.json exists)
- system_information.json#rental_apps.android.store_uri (already done with "partial" schemas)
- system_information.json#rental_apps.android.discovery_uri
- system_information.json#rental_apps.ios.store_uri
- system_information.json#rental_apps.ios.discovery_uri
- vehicle_types.json#vehicle_types.default_reserve_time
- vehicle_types.json#vehicle_types.default_pricing_plan_id (already done with "partial" schemas)
- station_status.json#stations.vehicle_types_available (already done with "partial" schemas)
- station_status.json#stations.num_docks_available
- station_status.json#stations.vehicle_docks_available
- vehicle_status.json#vehicles.vehicle_type_id (already done with "partial" schemas)
- vehicle_status.json#vehicles.current_range_meters

richfab avatar Nov 13 '23 15:11 richfab