Repository: seratch/notion-sdk-jvm
Pull request #53 (2022-06-25 22:38:24)

Deserialize captions on Images and Videos as Rich-Text
This PR addresses https://github.com/seratch/notion-sdk-jvm/issues/52 

seratch: @looorent Can you run the code formatter? `mvn spotless:apply` or `./scripts/format.sh` works for you.

```
Error:  Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.20.0:check (default-cli) on project notion-sdk-jvm-core: The following files had format violations:
Error:      src/main/kotlin/notion/api/v1/model/blocks/VideoBlock.kt
Error:          @@ -45,8 +45,8 @@
Error:           ··open·class·Element
Error:           ··@JvmOverloads
Error:           ··constructor(
Error:          -····val·caption:·List<PageProperty.RichText>?·=·null,
Error:          -····val·type:·String?·=·"external",
Error:          -····val·external:·ExternalFileDetails?·=·null,
Error:          +······val·caption:·List<PageProperty.RichText>?·=·null,
Error:          +······val·type:·String?·=·"external",
Error:          +······val·external:·ExternalFileDetails?·=·null,
Error:           ··)
Error:           }
Error:  Run 'mvn spotless:apply' to fix these violations.
Error:  -> [Help 1]
```
looorent: Sure, it's done.

Patch:
diff --git a/core/src/main/kotlin/notion/api/v1/model/blocks/ImageBlock.kt b/core/src/main/kotlin/notion/api/v1/model/blocks/ImageBlock.kt
index c18ba92..d9c0c9d 100644
--- a/core/src/main/kotlin/notion/api/v1/model/blocks/ImageBlock.kt
+++ b/core/src/main/kotlin/notion/api/v1/model/blocks/ImageBlock.kt
@@ -5,6 +5,7 @@ import java.util.*
 import notion.api.v1.model.common.ExternalFileDetails
 import notion.api.v1.model.common.FileDetails
 import notion.api.v1.model.common.ObjectType
+import notion.api.v1.model.pages.PageProperty
 import notion.api.v1.model.users.User
 
 open class ImageBlock
@@ -48,6 +49,6 @@ constructor(
       val type: String? = null,
       val external: ExternalFileDetails? = null,
       val file: FileDetails? = null,
-      val caption: List<String>? = null,
+      val caption: List<PageProperty.RichText>? = null,
   )
 }
diff --git a/core/src/main/kotlin/notion/api/v1/model/blocks/VideoBlock.kt b/core/src/main/kotlin/notion/api/v1/model/blocks/VideoBlock.kt
index 5c45dbd..1f0e900 100644
--- a/core/src/main/kotlin/notion/api/v1/model/blocks/VideoBlock.kt
+++ b/core/src/main/kotlin/notion/api/v1/model/blocks/VideoBlock.kt
@@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName
 import java.util.*
 import notion.api.v1.model.common.ExternalFileDetails
 import notion.api.v1.model.common.ObjectType
+import notion.api.v1.model.pages.PageProperty
 import notion.api.v1.model.users.User
 
 open class VideoBlock
@@ -44,7 +45,7 @@ constructor(
   open class Element
   @JvmOverloads
   constructor(
-      val caption: List<String>? = null,
+      val caption: List<PageProperty.RichText>? = null,
       val type: String? = "external",
       val external: ExternalFileDetails? = null,
   )


Test patch:
diff --git a/core/src/test/kotlin/tests/json/BlockParserTest.kt b/core/src/test/kotlin/tests/json/BlockParserTest.kt
index fa73fee..ea51ada 100644
--- a/core/src/test/kotlin/tests/json/BlockParserTest.kt
+++ b/core/src/test/kotlin/tests/json/BlockParserTest.kt
@@ -475,6 +475,49 @@ class BlockParserTest {
         }
       }
     },
+    {
+        "object": "block",
+        "id": "f325c9c4-ffdb-43ae-b45d-4836cb54d570",
+        "created_time": "2022-06-21T11:39:00.000Z",
+        "last_edited_time": "2022-06-21T11:41:00.000Z",
+        "created_by": {
+            "object": "user",
+            "id": "085d81d9-f6bc-4fb2-ad91-cac7c64d64d5"
+        },
+        "last_edited_by": {
+            "object": "user",
+            "id": "085d81d9-f6bc-4fb2-ad91-cac7c64d64d5"
+        },
+        "has_children": false,
+        "archived": false,
+        "type": "image",
+        "image": {
+            "caption": [
+                {
+                    "type": "text",
+                    "text": {
+                        "content": "Any kind of caption",
+                        "link": null
+                    },
+                    "annotations": {
+                        "bold": false,
+                        "italic": false,
+                        "strikethrough": false,
+                        "underline": false,
+                        "code": false,
+                        "color": "default"
+                    },
+                    "plain_text": "Any kind of caption",
+                    "href": null
+                }
+            ],
+            "type": "file",
+            "file": {
+                "url": "https://any-url.com",
+                "expiry_time": "2022-06-25T22:56:28.669Z"
+            }
+        }
+    },
     {
       "type": "file",
       "file": {
@@ -484,6 +527,82 @@ class BlockParserTest {
         }
       }
     },
+    {
+        "object": "block",
+        "id": "a379f8db-38f4-4e1d-8985-2001c33fff82",
+        "created_time": "2022-06-25T22:23:00.000Z",
+        "last_edited_time": "2022-06-25T22:24:00.000Z",
+        "created_by": {
+            "object": "user",
+            "id": "a613fdcd-8a8a-4893-a1bc-2fddf2eb1f37"
+        },
+        "last_edited_by": {
+            "object": "user",
+            "id": "a613fdcd-8a8a-4893-a1bc-2fddf2eb1f37"
+        },
+        "has_children": false,
+        "archived": false,
+        "type": "video",
+        "video": {
+            "caption": [
+                {
+                    "type": "text",
+                    "text": {
+                        "content": "A caption ",
+                        "link": null
+                    },
+                    "annotations": {
+                        "bold": false,
+                        "italic": false,
+                        "strikethrough": false,
+                        "underline": false,
+                        "code": false,
+                        "color": "default"
+                    },
+                    "plain_text": "A caption ",
+                    "href": null
+                },
+                {
+                    "type": "text",
+                    "text": {
+                        "content": "about",
+                        "link": null
+                    },
+                    "annotations": {
+                        "bold": true,
+                        "italic": false,
+                        "strikethrough": false,
+                        "underline": false,
+                        "code": false,
+                        "color": "default"
+                    },
+                    "plain_text": "about",
+                    "href": null
+                },
+                {
+                    "type": "text",
+                    "text": {
+                        "content": " a video",
+                        "link": null
+                    },
+                    "annotations": {
+                        "bold": false,
+                        "italic": false,
+                        "strikethrough": false,
+                        "underline": false,
+                        "code": false,
+                        "color": "default"
+                    },
+                    "plain_text": " a video",
+                    "href": null
+                }
+            ],
+            "type": "external",
+            "external": {
+                "url": "https://www.youtube.com/watch?v=aA7si7AmPkY"
+            }
+        }
+    },
     {
       "type": "pdf",
       "pdf": {