Skip to main content

ogcapi_types/common/
collection.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Map, Value};
3use serde_with::DisplayFromStr;
4
5use crate::common::{Crs, Extent, Links};
6
7// const CRS_REF: &str = "#/crs";
8
9/// A body of resources that belong or are used together. An aggregate, set, or group of related resources.
10#[serde_with::serde_as]
11#[serde_with::skip_serializing_none]
12#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
13#[serde(rename_all = "camelCase")]
14pub struct Collection {
15    /// Must be set to `Collection` to be a valid Collection.
16    #[cfg(feature = "stac")]
17    #[serde(default = "collection")]
18    pub r#type: String,
19    pub id: String,
20    pub title: Option<String>,
21    pub description: Option<String>,
22    #[serde(default, skip_serializing_if = "Vec::is_empty")]
23    pub keywords: Vec<String>,
24    /// Attribution for the collection.
25    pub attribution: Option<String>,
26    pub extent: Option<Extent>,
27    /// An indicator about the type of the items in the collection.
28    pub item_type: Option<String>,
29    /// The list of coordinate reference systems supported by the API; the first item is the default coordinate reference system.
30    #[serde(default)]
31    #[serde_as(as = "Vec<DisplayFromStr>")]
32    pub crs: Vec<Crs>,
33    #[serde(default)]
34    #[serde_as(as = "Option<DisplayFromStr>")]
35    pub storage_crs: Option<Crs>,
36    pub storage_crs_coordinate_epoch: Option<f32>,
37    #[serde(default)]
38    pub links: Links,
39    /// Detailed information relevant to individual query types
40    #[cfg(feature = "edr")]
41    #[serde(rename = "data_queries")]
42    pub data_queries: Option<crate::edr::DataQueries>,
43    /// List of formats the results can be presented in
44    #[cfg(feature = "edr")]
45    #[serde(
46        default,
47        rename = "output_formats",
48        skip_serializing_if = "Vec::is_empty"
49    )]
50    pub output_formats: Vec<String>,
51    /// List of the data parameters available in the collection
52    #[cfg(feature = "edr")]
53    #[serde(
54        default,
55        rename = "parameter_names",
56        skip_serializing_if = "std::collections::HashMap::is_empty"
57    )]
58    pub parameter_names: std::collections::HashMap<String, crate::edr::ParameterNames>,
59    /// The STAC version the Collection implements.
60    #[cfg(feature = "stac")]
61    #[serde(default = "crate::stac::stac_version", rename = "stac_version")]
62    pub stac_version: String,
63    // /// A list of extension identifiers the Collection implements.
64    #[cfg(feature = "stac")]
65    #[serde(
66        default,
67        rename = "stac_extensions",
68        skip_serializing_if = "Vec::is_empty"
69    )]
70    pub stac_extensions: Vec<String>,
71    /// Collection's license(s), either a SPDX License identifier, `various` if
72    /// multiple licenses apply or `proprietary` for all other cases.
73    #[cfg(feature = "stac")]
74    pub license: String,
75    /// A list of providers, which may include all organizations capturing or processing the data or the hosting provider.
76    #[cfg(feature = "stac")]
77    #[serde(default, skip_serializing_if = "Vec::is_empty")]
78    pub providers: Vec<crate::stac::Provider>,
79    /// A map of property summaries, either a set of values, a range of values or a JSON Schema.
80    #[cfg(feature = "stac")]
81    #[serde(default, skip_serializing_if = "Map::is_empty")]
82    pub summaries: Map<String, Value>,
83    /// Dictionary of asset objects that can be downloaded, each with a unique key.
84    #[cfg(feature = "stac")]
85    #[serde(default, skip_serializing_if = "std::collections::HashMap::is_empty")]
86    pub assets: std::collections::HashMap<String, crate::stac::Asset>,
87    #[serde(flatten, default, skip_serializing_if = "Map::is_empty")]
88    pub additional_properties: Map<String, Value>,
89}
90
91#[cfg(feature = "stac")]
92fn collection() -> String {
93    "Collection".to_string()
94}
95
96#[allow(clippy::derivable_impls)]
97impl Default for Collection {
98    fn default() -> Self {
99        Self {
100            #[cfg(feature = "stac")]
101            r#type: "Collection".to_string(),
102            id: Default::default(),
103            title: Default::default(),
104            description: Default::default(),
105            keywords: Default::default(),
106            attribution: Default::default(),
107            extent: Default::default(),
108            item_type: Default::default(),
109            crs: vec![Crs::default()],
110            storage_crs: Default::default(),
111            storage_crs_coordinate_epoch: Default::default(),
112            links: Default::default(),
113            #[cfg(feature = "edr")]
114            data_queries: Default::default(),
115            #[cfg(feature = "edr")]
116            output_formats: Default::default(),
117            #[cfg(feature = "edr")]
118            parameter_names: Default::default(),
119            #[cfg(feature = "stac")]
120            stac_version: crate::stac::stac_version(),
121            #[cfg(feature = "stac")]
122            stac_extensions: Default::default(),
123            #[cfg(feature = "stac")]
124            license: "various".to_string(),
125            #[cfg(feature = "stac")]
126            providers: Default::default(),
127            #[cfg(feature = "stac")]
128            summaries: Default::default(),
129            #[cfg(feature = "stac")]
130            assets: Default::default(),
131            additional_properties: Default::default(),
132        }
133    }
134}