diff --git a/api/docs/CHANGELOG.md b/api/docs/CHANGELOG.md index 24ac43c57b..b0ab42e497 100644 --- a/api/docs/CHANGELOG.md +++ b/api/docs/CHANGELOG.md @@ -40,6 +40,7 @@ keywords: "API, Docker, rcli, REST, documentation" longer set when using BuildKit. The `Author` field is set through the `MAINTAINER` Dockerfile instruction, which is deprecated, and the `Comment` field is option, and may not be set depending on how the image was created. +* `GET /container/{id}/json` now omits `Config.OnBuild` if its value is empty. * `GET /containers/{id}/json`: the `NetworkSettings` no longer returns the deprecated `Bridge`, `HairpinMode`, `LinkLocalIPv6Address`, `LinkLocalIPv6PrefixLen`, `SecondaryIPAddresses`, `SecondaryIPv6Addresses`, `EndpointID`, `Gateway`, diff --git a/api/types/container/config.go b/api/types/container/config.go index c5650f10c9..98e7c479c6 100644 --- a/api/types/container/config.go +++ b/api/types/container/config.go @@ -46,7 +46,7 @@ type Config struct { // // Deprecated: this field is deprecated since API v1.44. Use EndpointSettings.MacAddress instead. MacAddress string `json:",omitempty"` - OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile + OnBuild []string `json:",omitempty"` // ONBUILD metadata that were defined on the image Dockerfile Labels map[string]string // List of labels set to this container StopSignal string `json:",omitempty"` // Signal to stop a container StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container diff --git a/api/types/container/config_test.go b/api/types/container/config_test.go new file mode 100644 index 0000000000..691f2c9d91 --- /dev/null +++ b/api/types/container/config_test.go @@ -0,0 +1,24 @@ +package container + +import ( + "encoding/json" + "testing" + + "gotest.tools/v3/assert" +) + +func TestMarshalConfig(t *testing.T) { + omitted := []byte(`{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"Labels":null}`) + + bytes, err := json.Marshal(Config{}) + assert.NilError(t, err) + assert.Equal(t, string(bytes), string(omitted)) + + empty := Config{ + OnBuild: []string{}, + } + + bytes, err = json.Marshal(empty) + assert.NilError(t, err) + assert.Equal(t, string(bytes), string(omitted)) +} diff --git a/vendor/github.com/moby/moby/api/types/container/config.go b/vendor/github.com/moby/moby/api/types/container/config.go index c5650f10c9..98e7c479c6 100644 --- a/vendor/github.com/moby/moby/api/types/container/config.go +++ b/vendor/github.com/moby/moby/api/types/container/config.go @@ -46,7 +46,7 @@ type Config struct { // // Deprecated: this field is deprecated since API v1.44. Use EndpointSettings.MacAddress instead. MacAddress string `json:",omitempty"` - OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile + OnBuild []string `json:",omitempty"` // ONBUILD metadata that were defined on the image Dockerfile Labels map[string]string // List of labels set to this container StopSignal string `json:",omitempty"` // Signal to stop a container StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container