Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions sdk/src/assertions/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
// specific language governing permissions and limitations under
// each license.

use std::collections::HashMap;

use chrono::{SecondsFormat, Utc};
#[cfg(feature = "json_schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::{
assertion::{Assertion, AssertionBase, AssertionCbor},
Expand All @@ -43,8 +40,6 @@ pub struct Metadata {
data_source: Option<DataSource>,
#[serde(rename = "regionOfInterest", skip_serializing_if = "Option::is_none")]
region_of_interest: Option<RegionOfInterest>,
#[serde(flatten)]
other: HashMap<String, Value>,
}

impl Metadata {
Expand All @@ -62,7 +57,6 @@ impl Metadata {
reference: None,
data_source: None,
region_of_interest: None,
other: HashMap::new(),
}
}

Expand All @@ -86,11 +80,6 @@ impl Metadata {
self.region_of_interest.as_ref()
}

/// Returns map containing custom metadata fields.
pub fn other(&self) -> &HashMap<String, Value> {
&self.other
}

/// Adds a [`ReviewRating`] associated with the assertion.
pub fn add_review(mut self, review: ReviewRating) -> Self {
match &mut self.reviews {
Expand Down Expand Up @@ -132,17 +121,6 @@ impl Metadata {
self.region_of_interest = Some(region_of_interest);
self
}

/// Adds an additional key / value pair.
pub fn insert(&mut self, key: &str, value: Value) -> &mut Self {
self.other.insert(key.to_string(), value);
self
}

/// Gets additional values by key.
pub fn get(&self, key: &str) -> Option<&Value> {
self.other.get(key)
}
}

impl Default for Metadata {
Expand Down Expand Up @@ -334,8 +312,7 @@ pub mod tests {
#[test]
fn assertion_metadata() {
let review = ReviewRating::new("foo", Some("bar".to_owned()), 3);
let test_value = Value::from("test");
let mut original =
let original =
Metadata::new()
.add_review(review)
.set_region_of_interest(RegionOfInterest {
Expand All @@ -350,7 +327,6 @@ pub mod tests {
}],
..Default::default()
});
original.insert("foo", test_value);
println!("{:}", &original);
let assertion = original.to_assertion().expect("build_assertion");
assert_eq!(assertion.mime_type(), "application/cbor");
Expand All @@ -359,7 +335,6 @@ pub mod tests {
println!("{:?}", serde_json::to_string(&result));
assert_eq!(original.date_time, result.date_time);
assert_eq!(original.reviews, result.reviews);
assert_eq!(original.get("foo").unwrap(), "test");
assert_eq!(
original.region_of_interest.as_ref(),
result.region_of_interest()
Expand Down
13 changes: 1 addition & 12 deletions sdk/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,7 @@ mod tests {
],
"metadata": [
{
"dateTime": "1985-04-12T23:20:50.52Z",
"my_custom_metadata": "my custom metatdata value"
"dateTime": "1985-04-12T23:20:50.52Z"
}
],
"title": "Test_Manifest",
Expand Down Expand Up @@ -1412,16 +1411,6 @@ mod tests {
"org.test.assertion".to_string()
);

assert_eq!(
definition.metadata.as_ref().unwrap()[0]
.other()
.get("my_custom_metadata")
.unwrap()
.as_str()
.unwrap(),
"mycustommetatdatavalue"
);

// convert back to json and compare to original
let builder_json = serde_json::to_string(&builder.definition).unwrap();
assert_eq!(builder_json, stripped_json);
Expand Down
Loading