Skip to content

Commit 843c0d1

Browse files
committed
Add null checks in rules
1 parent 53f046e commit 843c0d1

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Existing rules:
3838
Planned rules:
3939

4040
* Either station_information or station_status is required if the other is present
41-
* vehicle_types is required vehicle types are referenced in other files
41+
* Can this be checked by cross-checking ids between files - using schema patching?
42+
* vehicle_types is required if vehicle types are referenced in other files (already covered?)
4243
* system_pricing_plans is required if pricing plans are referenced in other files
4344

src/main/java/org/entur/gbfs/validation/validator/rules/VehicleTypeDefaultPricingPlanIdExistsInSystemPricingPlans.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public class VehicleTypeDefaultPricingPlanIdExistsInSystemPricingPlans implement
4040
@Override
4141
public DocumentContext addRule(DocumentContext rawSchemaDocumentContext, Map<String, JSONObject> feeds) {
4242
JSONObject pricingPlansFeed = feeds.get("system_pricing_plans");
43-
JSONArray pricingPlanIds = JsonPath.parse(pricingPlansFeed).read("$.data.plans[*].plan_id");
4443
JSONObject defaultPricingPlanIdSchema = rawSchemaDocumentContext.read(DEFAULT_PRICING_PLAN_ID_SCHEMA_PATH);
45-
defaultPricingPlanIdSchema.put("enum", pricingPlanIds);
44+
45+
if (pricingPlansFeed != null) {
46+
JSONArray pricingPlanIds = JsonPath.parse(pricingPlansFeed).read("$.data.plans[*].plan_id");
47+
defaultPricingPlanIdSchema.put("enum", pricingPlanIds);
48+
}
49+
4650
return rawSchemaDocumentContext.set(DEFAULT_PRICING_PLAN_ID_SCHEMA_PATH, defaultPricingPlanIdSchema);
4751
}
4852
}

src/main/java/org/entur/gbfs/validation/validator/rules/VehicleTypeIdsInVehicleTypesAvailableExistsInVehicleTypes.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public class VehicleTypeIdsInVehicleTypesAvailableExistsInVehicleTypes implement
4040
@Override
4141
public DocumentContext addRule(DocumentContext rawSchemaDocumentContext, Map<String, JSONObject> feeds) {
4242
JSONObject vehicleTypesFeed = feeds.get("vehicle_types");
43-
JSONArray vehicleTypeIds = JsonPath.parse(vehicleTypesFeed).read("$.data.vehicle_types[*].vehicle_type_id");
4443
JSONObject vehicleTypeIdSchema = rawSchemaDocumentContext.read(VEHICLE_TYPE_ID_SCHEMA_PATH);
45-
vehicleTypeIdSchema.put("enum", vehicleTypeIds);
44+
45+
if (vehicleTypesFeed != null) {
46+
JSONArray vehicleTypeIds = JsonPath.parse(vehicleTypesFeed).read("$.data.vehicle_types[*].vehicle_type_id");
47+
vehicleTypeIdSchema.put("enum", vehicleTypeIds);
48+
}
49+
4650
return rawSchemaDocumentContext.set(VEHICLE_TYPE_ID_SCHEMA_PATH, vehicleTypeIdSchema);
4751
}
4852
}

0 commit comments

Comments
 (0)