def vehicles_schema(): """ Create the schema for the /vehicles endpoint. """ definitions, properties = {}, {} prop, defn = common.property_definition("links") definitions.update(defn) properties.update(prop) prop, _ = common.property_definition("last_updated", ref=common.definition_id("timestamp")) properties.update(prop) prop, defn = common.property_definition("ttl") definitions.update(defn) properties.update(prop) state_defs, transitions = common.vehicle_state_machine( "last_vehicle_state", "last_event_types") definitions.update(state_defs) schema = endpoint_schema("vehicles", definitions) # update list of required and properties object schema["required"].extend(["last_updated", "ttl"]) schema["properties"].update(properties) # add state machine transition rules schema["properties"]["data"]["properties"]["vehicles"]["items"][ "allOf"].append(transitions) # 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 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)
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)