fix: Go SDK metrics unmarshal error with OptionalNullable[time.Time]#867
Merged
fix: Go SDK metrics unmarshal error with OptionalNullable[time.Time]#867
Conversation
…me.Time] The Speakeasy-generated unmarshalValue treats OptionalNullable[time.Time] (map[bool]*time.Time) as a regular map with complex value types and tries to unmarshal a datetime string into map[string]json.RawMessage, which fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The OpenAPI spec used `type: [string, "null"]` for these fields, which causes Speakeasy to generate `OptionalNullable[time.Time]` (map[bool]*T). The Speakeasy unmarshalValue function has a bug where it treats this map type with complex value types (time.Time) as a regular map and tries to unmarshal a datetime string into map[string]json.RawMessage, causing: json: cannot unmarshal string into Go value of type map[string]json.RawMessage Changing to non-nullable `type: string` generates `*time.Time` / `*string` instead, which works correctly. The SDK still handles null values from the API gracefully (null deserializes to nil pointer). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alexbouchardd
approved these changes
Apr 23, 2026
Add omitempty to APIMetricsDataPoint.TimeBucket and APIMetricsMetadata.Granularity so the server omits these fields when nil, matching the non-nullable OpenAPI spec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes Go SDK crash when calling
GetEventMetricsorGetAttemptMetricswith granularity:Root cause
Speakeasy's generated
unmarshalValueinjson.gohas a bug withOptionalNullable[time.Time]. The type ismap[bool]*time.Timeunder the hood. When unmarshalling a map field, the code checks if the map's value type is a "complex value type" (time.Time,big.Int,types.Date). If it is, it skips the standardjson.Unmarshalpath (which would correctly callOptionalNullable.UnmarshalJSON()) and falls through to custom map handling that tries to unmarshal a datetime string intomap[string]json.RawMessage— which crashes.This only affects
OptionalNullable[time.Time]. OtherOptionalNullabletypes likeOptionalNullable[string]work fine becausestringis not a "complex value type". The marshal side already handles this correctly with ajson.Marshalercheck, but the unmarshal side is missing the equivalentjson.Unmarshalercheck. This is a Speakeasy codegen bug — we'll report it upstream.Fix
time_bucketandgranularityfrom nullable (type: [string, "null"]) to non-nullable (type: string). This makes Speakeasy generate*time.Time/*stringinstead ofOptionalNullable[T], avoiding the buggy code path.omitemptytoAPIMetricsDataPoint.TimeBucketandAPIMetricsMetadata.GranularityJSON tags so the server omits these fields when nil instead of returningnull. This matches the updated spec.API behavior change
When no granularity is specified, the response changes from:
{ "data": [{"time_bucket": null, "dimensions": {}, "metrics": {"count": 100}}], "metadata": {"granularity": null, "query_time_ms": 5, ...} }to:
{ "data": [{"dimensions": {}, "metrics": {"count": 100}}], "metadata": {"query_time_ms": 5, ...} }The fields are omitted instead of sent as
null. Functionally equivalent for consumers — both result in nil/undefined when accessed.Test plan
omitemptychange🤖 Generated with Claude Code