Repository: moby/moby
File: api/types/container/container.go (Go)

Code before:

// State stores container's running state
// it's part of ContainerJSONBase and returned by "inspect" command
type State struct {
	Status     string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
	Running    bool
	Paused     bool
	Restarting bool
	OOMKilled  bool
	Dead       bool
	Pid        int
	ExitCode   int
	Error      string
	StartedAt  string
	FinishedAt string
	Health     *Health `json:",omitempty"`
}

// Summary contains response of Engine API:
// GET "/containers/json"
type Summary struct {
	ID                      string `json:"Id"`
	Names                   []string
	Image                   string
	ImageID                 string
	ImageManifestDescriptor *ocispec.Descriptor `json:",omitempty"`
	Command                 string
	Created                 int64
	Ports                   []Port
	SizeRw                  int64 `json:",omitempty"`
	SizeRootFs              int64 `json:",omitempty"`
	Labels                  map[string]string
	State                   string
	Status                  string
	HostConfig              struct {
		NetworkMode string            `json:",omitempty"`
		Annotations map[string]string `json:",omitempty"`
	}
	NetworkSettings *NetworkSettingsSummary
	Mounts          []MountPoint
}

// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
// for API version 1.18 and older.
//
// TODO(thaJeztah): combine ContainerJSONBase and InspectResponse into a single struct.
// The split between ContainerJSONBase (ContainerJSONBase) and InspectResponse (InspectResponse)
// was done in commit 6deaa58ba5f051039643cedceee97c8695e2af74 (https://github.com/moby/moby/pull/13675).
// ContainerJSONBase contained all fields for API < 1.19, and InspectResponse
// held fields that were added in API 1.19 and up. Given that the minimum
// supported API version is now 1.24, we no longer use the separate type.

Review comment (bug):
oh! Before I blame myself; we've been very lax on specifying the _intended_ casing of fields in JSON (depending on "whatever Go makes of it); this has resulted in inconsistencies where the Swagger documented the wrong casing (the `Id` one is a good example of that, where we had to later adjust the case to what it happened to be). Go itself treats JSON case-insensitive, but not all languages do (and ISTR Go is working on a "v2" JSON package to allow case-sensitivity).

Probably good to add an explicit `json:"ImageManifestDescriptor,omitempty"` (at least for new fields; we should also tackle existing fields at some point)

Code after:

// State stores container's running state
// it's part of ContainerJSONBase and returned by "inspect" command
type State struct {
	Status     string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
	Running    bool
	Paused     bool
	Restarting bool
	OOMKilled  bool
	Dead       bool
	Pid        int
	ExitCode   int
	Error      string
	StartedAt  string
	FinishedAt string
	Health     *Health `json:",omitempty"`
}

// Summary contains response of Engine API:
// GET "/containers/json"
type Summary struct {
	ID                      string `json:"Id"`
	Names                   []string
	Image                   string
	ImageID                 string
	ImageManifestDescriptor *ocispec.Descriptor `json:"ImageManifestDescriptor,omitempty"`
	Command                 string
	Created                 int64
	Ports                   []Port
	SizeRw                  int64 `json:",omitempty"`
	SizeRootFs              int64 `json:",omitempty"`
	Labels                  map[string]string
	State                   string
	Status                  string
	HostConfig              struct {
		NetworkMode string            `json:",omitempty"`
		Annotations map[string]string `json:",omitempty"`
	}
	NetworkSettings *NetworkSettingsSummary
	Mounts          []MountPoint
}

// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
// for API version 1.18 and older.
//
// TODO(thaJeztah): combine ContainerJSONBase and InspectResponse into a single struct.
// The split between ContainerJSONBase (ContainerJSONBase) and InspectResponse (InspectResponse)
// was done in commit 6deaa58ba5f051039643cedceee97c8695e2af74 (https://github.com/moby/moby/pull/13675).
// ContainerJSONBase contained all fields for API < 1.19, and InspectResponse
// held fields that were added in API 1.19 and up. Given that the minimum
// supported API version is now 1.24, we no longer use the separate type.