fix: change MessageEmailContent from field from String to union type#75
Open
zerocool4u2 wants to merge 1 commit into
Open
fix: change MessageEmailContent from field from String to union type#75zerocool4u2 wants to merge 1 commit into
from field from String to union type#75zerocool4u2 wants to merge 1 commit into
Conversation
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.
meryldakin
approved these changes
Apr 30, 2026
|
|
||
| # @!attribute from | ||
| # The sender's email address. | ||
| # The sender's email address. Can be a string email address or an object |
Contributor
There was a problem hiding this comment.
i think we want a "." at the end of this sentence
Author
There was a problem hiding this comment.
it has the . on the next line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Knock API returns the
fromfield 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)
Tested
Verified against live Knock API responses -
content.datanow correctly returns a typedMessageEmailContentwith from as aFrom::EmailObject.