From 42cd0638771aa5b414bd4fab5825f0b5020f4d2a Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:59:14 +0400 Subject: [PATCH] Make `from` optional for Message and Draft models (#204) # Description This PR makes the `from` field optional for both messages and drafts, aligning it to the API. # License I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner. --- CHANGELOG.md | 2 +- src/main/kotlin/com/nylas/models/Draft.kt | 10 +++++----- src/main/kotlin/com/nylas/models/Message.kt | 10 +++++----- src/test/kotlin/com/nylas/resources/DraftsTests.kt | 6 +++--- src/test/kotlin/com/nylas/resources/MessagesTests.kt | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd238d62..81ba5746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -* Fix schema issue in the `Event` model +* Fix schema issue in the `Event`, `Message`, and `Draft` models ## [2.0.0] - Released 2024-02-05 diff --git a/src/main/kotlin/com/nylas/models/Draft.kt b/src/main/kotlin/com/nylas/models/Draft.kt index 18220af7..0ec5c612 100644 --- a/src/main/kotlin/com/nylas/models/Draft.kt +++ b/src/main/kotlin/com/nylas/models/Draft.kt @@ -16,11 +16,6 @@ class Draft( */ @Json(name = "grant_id") val grantId: String, - /** - * An array of message senders. - */ - @Json(name = "from") - val from: List, /** * Unix timestamp of when the message was received by the mail server. * This may be different from the unverified Date header in raw message object. @@ -32,6 +27,11 @@ class Draft( */ @Json(name = "object") private val obj: String = "draft", + /** + * An array of message senders. + */ + @Json(name = "from") + val from: List? = null, /** * An array of bcc recipients. */ diff --git a/src/main/kotlin/com/nylas/models/Message.kt b/src/main/kotlin/com/nylas/models/Message.kt index db9da2d0..d7fb3faf 100644 --- a/src/main/kotlin/com/nylas/models/Message.kt +++ b/src/main/kotlin/com/nylas/models/Message.kt @@ -11,16 +11,16 @@ data class Message( */ @Json(name = "grant_id") val grantId: String, - /** - * An array of message senders. - */ - @Json(name = "from") - val from: List, /** * The type of object. */ @Json(name = "object") private val obj: String = "message", + /** + * An array of message senders. + */ + @Json(name = "from") + val from: List? = null, /** * The unique identifier for the message. * Note: The ID may not be present for scheduled messages until the message is sent. diff --git a/src/test/kotlin/com/nylas/resources/DraftsTests.kt b/src/test/kotlin/com/nylas/resources/DraftsTests.kt index 0ca3d53f..b6c27bcb 100644 --- a/src/test/kotlin/com/nylas/resources/DraftsTests.kt +++ b/src/test/kotlin/com/nylas/resources/DraftsTests.kt @@ -109,9 +109,9 @@ class DraftsTests { assertEquals(2, draft.folders?.size) assertEquals("8l6c4d11y1p4dm4fxj52whyr9", draft.folders?.first()) assertEquals("d9zkcr2tljpu3m4qpj7l2hbr0", draft.folders?.last()) - assertEquals(1, draft.from.size) - assertEquals("Daenerys Targaryen", draft.from.first().name) - assertEquals("daenerys.t@example.com", draft.from.first().email) + assertEquals(1, draft.from?.size) + assertEquals("Daenerys Targaryen", draft.from?.first()?.name) + assertEquals("daenerys.t@example.com", draft.from?.first()?.email) assertEquals("41009df5-bf11-4c97-aa18-b285b5f2e386", draft.grantId) assertEquals("5d3qmne77v32r8l4phyuksl2x", draft.id) assertEquals("draft", draft.getObject()) diff --git a/src/test/kotlin/com/nylas/resources/MessagesTests.kt b/src/test/kotlin/com/nylas/resources/MessagesTests.kt index db8b302d..62598c70 100644 --- a/src/test/kotlin/com/nylas/resources/MessagesTests.kt +++ b/src/test/kotlin/com/nylas/resources/MessagesTests.kt @@ -108,9 +108,9 @@ class MessagesTests { assertEquals(2, message.folders?.size) assertEquals("8l6c4d11y1p4dm4fxj52whyr9", message.folders?.get(0)) assertEquals("d9zkcr2tljpu3m4qpj7l2hbr0", message.folders?.get(1)) - assertEquals(1, message.from.size) - assertEquals("Daenerys Targaryen", message.from[0].name) - assertEquals("daenerys.t@example.com", message.from[0].email) + assertEquals(1, message.from?.size) + assertEquals("Daenerys Targaryen", message.from?.get(0)?.name) + assertEquals("daenerys.t@example.com", message.from?.get(0)?.email) assertEquals("41009df5-bf11-4c97-aa18-b285b5f2e386", message.grantId) assertEquals("5d3qmne77v32r8l4phyuksl2x", message.id) assertEquals("message", message.getObject())