From 00dd03ed3bc213f41722053e68d168bad7043375 Mon Sep 17 00:00:00 2001 From: generalvamp Date: Sat, 11 Apr 2026 14:12:06 -0400 Subject: [PATCH 1/2] fix: failure to deserialize native icon --- src/objects.rs | 1 + src/objects/native_icon.rs | 14 +++++ src/objects/page.rs | 5 +- src/objects/tests.rs | 16 ++++- src/objects/tests/native_icon.json | 7 +++ src/objects/tests/page_native_icon.json | 78 +++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 src/objects/native_icon.rs create mode 100644 src/objects/tests/native_icon.json create mode 100644 src/objects/tests/page_native_icon.json diff --git a/src/objects.rs b/src/objects.rs index 1e5cc5a..acc567a 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -7,6 +7,7 @@ pub mod database; pub mod emoji; pub mod error; pub mod file; +pub mod native_icon; pub mod page; pub mod parent; pub mod property; diff --git a/src/objects/native_icon.rs b/src/objects/native_icon.rs new file mode 100644 index 0000000..e81b0bc --- /dev/null +++ b/src/objects/native_icon.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] +#[serde(tag = "type", rename = "icon", rename_all = "snake_case")] +pub enum NativeIcon { + Icon { icon: Native }, +} + +#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] +#[serde(rename_all = "snake_case")] +pub struct Native { + pub name: String, + pub color: Option, +} diff --git a/src/objects/page.rs b/src/objects/page.rs index 53bc23c..08723a4 100644 --- a/src/objects/page.rs +++ b/src/objects/page.rs @@ -6,8 +6,8 @@ use serde_json::Number; use serde_with::skip_serializing_none; use super::{ - emoji::Emoji, file::File, parent::Parent, property::DateOrDateTime, rich_text::RichText, - user::User, + emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, property::DateOrDateTime, + rich_text::RichText, user::User, }; #[skip_serializing_none] @@ -32,6 +32,7 @@ pub struct Page { pub enum Icon { File(File), Emoji(Emoji), + NativeIcon(NativeIcon), } #[skip_serializing_none] diff --git a/src/objects/tests.rs b/src/objects/tests.rs index 14f1410..d7eebbd 100644 --- a/src/objects/tests.rs +++ b/src/objects/tests.rs @@ -1,6 +1,6 @@ use crate::objects::{ - block::Block, comment::Comment, emoji::Emoji, error::Error, file::File, page::Page, - rich_text::RichText, + block::Block, comment::Comment, emoji::Emoji, error::Error, file::File, + native_icon::NativeIcon, page::Page, rich_text::RichText, }; use super::block::CalloutValue; @@ -70,3 +70,15 @@ fn test_mention_date_only() { let result = serde_json::from_str::(include_str!("tests/mention_date.json")); assert!(result.is_ok()); } + +#[test] +fn test_page_icon_native() { + let result = serde_json::from_str::(include_str!("tests/native_icon.json")); + assert!(result.is_ok()); +} + +#[test] +fn test_page_icon_native_page() { + let result = serde_json::from_str::(include_str!("tests/page_native_icon.json")); + assert!(result.is_ok()); +} diff --git a/src/objects/tests/native_icon.json b/src/objects/tests/native_icon.json new file mode 100644 index 0000000..f82aae2 --- /dev/null +++ b/src/objects/tests/native_icon.json @@ -0,0 +1,7 @@ +{ + "type": "icon", + "icon": { + "name": "book-closed", + "color": "lightgray" + } +} diff --git a/src/objects/tests/page_native_icon.json b/src/objects/tests/page_native_icon.json new file mode 100644 index 0000000..1df6296 --- /dev/null +++ b/src/objects/tests/page_native_icon.json @@ -0,0 +1,78 @@ +{ + "object": "page", + "id": "be633bf1-dfa0-436d-b259-571129a590e5", + "created_time": "2022-10-24T22:54:00.000Z", + "last_edited_time": "2023-03-08T18:25:00.000Z", + "created_by": { + "object": "user", + "id": "c2f20311-9e54-4d11-8c79-7398424ae41e" + }, + "last_edited_by": { + "object": "user", + "id": "9188c6a5-7381-452f-b3dc-d4865aa89bdf" + }, + "cover": null, + "icon": { + "type": "icon", + "icon": { + "name": "book-closed", + "color": "lightgray" + } + }, + "parent": { + "type": "database_id", + "database_id": "a1d8501e-1ac1-43e9-a6bd-ea9fe6c8822b" + }, + "in_trash": true, + "properties": { + "Due date": { + "id": "M%3BBw", + "type": "date", + "date": { + "start": "2023-02-23", + "end": null, + "time_zone": null + } + }, + "Status": { + "id": "Z%3ClH", + "type": "status", + "status": { + "id": "86ddb6ec-0627-47f8-800d-b65afd28be13", + "name": "Not started", + "color": "default" + } + }, + "Title": { + "id": "title", + "type": "title", + "title": [ + { + "type": "text", + "text": { + "content": "Bug bash", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Bug bash", + "href": null + } + ] + }, + "Button": { + "id": "KJOc", + "type": "button", + "button": {} + } + }, + "url": "https://www.notion.so/Bug-bash-be633bf1dfa0436db259571129a590e5", + "public_url": "https://jm-testing.notion.site/p1-6df2c07bfc6b4c46815ad205d132e22d" +} + From 0e7500f096d8c0a737b02b31cbc5af110019f551 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Sat, 18 Apr 2026 16:05:53 -0500 Subject: [PATCH 2/2] fix: Further propagate icon-deser changes --- src/objects/block.rs | 6 +++++- src/objects/data_source.rs | 5 +++-- src/objects/database.rs | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/objects/block.rs b/src/objects/block.rs index 29c1b89..f44ce63 100644 --- a/src/objects/block.rs +++ b/src/objects/block.rs @@ -2,7 +2,10 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User}; +use super::{ + emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, rich_text::RichText, + user::User, +}; #[skip_serializing_none] #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)] @@ -341,6 +344,7 @@ pub enum TextColor { pub enum Icon { File(File), Emoji(Emoji), + NativeIcon(NativeIcon), } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] diff --git a/src/objects/data_source.rs b/src/objects/data_source.rs index c173f8e..4141c84 100644 --- a/src/objects/data_source.rs +++ b/src/objects/data_source.rs @@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use super::{ - database::DatabaseProperty, emoji::Emoji, file::File, parent::Parent, rich_text::RichText, - user::User, + database::DatabaseProperty, emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, + rich_text::RichText, user::User, }; #[skip_serializing_none] @@ -37,4 +37,5 @@ pub enum Icon { None, File(File), Emoji(Emoji), + NativeIcon(NativeIcon), } diff --git a/src/objects/database.rs b/src/objects/database.rs index 07c77b0..82b00ba 100644 --- a/src/objects/database.rs +++ b/src/objects/database.rs @@ -4,7 +4,10 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; -use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User}; +use super::{ + emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, rich_text::RichText, + user::User, +}; #[skip_serializing_none] #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)] @@ -33,6 +36,7 @@ pub enum Icon { None, File(File), Emoji(Emoji), + NativeIcon(NativeIcon), } #[skip_serializing_none]