浏览代码

Generate ContainerWait response from the swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 年之前
父节点
当前提交
181562c2e5

+ 2 - 2
api/server/router/container/container_routes.go

@@ -283,8 +283,8 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons
 		return err
 		return err
 	}
 	}
 
 
-	return httputils.WriteJSON(w, http.StatusOK, &types.ContainerWaitResponse{
-		StatusCode: status,
+	return httputils.WriteJSON(w, http.StatusOK, &container.ContainerWaitOKBody{
+		StatusCode: int64(status),
 	})
 	})
 }
 }
 
 

+ 5 - 4
api/swagger.yaml

@@ -3780,18 +3780,19 @@ paths:
     post:
     post:
       summary: "Wait for a container"
       summary: "Wait for a container"
       description: "Block until a container stops, then returns the exit code."
       description: "Block until a container stops, then returns the exit code."
-      operationId: "PostContainerWait"
-      produces:
-        - "application/json"
+      operationId: "ContainerWait"
+      produces: ["application/json"]
       responses:
       responses:
         200:
         200:
-          description: "no error"
+          description: "The container has exit."
           schema:
           schema:
             type: "object"
             type: "object"
+            required: [StatusCode]
             properties:
             properties:
               StatusCode:
               StatusCode:
                 description: "Exit code of the container"
                 description: "Exit code of the container"
                 type: "integer"
                 type: "integer"
+                x-nullable: false
         404:
         404:
           description: "no such container"
           description: "no such container"
           schema:
           schema:

+ 17 - 0
api/types/container/container_wait.go

@@ -0,0 +1,17 @@
+package container
+
+// ----------------------------------------------------------------------------
+// DO NOT EDIT THIS FILE
+// This file was generated by `swagger generate operation`
+//
+// See hack/swagger-gen.sh
+// ----------------------------------------------------------------------------
+
+// ContainerWaitOKBody container wait o k body
+// swagger:model ContainerWaitOKBody
+type ContainerWaitOKBody struct {
+
+	// Exit code of the container
+	// Required: true
+	StatusCode int64 `json:"StatusCode"`
+}

+ 0 - 7
api/types/types.go

@@ -13,13 +13,6 @@ import (
 	"github.com/docker/go-connections/nat"
 	"github.com/docker/go-connections/nat"
 )
 )
 
 
-// ContainerWaitResponse contains response of Remote API:
-// POST "/containers/"+containerID+"/wait"
-type ContainerWaitResponse struct {
-	// StatusCode is the status code of the wait job
-	StatusCode int `json:"StatusCode"`
-}
-
 // ContainerChange contains response of Remote API:
 // ContainerChange contains response of Remote API:
 // GET "/containers/{name:.*}/changes"
 // GET "/containers/{name:.*}/changes"
 type ContainerChange struct {
 type ContainerChange struct {

+ 3 - 3
client/container_wait.go

@@ -5,19 +5,19 @@ import (
 
 
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 
 
-	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/api/types/container"
 )
 )
 
 
 // ContainerWait pauses execution until a container exits.
 // ContainerWait pauses execution until a container exits.
 // It returns the API status code as response of its readiness.
 // It returns the API status code as response of its readiness.
-func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int, error) {
+func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int64, error) {
 	resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil)
 	resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil)
 	if err != nil {
 	if err != nil {
 		return -1, err
 		return -1, err
 	}
 	}
 	defer ensureReaderClosed(resp)
 	defer ensureReaderClosed(resp)
 
 
-	var res types.ContainerWaitResponse
+	var res container.ContainerWaitOKBody
 	if err := json.NewDecoder(resp.body).Decode(&res); err != nil {
 	if err := json.NewDecoder(resp.body).Decode(&res); err != nil {
 		return -1, err
 		return -1, err
 	}
 	}

+ 2 - 2
client/container_wait_test.go

@@ -11,7 +11,7 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
-	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/api/types/container"
 
 
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
@@ -36,7 +36,7 @@ func TestContainerWait(t *testing.T) {
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
 			}
 			}
-			b, err := json.Marshal(types.ContainerWaitResponse{
+			b, err := json.Marshal(container.ContainerWaitOKBody{
 				StatusCode: 15,
 				StatusCode: 15,
 			})
 			})
 			if err != nil {
 			if err != nil {

+ 1 - 1
client/interface.go

@@ -59,7 +59,7 @@ type ContainerAPIClient interface {
 	ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
 	ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
 	ContainerUnpause(ctx context.Context, container string) error
 	ContainerUnpause(ctx context.Context, container string) error
 	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
 	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
-	ContainerWait(ctx context.Context, container string) (int, error)
+	ContainerWait(ctx context.Context, container string) (int64, error)
 	CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
 	CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
 	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
 	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
 	ContainersPrune(ctx context.Context, cfg types.ContainersPruneConfig) (types.ContainersPruneReport, error)
 	ContainersPrune(ctx context.Context, cfg types.ContainersPruneConfig) (types.ContainersPruneReport, error)

+ 1 - 1
daemon/cluster/executor/backend.go

@@ -23,7 +23,7 @@ type Backend interface {
 	FindNetwork(idName string) (libnetwork.Network, error)
 	FindNetwork(idName string) (libnetwork.Network, error)
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
-	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error)
+	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
 	ContainerStop(name string, seconds *int) error
 	ContainerStop(name string, seconds *int) error
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error

+ 2 - 1
hack/generate-swagger-api.sh

@@ -17,4 +17,5 @@ swagger generate operation -f api/swagger.yaml \
     -n VolumesCreate \
     -n VolumesCreate \
     -n ContainerCreate \
     -n ContainerCreate \
     -n ContainerUpdate \
     -n ContainerUpdate \
-    -n Authenticate
+    -n Authenticate \
+    -n ContainerWait

+ 2 - 2
integration-cli/docker_api_containers_test.go

@@ -957,9 +957,9 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
 	c.Assert(status, checker.Equals, http.StatusOK)
 	c.Assert(status, checker.Equals, http.StatusOK)
 	c.Assert(waitInspect(name, "{{ .State.Running  }}", "false", 60*time.Second), checker.IsNil)
 	c.Assert(waitInspect(name, "{{ .State.Running  }}", "false", 60*time.Second), checker.IsNil)
 
 
-	var waitres types.ContainerWaitResponse
+	var waitres containertypes.ContainerWaitOKBody
 	c.Assert(json.Unmarshal(body, &waitres), checker.IsNil)
 	c.Assert(json.Unmarshal(body, &waitres), checker.IsNil)
-	c.Assert(waitres.StatusCode, checker.Equals, 0)
+	c.Assert(waitres.StatusCode, checker.Equals, int64(0))
 }
 }
 
 
 func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {
 func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {