Skip to content

Commit 174e9b4

Browse files
committed
Allow integer for feature id
1 parent b68d523 commit 174e9b4

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
- Make features opt-out rather than opt-in for released standards
15+
- Allow integers for feature id.
1516

1617
### Added
1718

ogcapi-client/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ mod tests {
489489
.with_collections(["ch.swisstopo.swissalti3d"]);
490490
let mut items = client.search(params).unwrap();
491491
let item = items.next().unwrap().unwrap();
492-
assert_eq!(Some("swissalti3d_2019_2600-1199".to_string()), item.id);
492+
assert_eq!("swissalti3d_2019_2600-1199", item.id.unwrap().to_string());
493493
assert_eq!(
494494
Some("ch.swisstopo.swissalti3d".to_string()),
495495
item.collection

ogcapi-services/src/routes/features.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ogcapi_types::{
1515
link_rel::{COLLECTION, NEXT, PREV, ROOT, SELF},
1616
media_type::{GEO_JSON, JSON},
1717
},
18-
features::{Feature, FeatureCollection, Query},
18+
features::{Feature, FeatureId, FeatureCollection, Query},
1919
};
2020

2121
use crate::{
@@ -95,7 +95,11 @@ async fn update(
9595
Path((collection_id, id)): Path<(String, String)>,
9696
Json(mut feature): Json<Feature>,
9797
) -> Result<StatusCode> {
98-
feature.id = Some(id);
98+
match feature.id {
99+
Some(ref fid) => assert_eq!(id, fid.to_string()),
100+
None => feature.id = Some(FeatureId::String(id)),
101+
}
102+
99103
feature.collection = Some(collection_id);
100104

101105
state.drivers.features.update_feature(&feature).await?;

ogcapi-types/src/features/feature.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(feature = "stac")]
22
use std::collections::HashMap;
3+
use std::fmt::Display;
34

45
#[cfg(feature = "stac")]
56
use crate::common::Bbox;
@@ -15,11 +16,28 @@ pub enum Type {
1516
Feature,
1617
}
1718

19+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
20+
#[serde(untagged)]
21+
pub enum FeatureId {
22+
String(String),
23+
Integer(isize),
24+
}
25+
26+
impl Display for FeatureId {
27+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
match self {
29+
FeatureId::String(s) => f.write_str(s),
30+
FeatureId::Integer(i) => f.write_fmt(format_args!("{i}")),
31+
}
32+
}
33+
}
34+
1835
/// Abstraction of real world phenomena (ISO 19101-1:2014)
1936
#[serde_with::skip_serializing_none]
2037
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
2138
pub struct Feature {
22-
pub id: Option<String>,
39+
#[serde(default)]
40+
pub id: Option<FeatureId>,
2341
pub collection: Option<String>,
2442
#[serde(default)]
2543
pub r#type: Type,
@@ -42,6 +60,7 @@ pub struct Feature {
4260
pub assets: HashMap<String, crate::stac::Asset>,
4361
/// Bounding Box of the asset represented by this Item, formatted according to RFC 7946, section 5.
4462
#[cfg(feature = "stac")]
63+
#[serde(default)]
4564
pub bbox: Option<Bbox>,
4665
}
4766

ogcapi-types/src/features/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod feature;
22
mod feature_collection;
33
mod query;
44

5-
pub use feature::Feature;
5+
pub use feature::{Feature, FeatureId};
66
pub use feature_collection::FeatureCollection;
77
pub use query::Query;
88

0 commit comments

Comments
 (0)