Files
moby/api/types
Sebastiaan van Stijn 62c1a719b3 api/types: use "omitzero" instead of "omitempty" for "netip" fields
Pull request 50956 (88adc28731) updated
various types in the API module from a string to a `netip.Prefix` or
`netip.Addr`. A side-effect of this was that zero values would no longer
be omitted, and instead marshaled as an empty string;

    package main

    import (
        "encoding/json"
        "fmt"
        "net/netip"
    )

    type Foo struct {
        OmitEmpty netip.Prefix `json:",omitempty"`
        OmitZero  netip.Prefix `json:",omitzero"`
    }

    func main() {
        out, _ := json.Marshal(Foo{})
        fmt.Println(string(out))
    }

The above produces `{"OmitEmpty":""}`, not omitting the empty address.

This patch;

- updates most types to use `omitzero` instead of `omitempty`.
- adds explicit `json` names to fields.

There's one type remaining that uses `omitzero`, but it's generated by
go-swagger, which currently doesn't support `omitzero`; the `PortSummary.IP`;
335f60509f/api/types/container/port_summary.go (L12-L20)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-26 15:57:18 +01:00
..
2025-05-30 15:59:01 +02:00
2025-11-06 16:21:32 -06:00
2025-05-30 15:59:01 +02:00
2025-12-15 10:36:05 +00:00