valhalla_client/status.rs
1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashSet;
4
5#[serde_with::skip_serializing_none]
6#[derive(Serialize, Default, Debug)]
7pub struct Manifest {
8 verbose: Option<bool>,
9}
10impl Manifest {
11 pub fn builder() -> Self {
12 Default::default()
13 }
14
15 /// If set to `true` will add [`VerboseStatus`] to the output.
16 ///
17 /// **Note:**
18 /// Gathering this additional information can be computationally expensive.
19 /// Hence, the verbose flag can be disallowed in the configuration JSON.
20 /// See `service_limits.status.allow_verbose`, with default `false`.
21 ///
22 /// Default: `false`
23 pub fn verbose_output(mut self, verbose: bool) -> Self {
24 self.verbose = Some(verbose);
25 self
26 }
27}
28
29#[derive(Deserialize, Debug, Clone)]
30pub struct Response {
31 /// Current Valhalla version
32 ///
33 /// Example: `3.1.4`
34 pub version: semver::Version,
35 /// Time the tile_extract or tile_dir were last modified
36 #[serde(with = "chrono::serde::ts_seconds")]
37 pub tileset_last_modified: chrono::DateTime<chrono::Utc>,
38 /// Actions which are available to a consumer.
39 ///
40 /// Can be used in applications to enable/disable parts of the UI such as an elevation map.
41 /// Example: `["expansion","height","status","trace_attributes","trace_route","optimized_route","sources_to_targets","isochrone","route","locate"]`
42 pub available_actions: HashSet<String>,
43 /// Verbose information about the deployment
44 ///
45 /// Only included if
46 /// - requested via [`Manifest::verbose_output`] (default: `false`) and
47 /// - allowed via the configuration option `service_limits.status.allow_verbose` (default: `false`)
48 #[serde(flatten)]
49 pub verbose: Option<VerboseStatus>,
50}
51#[derive(Deserialize, Debug, Clone)]
52pub struct VerboseStatus {
53 /// Whether a valid tileset is currently loaded
54 pub has_tiles: bool,
55 /// Whether the current tileset was built using the admin database
56 pub has_admins: bool,
57 /// Whether the current tileset was built using the timezone database
58 pub has_timezones: bool,
59 /// Whether live traffic tiles are currently available
60 pub has_live_traffic: bool,
61 /// GeoJSON of the tileset extent
62 ///
63 /// This is likely humongous, be cautions
64 pub bbox: Value,
65 /// May contain warning objects informing about
66 /// - deprecated request parameters,
67 /// - clamped values
68 /// - etc.
69 #[serde(default = "Vec::new")]
70 pub warnings: Vec<Value>,
71}
72
73#[cfg(all(test, feature = "blocking"))]
74mod tests {
75 use super::*;
76 use crate::blocking::Valhalla;
77 #[test]
78 fn test_status_verbose() {
79 let request = Manifest::builder().verbose_output(true);
80 let response = Valhalla::default().status(request).unwrap();
81 assert!(response.version >= semver::Version::parse("3.1.4").unwrap());
82 assert!(response.tileset_last_modified.timestamp() > 0);
83 let verbose = response.verbose.unwrap();
84 assert!(verbose.bbox.is_object());
85 assert!(verbose.warnings.is_empty());
86 }
87}