Skip to content

Commit 01883c1

Browse files
committed
Add an IDResponse type
Generated from a swagger spec and use it for container exec response Signed-off-by: Daniel Nephin <[email protected]>
1 parent bad849f commit 01883c1

File tree

8 files changed

+31
-26
lines changed

8 files changed

+31
-26
lines changed

api/server/router/container/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
4949
return err
5050
}
5151

52-
return httputils.WriteJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{
52+
return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{
5353
ID: id,
5454
})
5555
}

api/swagger.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,16 @@ definitions:
10751075
example:
10761076
message: "Something went wrong."
10771077

1078+
IdResponse:
1079+
description: "Response to an API call that returns just an Id"
1080+
type: "object"
1081+
required: ["Id"]
1082+
properties:
1083+
Id:
1084+
description: "The id of the newly created object."
1085+
type: "string"
1086+
x-nullable: false
1087+
10781088
EndpointSettings:
10791089
description: "Configuration for a network endpoint."
10801090
type: "object"
@@ -5194,19 +5204,7 @@ paths:
51945204
201:
51955205
description: "no error"
51965206
schema:
5197-
type: "object"
5198-
properties:
5199-
Id:
5200-
description: "The ID of the exec instance created."
5201-
type: "string"
5202-
Warnings:
5203-
type: "array"
5204-
items:
5205-
type: "string"
5206-
examples:
5207-
application/json:
5208-
Id: "f90e34656806"
5209-
Warnings: []
5207+
$ref: "#/definitions/IdResponse"
52105208
404:
52115209
description: "no such container"
52125210
schema:

api/types/id_response.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package types
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
// IDResponse Response to an API call that returns just an Id
7+
// swagger:model IdResponse
8+
type IDResponse struct {
9+
10+
// The id of the newly created object.
11+
// Required: true
12+
ID string `json:"Id"`
13+
}

api/types/types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ import (
1313
"github.com/docker/go-connections/nat"
1414
)
1515

16-
// ContainerExecCreateResponse contains response of Remote API:
17-
// POST "/containers/{name:.*}/exec"
18-
type ContainerExecCreateResponse struct {
19-
// ID is the exec ID.
20-
ID string `json:"Id"`
21-
}
22-
2316
// ContainerUpdateResponse contains response of Remote API:
2417
// POST "/containers/{name:.*}/update"
2518
type ContainerUpdateResponse struct {

client/container_exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

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

client/container_exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestContainerExecCreate(t *testing.T) {
4545
if execConfig.User != "user" {
4646
return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig)
4747
}
48-
b, err := json.Marshal(types.ContainerExecCreateResponse{
48+
b, err := json.Marshal(types.IDResponse{
4949
ID: "exec_id",
5050
})
5151
if err != nil {

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type ContainerAPIClient interface {
3737
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
3838
ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
3939
ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
40-
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
40+
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
4141
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
4242
ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error
4343
ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error

hack/generate-swagger-api.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ swagger generate model -f api/swagger.yaml \
77
-n Port \
88
-n ImageSummary \
99
-n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \
10-
-n ErrorResponse
10+
-n ErrorResponse \
11+
-n IdResponse
1112

1213
swagger generate operation -f api/swagger.yaml \
1314
-t api -a types -m types -C api/swagger-gen.yaml \

0 commit comments

Comments
 (0)