From af4d5d6a2258d131206e877158b616e3886fe5d9 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 10 Sep 2022 06:18:30 +0200 Subject: [PATCH] fixup! feat: implement first crate version --- src/models/property.rs | 3 +++ src/models/thing_description.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/models/property.rs b/src/models/property.rs index 1602cc8..db1343d 100644 --- a/src/models/property.rs +++ b/src/models/property.rs @@ -30,6 +30,9 @@ impl<'a> Serialize for Property<'a> { if data_schema.title.is_some() { map.serialize_entry("title", data_schema.title.unwrap())?; } + if data_schema.data_type.is_some() { + map.serialize_entry("type", &data_schema.data_type)?; + } map.end() } diff --git a/src/models/thing_description.rs b/src/models/thing_description.rs index d7d01a9..902698f 100644 --- a/src/models/thing_description.rs +++ b/src/models/thing_description.rs @@ -152,7 +152,10 @@ mod tests { use crate::{ data_structures::{array::ArrayEntry, map::MapEntry}, models::{ - action::Action, data_schema::DataSchema, link::Link, property::Property, + action::Action, + data_schema::{DataSchema, DataType}, + link::Link, + property::Property, thing_description::ThingDescriptionBuilder, }, }; @@ -215,7 +218,7 @@ mod tests { read_only: None, write_only: None, format: None, - data_type: None, + data_type: Some(DataType::Boolean), }, }, ); @@ -231,7 +234,7 @@ mod tests { .links(links) .build(); - let expected_result = r#"{"@context":"https://www.w3.org/2022/wot/td/v1.1","@type":["saref:LightSwitch"],"title":"Test TD","properties":{"status":{"title":"Status"}},"actions":{"toggle":{"input":{"title":"Toggle Data"}},"toggle2":{}},"links":[{"href":"https://example.org"}]}"#; + let expected_result = r#"{"@context":"https://www.w3.org/2022/wot/td/v1.1","@type":["saref:LightSwitch"],"title":"Test TD","properties":{"status":{"title":"Status","type":"boolean"}},"actions":{"toggle":{"input":{"title":"Toggle Data"}},"toggle2":{}},"links":[{"href":"https://example.org"}]}"#; let actual_result: String<300> = to_string(&thing_description)?; assert_eq!(expected_result, actual_result.as_str());