You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the big improvements added in Go 1.24 is `omitzero`[0][1][2],
which makes it possible to omit the "zero value" of a given Go type when
marshaling to JSON, or if the `IsZero() bool` function on the type
returns `true`.
To make it possible for `oapi-codegen` to use this, we can wire in a new
extension, `x-omitzero` which allows per-field tuning of this behaviour.
This is something that is safe to generate alongside the `omitempty`
tags[3]:
> If both "omitempty" and "omitzero" are specified, the field will be
omitted if the value is either empty or zero (or both).
To validate this, we can add a new example for the extension, which
provides testing of the expected behaviour.
As this requires Go 1.24, we need to set up the boilerplate for a new
module that only runs Go 1.24.
Closesoapi-codegen#1899.
[0]: https://www.jvt.me/posts/2025/02/12/go-omitzero-124/
[1]: https://www.bytesizego.com/blog/go-124-omitzero
[2]: https://antonz.org/go-1-24/#omit-zero-values-in-json
[3]: https://pkg.go.dev/encoding/json
0 commit comments