diff --git a/Makefile b/Makefile index 725559c71c..a2a1e6ad82 100644 --- a/Makefile +++ b/Makefile @@ -142,4 +142,5 @@ win: build ## cross build the binary for windows swagger-gen: docker run --rm -v $(PWD):/work -w /work quay.io/goswagger/swagger \ generate model -m "types" -f api/swagger.yaml -t api/ --skip-validator \ - -n Volume + -n Volume \ + -n Port diff --git a/api/common.go b/api/common.go index 2cb538e3a2..a42f7a6128 100644 --- a/api/common.go +++ b/api/common.go @@ -20,7 +20,7 @@ import ( // Common constants for daemon and client. const ( - // Version of Current REST API + // DefaultVersion of Current REST API DefaultVersion string = "1.25" // MinVersion represents Minimum REST API version supported @@ -57,8 +57,8 @@ func (r byPortInfo) Less(i, j int) bool { // it's used by command 'docker ps' func DisplayablePorts(ports []types.Port) string { type portGroup struct { - first int - last int + first uint16 + last uint16 } groupMap := make(map[string]*portGroup) var result []string @@ -99,7 +99,7 @@ func DisplayablePorts(ports []types.Port) string { return strings.Join(result, ", ") } -func formGroup(key string, start, last int) string { +func formGroup(key string, start, last uint16) string { parts := strings.Split(key, "/") groupType := parts[0] var ip string @@ -107,7 +107,7 @@ func formGroup(key string, start, last int) string { ip = parts[0] groupType = parts[1] } - group := strconv.Itoa(start) + group := strconv.Itoa(int(start)) if start != last { group = fmt.Sprintf("%s-%d", group, last) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 0f49e39ab1..3e63fc2db0 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -62,20 +62,28 @@ definitions: Port: type: "object" description: "An open port on a container" + required: [PrivatePort, Type] properties: IP: type: "string" + format: "ip-address" PrivatePort: type: "integer" + format: "uint16" + x-nullable: false description: "Port on the container" PublicPort: type: "integer" + format: "uint16" description: "Port exposed on the host" Type: type: "string" - enum: - - "tcp" - - "udp" + x-nullable: false + enum: ["tcp", "udp"] + example: + PrivatePort: 8080 + PublicPort: 80 + Type: "tcp" MountPoint: type: "object" description: "A mount point inside a container" diff --git a/api/types/port.go b/api/types/port.go new file mode 100644 index 0000000000..ad52d46d56 --- /dev/null +++ b/api/types/port.go @@ -0,0 +1,23 @@ +package types + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// Port An open port on a container +// swagger:model Port +type Port struct { + + // IP + IP string `json:"IP,omitempty"` + + // Port on the container + // Required: true + PrivatePort uint16 `json:"PrivatePort"` + + // Port exposed on the host + PublicPort uint16 `json:"PublicPort,omitempty"` + + // type + // Required: true + Type string `json:"Type"` +} diff --git a/api/types/types.go b/api/types/types.go index 29b8e23dde..42df042394 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -138,15 +138,6 @@ type ImageInspect struct { RootFS RootFS } -// Port stores open ports info of container -// e.g. {"PrivatePort": 8080, "PublicPort": 80, "Type": "tcp"} -type Port struct { - IP string `json:",omitempty"` - PrivatePort int - PublicPort int `json:",omitempty"` - Type string -} - // Container contains response of Remote API: // GET "/containers/json" type Container struct { diff --git a/daemon/list.go b/daemon/list.go index 3b27102e14..9d9f1d5e3a 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -519,7 +519,7 @@ func (daemon *Daemon) transformContainer(container *container.Container, ctx *li } if len(bindings) == 0 { newC.Ports = append(newC.Ports, types.Port{ - PrivatePort: p, + PrivatePort: uint16(p), Type: port.Proto(), }) continue @@ -530,8 +530,8 @@ func (daemon *Daemon) transformContainer(container *container.Container, ctx *li return nil, err } newC.Ports = append(newC.Ports, types.Port{ - PrivatePort: p, - PublicPort: h, + PrivatePort: uint16(p), + PublicPort: uint16(h), Type: port.Proto(), IP: binding.HostIP, })