Skip to content

Comparison filters on ListNews (PublishedUtc.gte/gt/lte/lt) are unconstructible from outside the gen package #579

Description

@Americas

Description

The ListNewsParams struct in rest/gen/client.gen.go exposes comparison filters
for published_utc (and similarly for ticker.gte/gt/lte/lt) as anonymous structs
with a single unexported field:

// rest/gen/client.gen.go
type ListNewsParams struct {
    // ...
    PublishedUtcGte *struct {
        union json.RawMessage
    } `form:"published_utc.gte,omitempty" json:"published_utc.gte,omitempty"`

    PublishedUtcGt  *struct{ union json.RawMessage } `...`
    PublishedUtcLte *struct{ union json.RawMessage } `...`
    PublishedUtcLt  *struct{ union json.RawMessage } `...`
    // ...
}

These fields appear to come from a oneOf<datetime, date> schema in the OpenAPI
spec. oapi-codegen normally emits FromX / AsX / MergeX helpers for union
types, but no such helpers are generated here:

$ grep -E 'FromListNewsParamsPublishedUtcGte|AsListNewsParamsPublishedUtcGte' rest/gen
(no matches)

Why this is a problem

Two compounding issues make these fields unusable from outside the gen package:

  1. The union field is unexported. Per the Go spec (Type identity):

    Non-exported field names from different packages are always different.

    So callers cannot construct an equivalent struct literal — struct{ union json.RawMessage }{...} declared elsewhere is a different type and is not assignable to *ListNewsParams.PublishedUtcGte.

  2. No exported constructor or setter is generated.

The serialization side of the SDK does work — NewListNewsRequest calls runtime.StyleParamWithLocation on *params.PublishedUtcGte and produces the correct published_utc.gte=... query parameter — but there is no supported way to put a value into the field.

The only workarounds available to consumers are:

  • A RequestEditorFn that manually appends published_utc.gte to the query string (bypassing the typed param entirely).
  • reflect + unsafe to set the unexported field.

Affected fields include (non-exhaustive):

  • ListNewsParams.PublishedUtcGte / Gt / Lte / Lt
  • Likely the same pattern on other endpoints that filter by published_utc, timestamp, etc.

Versions

  • github.com/massive-com/client-go/v3 v3.1.0 and v3.3.0 (verified both)
  • Go 1.26

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions