From e24cbadf712a5b496d6ec84cedea11943bc6319c Mon Sep 17 00:00:00 2001 From: Rene Nochebuena Guerrero Date: Thu, 21 May 2026 19:29:06 -0600 Subject: [PATCH] =?UTF-8?q?fix(xerrors):=20rename=20MarshalJSON=20field=20?= =?UTF-8?q?platformCode=20=E2=86=92=20platform=5Fcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JSON tag on the anonymous struct inside MarshalJSON corrected from `json:"platformCode,omitempty"` to `json:"platform_code,omitempty"` to match the OpenAPI spec snake_case convention. All error responses that serialize *Err directly now emit "platform_code" instead of "platformCode". PR.md added to .gitignore. --- .gitignore | 1 + CHANGELOG.md | 9 +++++++++ xerrors.go | 6 +++--- xerrors_test.go | 8 ++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 221da82..ae6d551 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ Thumbs.db # VCS files COMMIT.md RELEASE.md +PR.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e86d6c..c619738 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this module will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.2] - 2026-05-22 + +### Fixed + +- `MarshalJSON` JSON tag corrected from `"platformCode"` to `"platform_code"` to + match the OpenAPI spec snake_case convention. + +[1.0.2]: https://code.nochebuena.dev/go/xerrors/compare/v1.0.1...v1.0.2 + ## [1.0.0] — 2026-05-08 ### Added diff --git a/xerrors.go b/xerrors.go index fab664e..9669b2c 100644 --- a/xerrors.go +++ b/xerrors.go @@ -188,12 +188,12 @@ func (e *Err) ErrorContext() map[string]any { } // MarshalJSON implements [json.Marshaler]. -// Output: {"code":"NOT_FOUND","platformCode":"EMPLOYEE_NOT_FOUND","message":"...","fields":{...}} -// platformCode and fields are omitted when empty. +// Output: {"code":"NOT_FOUND","platform_code":"IDG-USR-0004","message":"...","fields":{...}} +// platform_code and fields are omitted when empty. func (e *Err) MarshalJSON() ([]byte, error) { return json.Marshal(struct { Code string `json:"code"` - PlatformCode string `json:"platformCode,omitempty"` + PlatformCode string `json:"platform_code,omitempty"` Message string `json:"message"` Fields map[string]any `json:"fields,omitempty"` }{ diff --git a/xerrors_test.go b/xerrors_test.go index d3164c4..8597f7d 100644 --- a/xerrors_test.go +++ b/xerrors_test.go @@ -312,8 +312,8 @@ func TestErr_MarshalJSON_PlatformCode(t *testing.T) { if jsonErr = json.Unmarshal(b, &out); jsonErr != nil { t.Fatalf("unmarshal error: %v", jsonErr) } - if out["platformCode"] != "EMPLOYEE_NOT_FOUND" { - t.Errorf("json platformCode = %v, want EMPLOYEE_NOT_FOUND", out["platformCode"]) + if out["platform_code"] != "EMPLOYEE_NOT_FOUND" { + t.Errorf("json platform_code = %v, want EMPLOYEE_NOT_FOUND", out["platform_code"]) } }) @@ -323,8 +323,8 @@ func TestErr_MarshalJSON_PlatformCode(t *testing.T) { if jsonErr != nil { t.Fatalf("MarshalJSON error: %v", jsonErr) } - if strings.Contains(string(b), "platformCode") { - t.Errorf("json should omit platformCode when empty, got: %s", b) + if strings.Contains(string(b), "platform_code") { + t.Errorf("json should omit platform_code when empty, got: %s", b) } }) } -- 2.39.5