From bea5d9c144ef9f6a31b2ac45530f485d9730f2b0 Mon Sep 17 00:00:00 2001 From: Kenzo Tanaka Date: Wed, 28 Oct 2026 11:38:02 +0900 Subject: [PATCH] Parse template version warnings as an array SendGrid returns `warnings` as an array of objects, so GetTemplateVersion failed to unmarshal versions that had warnings. Refs kenzo0107/terraform-provider-sendgrid#223 Co-Authored-By: Claude Opus 5.5 --- template_version.go | 26 +++++++++++++------------- template_version_test.go | 10 +++++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/template_version.go b/template_version.go index 71604c3..9b991d5 100644 --- a/template_version.go +++ b/template_version.go @@ -6,19 +6,19 @@ import ( ) type OutputGetTemplateVersion struct { - ID string `json:"id,omitempty"` - TemplateID string `json:"template_id,omitempty"` - Active int `json:"active,omitempty"` - Name string `json:"name,omitempty"` - HTMLContent string `json:"html_content,omitempty"` - PlainContent string `json:"plain_content,omitempty"` - GeneratePlainContent bool `json:"generate_plain_content,omitempty"` - Subject string `json:"subject,omitempty"` - Editor string `json:"editor,omitempty"` - TestData string `json:"test_data,omitempty"` - UpdatedAt string `json:"updated_at,omitempty"` - Warnings Warning `json:"warnings,omitempty"` - ThumbnailURL string `json:"thumbnail_url,omitempty"` + ID string `json:"id,omitempty"` + TemplateID string `json:"template_id,omitempty"` + Active int `json:"active,omitempty"` + Name string `json:"name,omitempty"` + HTMLContent string `json:"html_content,omitempty"` + PlainContent string `json:"plain_content,omitempty"` + GeneratePlainContent bool `json:"generate_plain_content,omitempty"` + Subject string `json:"subject,omitempty"` + Editor string `json:"editor,omitempty"` + TestData string `json:"test_data,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + Warnings []Warning `json:"warnings,omitempty"` + ThumbnailURL string `json:"thumbnail_url,omitempty"` } // see: https://docs.sendgrid.com/api-reference/transactional-templates-versions/retrieve-a-specific-transactional-template-version diff --git a/template_version_test.go b/template_version_test.go index 917295b..1548bd0 100644 --- a/template_version_test.go +++ b/template_version_test.go @@ -23,7 +23,12 @@ func TestGetTemplateVersion(t *testing.T) { "name": "dummy", "generate_plain_content": true, "updated_at": "2024-01-20 08:46:07", - "editor": "code" + "editor": "code", + "warnings": [ + { + "message": "Failed to validate handlebars" + } + ] }`); err != nil { t.Fatal(err) } @@ -43,6 +48,9 @@ func TestGetTemplateVersion(t *testing.T) { GeneratePlainContent: true, UpdatedAt: "2024-01-20 08:46:07", Editor: "code", + Warnings: []Warning{ + {Message: "Failed to validate handlebars"}, + }, } if !reflect.DeepEqual(want, expected) { t.Fatal(ErrIncorrectResponse, errors.New(pretty.Compare(want, expected)))