Skip to content

fix: change MessageEmailContent from field from String to union type#75

Open
zerocool4u2 wants to merge 1 commit into
knocklabs:mainfrom
zerocool4u2:fix/message-email-content-from-type
Open

fix: change MessageEmailContent from field from String to union type#75
zerocool4u2 wants to merge 1 commit into
knocklabs:mainfrom
zerocool4u2:fix/message-email-content-from-type

Conversation

@zerocool4u2
Copy link
Copy Markdown

@zerocool4u2 zerocool4u2 commented Apr 21, 2026

Problem

The Knock API returns the from field in email message content as an object:

{ "email": "sender@example.com", "name": "Sender Name" }

However, MessageEmailContent declares from as required :from, String, which causes a ConversionError when the union type resolver tries to match the email content variant — the Hash value doesn't match the String type, so no variant matches and content.data fails:

Knockapi::Errors::ConversionError: Failed to parse MessageGetContentResponse.data
from Hash to MessageGetContentResponse::Data[...]. Cause: no matching variant

The only workaround is using content[:data] to bypass typed coercion entirely.

Fix

Changes from to a union type (From) that accepts both (I wasn't sure if this was the norm or not since other types just return a plain string, eg: SMS integrations)

  • A plain String (for simple email addresses)
  • An EmailObject with email and name attributes (matching the actual API response)

Tested

Verified against live Knock API responses - content.data now correctly returns a typed MessageEmailContent with from as a From::EmailObject.

The Knock API returns the `from` field in email message content as
either a plain string or an object with `email` and `name` keys:

    { email: "sender@example.com", name: "Sender Name" }

The current schema declares `from` as `required :from, String`, which
causes a `ConversionError` when the union type resolver tries to match
the email content variant — the Hash value doesn't match the String
type, so no variant matches and the entire `content.data` call fails.

This changes `from` to a union type (`From`) that accepts both a plain
String and an `EmailObject` with `email` and `name` attributes,
matching the actual API response shape.
@zerocool4u2 zerocool4u2 requested a review from a team as a code owner April 21, 2026 18:46
@zerocool4u2 zerocool4u2 requested review from meryldakin and thomaswhyyou and removed request for a team April 21, 2026 18:46

# @!attribute from
# The sender's email address.
# The sender's email address. Can be a string email address or an object
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want a "." at the end of this sentence

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has the . on the next line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants