Browse code

Generate ContainerWait response from the swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/10/21 07:56:27
Showing 10 changed files
... ...
@@ -283,8 +283,8 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons
283 283
 		return err
284 284
 	}
285 285
 
286
-	return httputils.WriteJSON(w, http.StatusOK, &types.ContainerWaitResponse{
287
-		StatusCode: status,
286
+	return httputils.WriteJSON(w, http.StatusOK, &container.ContainerWaitOKBody{
287
+		StatusCode: int64(status),
288 288
 	})
289 289
 }
290 290
 
... ...
@@ -3780,18 +3780,19 @@ paths:
3780 3780
     post:
3781 3781
       summary: "Wait for a container"
3782 3782
       description: "Block until a container stops, then returns the exit code."
3783
-      operationId: "PostContainerWait"
3784
-      produces:
3785
-        - "application/json"
3783
+      operationId: "ContainerWait"
3784
+      produces: ["application/json"]
3786 3785
       responses:
3787 3786
         200:
3788
-          description: "no error"
3787
+          description: "The container has exit."
3789 3788
           schema:
3790 3789
             type: "object"
3790
+            required: [StatusCode]
3791 3791
             properties:
3792 3792
               StatusCode:
3793 3793
                 description: "Exit code of the container"
3794 3794
                 type: "integer"
3795
+                x-nullable: false
3795 3796
         404:
3796 3797
           description: "no such container"
3797 3798
           schema:
3798 3799
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+package container
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/swagger-gen.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// ContainerWaitOKBody container wait o k body
10
+// swagger:model ContainerWaitOKBody
11
+type ContainerWaitOKBody struct {
12
+
13
+	// Exit code of the container
14
+	// Required: true
15
+	StatusCode int64 `json:"StatusCode"`
16
+}
... ...
@@ -13,13 +13,6 @@ import (
13 13
 	"github.com/docker/go-connections/nat"
14 14
 )
15 15
 
16
-// ContainerWaitResponse contains response of Remote API:
17
-// POST "/containers/"+containerID+"/wait"
18
-type ContainerWaitResponse struct {
19
-	// StatusCode is the status code of the wait job
20
-	StatusCode int `json:"StatusCode"`
21
-}
22
-
23 16
 // ContainerChange contains response of Remote API:
24 17
 // GET "/containers/{name:.*}/changes"
25 18
 type ContainerChange struct {
... ...
@@ -5,19 +5,19 @@ import (
5 5
 
6 6
 	"golang.org/x/net/context"
7 7
 
8
-	"github.com/docker/docker/api/types"
8
+	"github.com/docker/docker/api/types/container"
9 9
 )
10 10
 
11 11
 // ContainerWait pauses execution until a container exits.
12 12
 // It returns the API status code as response of its readiness.
13
-func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int, error) {
13
+func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int64, error) {
14 14
 	resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil)
15 15
 	if err != nil {
16 16
 		return -1, err
17 17
 	}
18 18
 	defer ensureReaderClosed(resp)
19 19
 
20
-	var res types.ContainerWaitResponse
20
+	var res container.ContainerWaitOKBody
21 21
 	if err := json.NewDecoder(resp.body).Decode(&res); err != nil {
22 22
 		return -1, err
23 23
 	}
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"testing"
12 12
 	"time"
13 13
 
14
-	"github.com/docker/docker/api/types"
14
+	"github.com/docker/docker/api/types/container"
15 15
 
16 16
 	"golang.org/x/net/context"
17 17
 )
... ...
@@ -36,7 +36,7 @@ func TestContainerWait(t *testing.T) {
36 36
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
37 37
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
38 38
 			}
39
-			b, err := json.Marshal(types.ContainerWaitResponse{
39
+			b, err := json.Marshal(container.ContainerWaitOKBody{
40 40
 				StatusCode: 15,
41 41
 			})
42 42
 			if err != nil {
... ...
@@ -59,7 +59,7 @@ type ContainerAPIClient interface {
59 59
 	ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
60 60
 	ContainerUnpause(ctx context.Context, container string) error
61 61
 	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
62
-	ContainerWait(ctx context.Context, container string) (int, error)
62
+	ContainerWait(ctx context.Context, container string) (int64, error)
63 63
 	CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
64 64
 	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
65 65
 	ContainersPrune(ctx context.Context, cfg types.ContainersPruneConfig) (types.ContainersPruneReport, error)
... ...
@@ -23,7 +23,7 @@ type Backend interface {
23 23
 	FindNetwork(idName string) (libnetwork.Network, error)
24 24
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
25 25
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
26
-	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error)
26
+	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
27 27
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
28 28
 	ContainerStop(name string, seconds *int) error
29 29
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
... ...
@@ -17,4 +17,5 @@ swagger generate operation -f api/swagger.yaml \
17 17
     -n VolumesCreate \
18 18
     -n ContainerCreate \
19 19
     -n ContainerUpdate \
20
-    -n Authenticate
20
+    -n Authenticate \
21
+    -n ContainerWait
... ...
@@ -957,9 +957,9 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
957 957
 	c.Assert(status, checker.Equals, http.StatusOK)
958 958
 	c.Assert(waitInspect(name, "{{ .State.Running  }}", "false", 60*time.Second), checker.IsNil)
959 959
 
960
-	var waitres types.ContainerWaitResponse
960
+	var waitres containertypes.ContainerWaitOKBody
961 961
 	c.Assert(json.Unmarshal(body, &waitres), checker.IsNil)
962
-	c.Assert(waitres.StatusCode, checker.Equals, 0)
962
+	c.Assert(waitres.StatusCode, checker.Equals, int64(0))
963 963
 }
964 964
 
965 965
 func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {