Skip to content

fix: accept day-name strings in SystemDayOfWeek unmarshal (v24 + v25)#36

Open
spbsoluble wants to merge 2 commits into
mainfrom
fix/system-day-of-week-string-unmarshal
Open

fix: accept day-name strings in SystemDayOfWeek unmarshal (v24 + v25)#36
spbsoluble wants to merge 2 commits into
mainfrom
fix/system-day-of-week-string-unmarshal

Conversation

@spbsoluble

Copy link
Copy Markdown
Contributor

Problem

SystemDayOfWeek.UnmarshalJSON only accepts a JSON integer, but Keyfactor Command (observed on v25.5) serializes WeeklyModel.Days as day-name strings (e.g. ["Monday"]) in GET /CertificateAuthority responses. Any Weekly-shaped CA schedule therefore fails to deserialize, which breaks every subsequent Read/Update of that CA in downstream consumers.

Tracked downstream as keyfactor-pub/terraform-provider-keyfactor#185.

Fix

UnmarshalJSON now tries the integer form first (preserving the original validation against AllowedSystemDayOfWeekEnumValues and its error message), then falls back to the string form via the existing Parse() day-name mapper. A payload that is neither a valid JSON integer nor a JSON string returns a clear error.

Applied identically to all four generated copies: v24/api/keyfactor/{v1,v2} and v25/api/keyfactor/{v1,v2}.

Verification

  • New unit tests in each of the four packages: int form, string form, invalid string, out-of-range int, plus full WeeklyModel round-trips for both {"Days":["Monday","Friday"],...} and int-index forms.
  • Red→green confirmed: with the fix reverted, the string-form tests fail with json: cannot unmarshal string into Go value of type int32.
  • Full go test ./... green in both the v24 and v25 modules (with -vet=off due to a pre-existing, unrelated fmt.Errorf non-constant-format vet error in configuration.go on main).

Notes

  • The feat/sdk-v25-migration branch generates this file from the shared custom-templates/go/model_enum.mustache, which still has the int-only unmarshal — that template will need the equivalent fallback when the migration branch is picked back up. That template is shared by ~80+ int-backed enums (all of which have unused Parse() string helpers), so a blanket template change deserves its own discussion; this PR deliberately fixes only the enum with an observed wire regression.

Keyfactor Command serializes WeeklyModel.Days as day-name strings (e.g.
"Monday") in some API responses, but SystemDayOfWeek.UnmarshalJSON only
accepted JSON integers, causing Weekly-scheduled resources to fail to
deserialize. Try the integer form first, preserving existing enum
validation, and fall back to the existing Parse() day-name mapping when
the payload is a JSON string. Malformed strings and out-of-range ints
still error clearly.

Applies to both v1 and v2 API packages in this module.
Fixes keyfactor-pub/terraform-provider-keyfactor#185: Keyfactor Command
v25.5 serializes WeeklyModel.Days as day-name strings (e.g. "Monday")
in GET /CertificateAuthority responses, but SystemDayOfWeek.UnmarshalJSON
only accepted JSON integers, causing any Weekly-scheduled CA to fail to
deserialize. Try the integer form first, preserving existing enum
validation, and fall back to the existing Parse() day-name mapping when
the payload is a JSON string. Malformed strings and out-of-range ints
still error clearly.

Applies to both v1 and v2 API packages in this module.
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.

1 participant