Skip to content

Commit 0df3a00

Browse files
committed
api/types/container: introduce CommitResponse type
Move api/types.IDResponse to a "common" package (to prevent cyclic import issues), and introduce a container.CommitResponse type as alias. This allows consumers to use ContainerCommit without having to import the "types" package, and allows us to differentiate the response for container commit separate from other endpoints currently using IDResponse. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 8ca7679 commit 0df3a00

9 files changed

Lines changed: 31 additions & 18 deletions

File tree

api/server/router/container/container_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *containerRouter) postCommit(ctx context.Context, w http.ResponseWriter,
7171
return err
7272
}
7373

74-
return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ID: imgID})
74+
return httputils.WriteJSON(w, http.StatusCreated, &container.CommitResponse{ID: imgID})
7575
}
7676

7777
func (c *containerRouter) getContainersJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {

api/swagger.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,9 +2908,10 @@ definitions:
29082908
example:
29092909
message: "Something went wrong."
29102910

2911-
IdResponse:
2911+
IDResponse:
29122912
description: "Response to an API call that returns just an Id"
29132913
type: "object"
2914+
x-go-name: "IDResponse"
29142915
required: ["Id"]
29152916
properties:
29162917
Id:
@@ -10220,7 +10221,7 @@ paths:
1022010221
201:
1022110222
description: "no error"
1022210223
schema:
10223-
$ref: "#/definitions/IdResponse"
10224+
$ref: "#/definitions/IDResponse"
1022410225
404:
1022510226
description: "no such container"
1022610227
schema:
@@ -10614,7 +10615,7 @@ paths:
1061410615
201:
1061510616
description: "no error"
1061610617
schema:
10617-
$ref: "#/definitions/IdResponse"
10618+
$ref: "#/definitions/IDResponse"
1061810619
404:
1061910620
description: "no such container"
1062010621
schema:
@@ -13094,7 +13095,7 @@ paths:
1309413095
201:
1309513096
description: "no error"
1309613097
schema:
13097-
$ref: "#/definitions/IdResponse"
13098+
$ref: "#/definitions/IDResponse"
1309813099
409:
1309913100
description: "name conflicts with an existing object"
1310013101
schema:
@@ -13301,7 +13302,7 @@ paths:
1330113302
201:
1330213303
description: "no error"
1330313304
schema:
13304-
$ref: "#/definitions/IdResponse"
13305+
$ref: "#/definitions/IDResponse"
1330513306
409:
1330613307
description: "name conflicts with an existing object"
1330713308
schema:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package types
1+
package common
22

33
// This file was generated by the swagger tool.
44
// Editing this file might prove futile when you re-run the swagger generate command
55

66
// IDResponse Response to an API call that returns just an Id
7-
// swagger:model IdResponse
7+
// swagger:model IDResponse
88
type IDResponse struct {
99

1010
// The id of the newly created object.

api/types/container/commit.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package container
2+
3+
import "github.com/docker/docker/api/types/common"
4+
5+
// CommitResponse response for the commit API call, containing the ID of the
6+
// image that was produced.
7+
type CommitResponse = common.IDResponse

api/types/types_deprecated.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ package types
33
import (
44
"context"
55

6+
"github.com/docker/docker/api/types/common"
67
"github.com/docker/docker/api/types/container"
78
"github.com/docker/docker/api/types/image"
89
"github.com/docker/docker/api/types/storage"
910
)
1011

12+
// IDResponse Response to an API call that returns just an Id
13+
type IDResponse = common.IDResponse
14+
1115
// ContainerJSONBase contains response of Engine API GET "/containers/{name:.*}/json"
1216
// for API version 1.18 and older.
1317
//

client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type HijackDialer interface {
6969
// ContainerAPIClient defines API client methods for the containers
7070
type ContainerAPIClient interface {
7171
ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error)
72-
ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (types.IDResponse, error)
72+
ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (container.CommitResponse, error)
7373
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
7474
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
7575
ContainerExecAttach(ctx context.Context, execID string, options container.ExecAttachOptions) (types.HijackedResponse, error)

client/container_commit.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@ import (
77
"net/url"
88

99
"github.com/distribution/reference"
10-
"github.com/docker/docker/api/types"
1110
"github.com/docker/docker/api/types/container"
1211
)
1312

1413
// ContainerCommit applies changes to a container and creates a new tagged image.
15-
func (cli *Client) ContainerCommit(ctx context.Context, containerID string, options container.CommitOptions) (types.IDResponse, error) {
14+
func (cli *Client) ContainerCommit(ctx context.Context, containerID string, options container.CommitOptions) (container.CommitResponse, error) {
1615
containerID, err := trimID("container", containerID)
1716
if err != nil {
18-
return types.IDResponse{}, err
17+
return container.CommitResponse{}, err
1918
}
2019

2120
var repository, tag string
2221
if options.Reference != "" {
2322
ref, err := reference.ParseNormalizedNamed(options.Reference)
2423
if err != nil {
25-
return types.IDResponse{}, err
24+
return container.CommitResponse{}, err
2625
}
2726

2827
if _, isCanonical := ref.(reference.Canonical); isCanonical {
29-
return types.IDResponse{}, errors.New("refusing to create a tag with a digest reference")
28+
return container.CommitResponse{}, errors.New("refusing to create a tag with a digest reference")
3029
}
3130
ref = reference.TagNameOnly(ref)
3231

@@ -49,7 +48,7 @@ func (cli *Client) ContainerCommit(ctx context.Context, containerID string, opti
4948
query.Set("pause", "0")
5049
}
5150

52-
var response types.IDResponse
51+
var response container.CommitResponse
5352
resp, err := cli.post(ctx, "/commit", query, options.Config, nil)
5453
defer ensureReaderClosed(resp)
5554
if err != nil {

client/container_commit_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
1514
"github.com/docker/docker/errdefs"
1615
"gotest.tools/v3/assert"
@@ -77,7 +76,7 @@ func TestContainerCommit(t *testing.T) {
7776
if len(changes) != len(expectedChanges) {
7877
return nil, fmt.Errorf("expected container changes size to be '%d', got %d", len(expectedChanges), len(changes))
7978
}
80-
b, err := json.Marshal(types.IDResponse{
79+
b, err := json.Marshal(container.CommitResponse{
8180
ID: "new_container_id",
8281
})
8382
if err != nil {

hack/generate-swagger-api.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ set -eu
44
swagger generate model -f api/swagger.yaml \
55
-t api -m types --skip-validator -C api/swagger-gen.yaml \
66
-n ErrorResponse \
7-
-n IdResponse \
87
-n Plugin \
98
-n PluginDevice \
109
-n PluginMount \
1110
-n PluginEnv \
1211
-n PluginInterfaceType
1312

13+
swagger generate model -f api/swagger.yaml \
14+
-t api -m types/common --skip-validator -C api/swagger-gen.yaml \
15+
-n IDResponse
16+
1417
swagger generate model -f api/swagger.yaml \
1518
-t api -m types/storage --skip-validator -C api/swagger-gen.yaml \
1619
-n DriverData

0 commit comments

Comments
 (0)