def vehicle_telemetry(): telemetry = common.load_definitions("telemetry") vehicle_telemetry = common.load_definitions("vehicle_telemetry") # merge the standard telemetry props into vehicle_telemetry.gps vehicle_telemetry["properties"]["gps"]["properties"].update( telemetry["properties"]) return vehicle_telemetry
def geography_schema(): """ Create the schema for the Geography endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/geography/geography.json") definitions = common.load_definitions("string", "timestamp", "uuid", "version") definitions.update( common.load_definitions("timestamp", "uuid_array", allow_null=True)) schema["definitions"].update(definitions) # verify and return return common.check_schema(schema)
def trips_schema(): """ Create the schema for the /trips endpoint. """ # generate the route definition mds_feature_collection_route = feature_collection_schema( id=common.definition_id("MDS_FeatureCollection_Route"), title="MDS GeoJSON FeatureCollection Route", # 1. Only allow MDS Feature Points # 2. There must be *at least* two Features in the FeatureCollection. features={ "items": { "$ref": common.definition_id("MDS_Feature_Point") }, "minItems": 2 }) trips_definitions = { "currency": common.load_definitions("currency"), "MDS_FeatureCollection_Route": mds_feature_collection_route } # create the trips schema schema = endpoint_schema("trips", trips_definitions) # verify and return return common.check_schema(schema)
def get_vehicle_schema(): """ Create the schema for the Agency GET /vehicles endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/agency/get_vehicle.json") definitions = common.load_definitions( "propulsion_types", "string", "timestamp", "vehicle_type", "uuid" ) schema["definitions"].update(definitions) # merge the state machine definitions and transition combinations rule state_machine_defs, transitions = common.vehicle_state_machine("state", "prev_events") schema["definitions"].update(state_machine_defs) schema["allOf"].append(transitions) # merge common vehicle information, with Agency tweaks vehicle = common.vehicle_definition(provider_name=False) schema["required"] = vehicle["required"] + schema["required"] schema["properties"] = { **vehicle["properties"], **schema["properties"] } # verify and return return common.check_schema(schema)
def post_vehicle_telemetry_schema(): """ Create the schema for the Agency POST /vehicles/telemetry endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/agency/post_vehicle_telemetry.json") definitions = common.load_definitions("timestamp", "uuid") definitions["vehicle_telemetry"] = vehicle_telemetry() schema["definitions"].update(definitions) # verify and return return common.check_schema(schema)
def post_vehicle_event_schema(): """ Create the schema for the Agency POST /vehicles/:id/event endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/agency/post_vehicle_event.json") definitions = common.load_definitions("timestamp", "uuid") definitions["vehicle_telemetry"] = vehicle_telemetry() schema["definitions"].update(definitions) # merge the state machine definitions and transition combinations rule state_machine_defs, transitions = common.vehicle_state_machine( "vehicle_state", "event_types") schema["definitions"].update(state_machine_defs) schema["allOf"].append(transitions) # add the conditionally-required trip_id rule trip_id_ref = common.load_definitions("trip_id_reference") schema["allOf"].append(trip_id_ref) # verify and return return common.check_schema(schema)
def policy_schema(): """ Create the schema for the Policy endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/policy/policy.json") definitions = common.load_definitions("currency", "day", "propulsion_type", "string", "timestamp", "uuid", "uuid_array", "vehicle_event", "vehicle_state", "vehicle_type", "version") definitions.update( common.load_definitions("days", "iso_time", "propulsion_types", "timestamp", "uuid_array", "vehicle_types", allow_null=True)) schema["definitions"].update(definitions) # verify and return return common.check_schema(schema)
def endpoint_schema(endpoint, extra_definitions={}): """ Generate the Provider payload schema for the given endpoint. """ # load common schema template and update metadata schema = common.load_json("./templates/provider/endpoint.json") schema["$id"] = schema["$id"].replace("endpoint.json", f"{endpoint}.json") schema["title"] = schema["title"].replace("endpoint", endpoint) # merge custom definitions with relevant common definitions definitions = common.load_definitions("string", "timestamp", "uuid", "version") definitions.update(common.point_definition()) definitions.update(common.mds_feature_point_definition()) definitions.update(extra_definitions) endpoint_schema = common.load_json(f"./templates/provider/{endpoint}.json") # for all but stops, merge standard vehicle info with items schema if endpoint not in ["stops"]: items = endpoint_schema[endpoint]["items"] vehicle = common.vehicle_definition() items["required"] = vehicle["required"] + items["required"] items["properties"] = {**vehicle["properties"], **items["properties"]} definitions.update( common.load_definitions("propulsion_type", "propulsion_types", "vehicle_type")) # merge endpoint schema into the endpoint template data_schema = schema["properties"]["data"] data_schema["required"] = [endpoint] data_schema["properties"] = endpoint_schema # insert definitions schema["definitions"].update(definitions) return schema
def post_vehicle_schema(): """ Create the schema for the Agency POST /vehicles endpoint. """ # load schema template and insert definitions schema = common.load_json("./templates/agency/post_vehicle.json") definitions = common.load_definitions("propulsion_types", "string", "vehicle_type", "uuid") schema["definitions"].update(definitions) # merge common vehicle information, with Agency tweaks vehicle = common.vehicle_definition(provider_name=False, provider_id=False) schema["required"] = vehicle["required"] + schema["required"] schema["properties"] = {**vehicle["properties"], **schema["properties"]} # verify and return return common.check_schema(schema)
def status_changes_schema(): """ Create the schema for the /status_changes endpoint. """ schema = endpoint_schema("status_changes") items = schema["properties"]["data"]["properties"]["status_changes"][ "items"] # merge the state machine definitions and transition combinations rule state_machine_defs, transitions = common.vehicle_state_machine( "vehicle_state", "event_types") schema["definitions"].update(state_machine_defs) items["allOf"].append(transitions) trip_id_ref = common.load_definitions("trip_id_reference") items["allOf"].append(trip_id_ref) # verify and return return common.check_schema(schema)