From 01883c136d9ef06962d80aa81e27d1d90eb6d199 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 15:56:45 -0700 Subject: [PATCH] Add an IDResponse type Generated from a swagger spec and use it for container exec response Signed-off-by: Daniel Nephin --- api/server/router/container/exec.go | 2 +- api/swagger.yaml | 24 +++++++++++------------- api/types/id_response.go | 13 +++++++++++++ api/types/types.go | 7 ------- client/container_exec.go | 4 ++-- client/container_exec_test.go | 2 +- client/interface.go | 2 +- hack/generate-swagger-api.sh | 3 ++- 8 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 api/types/id_response.go diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go index f840e54d70..8d49de7dac 100644 --- a/api/server/router/container/exec.go +++ b/api/server/router/container/exec.go @@ -49,7 +49,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re return err } - return httputils.WriteJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{ + return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ ID: id, }) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 9d106b9dbf..d624790eee 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1075,6 +1075,16 @@ definitions: example: 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: description: "Configuration for a network endpoint." type: "object" @@ -5194,19 +5204,7 @@ paths: 201: description: "no error" 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: description: "no such container" schema: diff --git a/api/types/id_response.go b/api/types/id_response.go new file mode 100644 index 0000000000..7592d2f8b1 --- /dev/null +++ b/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"` +} diff --git a/api/types/types.go b/api/types/types.go index e06dcc853b..33c4f26a62 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,13 +13,6 @@ import ( "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: // POST "/containers/{name:.*}/update" type ContainerUpdateResponse struct { diff --git a/client/container_exec.go b/client/container_exec.go index 34173d3194..f6df722918 100644 --- a/client/container_exec.go +++ b/client/container_exec.go @@ -8,8 +8,8 @@ import ( ) // 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) if err != nil { return response, err diff --git a/client/container_exec_test.go b/client/container_exec_test.go index 42146ae8a5..0e296a50ad 100644 --- a/client/container_exec_test.go +++ b/client/container_exec_test.go @@ -45,7 +45,7 @@ func TestContainerExecCreate(t *testing.T) { if execConfig.User != "user" { 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", }) if err != nil { diff --git a/client/interface.go b/client/interface.go index 8f8bbaf55f..0575ce5c3b 100644 --- a/client/interface.go +++ b/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) ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, 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) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index a5c02b10bc..13977dbb8c 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -7,7 +7,8 @@ swagger generate model -f api/swagger.yaml \ -n Port \ -n ImageSummary \ -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ - -n ErrorResponse + -n ErrorResponse \ + -n IdResponse swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \