stac_api/
conformance.rs

1use serde::{Deserialize, Serialize};
2
3/// The core conformance uri.
4pub const CORE_URI: &str = "https://api.stacspec.org/v1.0.0/core";
5
6/// The features conformance uri.
7pub const FEATURES_URI: &str = "https://api.stacspec.org/v1.0.0/ogcapi-features";
8
9/// The collections conformance uri.
10pub const COLLECTIONS_URI: &str = "https://api.stacspec.org/v1.0.0/collections";
11
12/// The OGC API - Features - Part 1 Requirements Class Core uri
13pub const OGC_API_FEATURES_URI: &str =
14    "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core";
15
16/// The GeoJSON spec conformance uri.
17pub const GEOJSON_URI: &str = "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson";
18
19/// The item search conformance uri.
20pub const ITEM_SEARCH_URI: &str = "https://api.stacspec.org/v1.0.0/item-search";
21
22/// The filter conformance uris.
23pub const FILTER_URIS: [&str; 5] = [
24    "http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/filter",
25    "http://www.opengis.net/spec/cql2/1.0/conf/basic-cql2",
26    "https://api.stacspec.org/v1.0.0-rc.3/item-search#filter",
27    "http://www.opengis.net/spec/cql2/1.0/conf/cql2-text",
28    "http://www.opengis.net/spec/cql2/1.0/conf/cql2-json",
29];
30
31/// To support "generic" clients that want to access multiple OGC API Features
32/// implementations - and not "just" a specific API / server, the server has to
33/// declare the conformance classes it implements and conforms to.
34#[derive(Debug, Serialize, Deserialize)]
35pub struct Conformance {
36    /// The conformance classes it implements and conforms to.
37    #[serde(rename = "conformsTo")]
38    pub conforms_to: Vec<String>,
39}
40
41impl Conformance {
42    /// Creates a new conformance structure with only the core conformance class.
43    ///
44    /// # Examples
45    ///
46    /// ```
47    /// use stac_api::Conformance;
48    /// let conformance = Conformance::new();
49    /// ```
50    pub fn new() -> Conformance {
51        Conformance {
52            conforms_to: vec![CORE_URI.to_string()],
53        }
54    }
55
56    /// Adds
57    /// [ogcapi-features](https://github.com/radiantearth/stac-api-spec/tree/release/v1.0.0/ogcapi-features)
58    /// conformance classes.
59    ///
60    /// # Examples
61    ///
62    /// ```
63    /// use stac_api::Conformance;
64    /// let conformance = Conformance::new().ogcapi_features();
65    /// ```
66    pub fn ogcapi_features(mut self) -> Conformance {
67        self.conforms_to.push(FEATURES_URI.to_string());
68        self.conforms_to.push(COLLECTIONS_URI.to_string());
69        self.conforms_to.push(OGC_API_FEATURES_URI.to_string());
70        self.conforms_to.push(GEOJSON_URI.to_string());
71        self
72    }
73
74    /// Adds
75    /// [item search](https://github.com/radiantearth/stac-api-spec/tree/release/v1.0.0/item-search)
76    /// conformance class.
77    ///
78    /// # Examples
79    ///
80    /// ```
81    /// use stac_api::Conformance;
82    /// let conformance = Conformance::new().item_search();
83    /// ```
84    pub fn item_search(mut self) -> Conformance {
85        self.conforms_to.push(ITEM_SEARCH_URI.to_string());
86        self
87    }
88
89    /// Adds [filter](https://github.com/stac-api-extensions/filter) conformance
90    /// class.
91    ///
92    /// # Examples
93    ///
94    /// ```
95    /// use stac_api::Conformance;
96    /// let conformance = Conformance::new().item_search();
97    /// ```
98    pub fn filter(mut self) -> Conformance {
99        self.conforms_to
100            .extend(FILTER_URIS.iter().map(|s| s.to_string()));
101        self
102    }
103}
104
105impl Default for Conformance {
106    fn default() -> Self {
107        Self::new()
108    }
109}