From ae94eb5209d16464d1a410cd3e486a9efa5dcc36 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 12:27:38 +0530 Subject: [PATCH 1/6] =?UTF-8?q?add=20support=20for=20reading=20and=20writi?= =?UTF-8?q?ng=20Name=20&=20Caption=20properties=20to=20file=20blocks=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../File/FIleInput/ExternalFileInput.cs | 7 ++- .../Models/File/FIleInput/IFileObjectInput.cs | 10 ++++- .../File/FIleInput/UploadedFileInput.cs | 5 +++ .../BlocksClientTests.cs | 45 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 9c258ceb..38ad781c 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { @@ -7,6 +8,10 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("external")] public Data External { get; set; } + public string Name { get; set; } + + public IEnumerable Caption { get; set; } + public class Data { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs index 31df1573..5883b7c1 100644 --- a/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs @@ -1,6 +1,14 @@ -namespace Notion.Client +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client { public interface IFileObjectInput { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index 52d7934d..dabca4e1 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client @@ -8,6 +9,10 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("file")] public Data File { get; set; } + public string Name { get; set; } + + public IEnumerable Caption { get; set; } + public class Data { [JsonProperty("url")] diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 5c8e4618..d52b8f64 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -399,6 +399,51 @@ private static IEnumerable BlockData() .Subject.Should().BeOfType() .Subject.Text.Content.Should().Be("Data"); }) + }, + new object[] + { + new FileBlockRequest { + File = new ExternalFile + { + Name = "Test file", + External = new ExternalFile.Info + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + }, + Caption = new List + { + new RichTextTextInput { Text = new Text { Content = "Test file" } } + } + } + }, + new FileUpdateBlock + { + File = new ExternalFileInput + { + Name = "Test file name", + External = new ExternalFileInput.Data + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + }, + Caption = new List + { + new RichTextTextInput { Text = new Text { Content = "Test file caption" } } + } + } + }, + new Action((block, client) => + { + var fileBlock = block.Should().NotBeNull().And.BeOfType().Subject; + fileBlock.HasChildren.Should().BeFalse(); + + var file = fileBlock.File.Should().NotBeNull().And.BeOfType().Subject; + file.Name.Should().Be("Test file name.jpg"); + file.External.Should().NotBeNull(); + file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"); + file.Caption.Should().NotBeNull().And.ContainSingle() + .Subject.Should().BeOfType().Subject + .Text.Content.Should().Be("Test file caption"); + }) } }; } From 4af4559095c8ad46d55bc5c3b94f82235fad23f9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:15:44 +0530 Subject: [PATCH 2/6] adding a [JsonProperty("name")] attribute for the Name property to ensure consistent JSON serialization Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index dabca4e1..31715b12 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -9,6 +9,7 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("file")] public Data File { get; set; } + [JsonProperty("name")] public string Name { get; set; } public IEnumerable Caption { get; set; } From 93ad9654a5555402bb8809fd1f970aebd343f370 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:16:33 +0530 Subject: [PATCH 3/6] add a [JsonProperty("caption")] attribute for the Caption property to ensure it serializes consistently with the interface Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index 31715b12..949df10c 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -12,6 +12,7 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("caption")] public IEnumerable Caption { get; set; } public class Data From dd4e517d51e6ee5f66575724fe83ba7d6a26dae0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:16:56 +0530 Subject: [PATCH 4/6] add a [JsonProperty("name")] attribute here for consistency with the JSON contract Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 38ad781c..8a602d38 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -8,6 +8,7 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("external")] public Data External { get; set; } + [JsonProperty("name")] public string Name { get; set; } public IEnumerable Caption { get; set; } From 28d6b212dbd50513734bd0a68d87accf8a38cb2e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:17:18 +0530 Subject: [PATCH 5/6] add a [JsonProperty("caption")] attribute to ensure proper serialization Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 8a602d38..6e2627cf 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -11,6 +11,7 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("caption")] public IEnumerable Caption { get; set; } public class Data From dcd3d98d06e503829a6f8e949750419d6e63fe89 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:22:07 +0530 Subject: [PATCH 6/6] =?UTF-8?q?add=20a=20comment=20to=20clarify=20why=20th?= =?UTF-8?q?e=20file=20name=20is=20expected=20to=20automatically=20have=20a?= =?UTF-8?q?=20'.jpg'=20or=20other=20file=20extension=F0=9F=92=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Models/File/FileObject.cs | 3 +++ Test/Notion.IntegrationTests/BlocksClientTests.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index aa7aed1b..0ac30a6c 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -12,6 +12,9 @@ public abstract class FileObject : IPageIcon [JsonProperty("caption")] public IEnumerable Caption { get; set; } + /// + /// The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions. + /// [JsonProperty("name")] public string Name { get; set; } diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index d52b8f64..5f1ca25b 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -437,7 +437,10 @@ private static IEnumerable BlockData() fileBlock.HasChildren.Should().BeFalse(); var file = fileBlock.File.Should().NotBeNull().And.BeOfType().Subject; + + // NOTE: The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions. file.Name.Should().Be("Test file name.jpg"); + file.External.Should().NotBeNull(); file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"); file.Caption.Should().NotBeNull().And.ContainSingle()