Browse Source

Add an IDResponse type

Generated from a swagger spec and use it for container exec response

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 năm trước cách đây
mục cha
commit
01883c136d

+ 1 - 1
api/server/router/container/exec.go

@@ -49,7 +49,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
 		return err
 		return err
 	}
 	}
 
 
-	return httputils.WriteJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{
+	return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{
 		ID: id,
 		ID: id,
 	})
 	})
 }
 }

+ 11 - 13
api/swagger.yaml

@@ -1075,6 +1075,16 @@ definitions:
     example:
     example:
       message: "Something went wrong."
       message: "Something went wrong."
 
 
+  IdResponse:
+    description: "Response to an API call that returns just an Id"
+    type: "object"
+    required: ["Id"]
+    properties:
+      Id:
+        description: "The id of the newly created object."
+        type: "string"
+        x-nullable: false
+
   EndpointSettings:
   EndpointSettings:
     description: "Configuration for a network endpoint."
     description: "Configuration for a network endpoint."
     type: "object"
     type: "object"
@@ -5194,19 +5204,7 @@ paths:
         201:
         201:
           description: "no error"
           description: "no error"
           schema:
           schema:
-            type: "object"
-            properties:
-              Id:
-                description: "The ID of the exec instance created."
-                type: "string"
-              Warnings:
-                type: "array"
-                items:
-                  type: "string"
-          examples:
-            application/json:
-              Id: "f90e34656806"
-              Warnings: []
+            $ref: "#/definitions/IdResponse"
         404:
         404:
           description: "no such container"
           description: "no such container"
           schema:
           schema:

+ 13 - 0
api/types/id_response.go

@@ -0,0 +1,13 @@
+package types
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the swagger generate command
+
+// IDResponse Response to an API call that returns just an Id
+// swagger:model IdResponse
+type IDResponse struct {
+
+	// The id of the newly created object.
+	// Required: true
+	ID string `json:"Id"`
+}

+ 0 - 7
api/types/types.go

@@ -13,13 +13,6 @@ import (
 	"github.com/docker/go-connections/nat"
 	"github.com/docker/go-connections/nat"
 )
 )
 
 
-// ContainerExecCreateResponse contains response of Remote API:
-// POST "/containers/{name:.*}/exec"
-type ContainerExecCreateResponse struct {
-	// ID is the exec ID.
-	ID string `json:"Id"`
-}
-
 // ContainerUpdateResponse contains response of Remote API:
 // ContainerUpdateResponse contains response of Remote API:
 // POST "/containers/{name:.*}/update"
 // POST "/containers/{name:.*}/update"
 type ContainerUpdateResponse struct {
 type ContainerUpdateResponse struct {

+ 2 - 2
client/container_exec.go

@@ -8,8 +8,8 @@ import (
 )
 )
 
 
 // ContainerExecCreate creates a new exec configuration to run an exec process.
 // ContainerExecCreate creates a new exec configuration to run an exec process.
-func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) {
-	var response types.ContainerExecCreateResponse
+func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) {
+	var response types.IDResponse
 	resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil)
 	resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil)
 	if err != nil {
 	if err != nil {
 		return response, err
 		return response, err

+ 1 - 1
client/container_exec_test.go

@@ -45,7 +45,7 @@ func TestContainerExecCreate(t *testing.T) {
 			if execConfig.User != "user" {
 			if execConfig.User != "user" {
 				return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig)
 				return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig)
 			}
 			}
-			b, err := json.Marshal(types.ContainerExecCreateResponse{
+			b, err := json.Marshal(types.IDResponse{
 				ID: "exec_id",
 				ID: "exec_id",
 			})
 			})
 			if err != nil {
 			if err != nil {

+ 1 - 1
client/interface.go

@@ -37,7 +37,7 @@ type ContainerAPIClient interface {
 	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
 	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
 	ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
 	ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
 	ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
 	ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
-	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
+	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
 	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
 	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
 	ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error
 	ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error
 	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
 	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error

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

@@ -7,7 +7,8 @@ swagger generate model -f api/swagger.yaml \
     -n Port \
     -n Port \
     -n ImageSummary \
     -n ImageSummary \
     -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \
     -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \
-    -n ErrorResponse
+    -n ErrorResponse \
+    -n IdResponse
 
 
 swagger generate operation -f api/swagger.yaml \
 swagger generate operation -f api/swagger.yaml \
     -t api -a types -m types -C api/swagger-gen.yaml \
     -t api -a types -m types -C api/swagger-gen.yaml \