diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go index 19a67a5ed0..08cde8829c 100644 --- a/api/server/router/image/backend.go +++ b/api/server/router/image/backend.go @@ -6,6 +6,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "golang.org/x/net/context" ) @@ -25,7 +26,7 @@ type containerBackend interface { type imageBackend interface { ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) - ImageHistory(imageName string) ([]*types.ImageHistory, error) + ImageHistory(imageName string) ([]*image.HistoryResponseItem, error) Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error) LookupImage(name string) (*types.ImageInspect, error) TagImage(imageName, repository, tag string) error diff --git a/api/swagger.yaml b/api/swagger.yaml index 3406f1ef7f..f1f3cfe1be 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4627,23 +4627,27 @@ paths: summary: "Get the history of an image" description: "Return parent layers of an image." operationId: "ImageHistory" - produces: - - "application/json" + produces: ["application/json"] responses: 200: - description: "No error" + description: "List of image layers" schema: type: "array" items: type: "object" + x-go-name: HistoryResponseItem + required: [Id, Created, CreatedBy, Tags, Size, Comment] properties: Id: type: "string" + x-nullable: false Created: type: "integer" format: "int64" + x-nullable: false CreatedBy: type: "string" + x-nullable: false Tags: type: "array" items: @@ -4651,8 +4655,10 @@ paths: Size: type: "integer" format: "int64" + x-nullable: false Comment: type: "string" + x-nullable: false examples: application/json: - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710" diff --git a/api/types/image/image_history.go b/api/types/image/image_history.go new file mode 100644 index 0000000000..6c56802488 --- /dev/null +++ b/api/types/image/image_history.go @@ -0,0 +1,37 @@ +package image + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// HistoryResponseItem history response item +// swagger:model HistoryResponseItem +type HistoryResponseItem struct { + + // comment + // Required: true + Comment string `json:"Comment"` + + // created + // Required: true + Created int64 `json:"Created"` + + // created by + // Required: true + CreatedBy string `json:"CreatedBy"` + + // Id + // Required: true + ID string `json:"Id"` + + // size + // Required: true + Size int64 `json:"Size"` + + // tags + // Required: true + Tags []string `json:"Tags"` +} diff --git a/api/types/types.go b/api/types/types.go index e0efc8021f..b98399e700 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -17,18 +17,6 @@ import ( "github.com/docker/go-connections/nat" ) - -// ImageHistory contains response of Engine API: -// GET "/images/{name:.*}/history" -type ImageHistory struct { - ID string `json:"Id"` - Created int64 - CreatedBy string - Tags []string - Size int64 - Comment string -} - // ImageDelete contains response of Engine API: // DELETE "/images/{name:.*}" type ImageDelete struct { diff --git a/client/image_history.go b/client/image_history.go index acb1ee9278..7b4babcba3 100644 --- a/client/image_history.go +++ b/client/image_history.go @@ -4,13 +4,13 @@ import ( "encoding/json" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "golang.org/x/net/context" ) // ImageHistory returns the changes in an image in history format. -func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error) { - var history []types.ImageHistory +func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]image.HistoryResponseItem, error) { + var history []image.HistoryResponseItem serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil) if err != nil { return history, err diff --git a/client/image_history_test.go b/client/image_history_test.go index 729edb1ad5..101bffd0c3 100644 --- a/client/image_history_test.go +++ b/client/image_history_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "golang.org/x/net/context" ) @@ -30,7 +30,7 @@ func TestImageHistory(t *testing.T) { if !strings.HasPrefix(r.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) } - b, err := json.Marshal([]types.ImageHistory{ + b, err := json.Marshal([]image.HistoryResponseItem{ { ID: "image_id1", Tags: []string{"tag1", "tag2"}, diff --git a/client/interface.go b/client/interface.go index 5e1b63b39d..742f9a6c17 100644 --- a/client/interface.go +++ b/client/interface.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" @@ -71,7 +72,7 @@ type ContainerAPIClient interface { type ImageAPIClient interface { ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) - ImageHistory(ctx context.Context, image string) ([]types.ImageHistory, error) + ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) diff --git a/daemon/image_history.go b/daemon/image_history.go index 839dd1283b..9e544963b1 100644 --- a/daemon/image_history.go +++ b/daemon/image_history.go @@ -4,21 +4,21 @@ import ( "fmt" "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/layer" "github.com/docker/docker/reference" ) // ImageHistory returns a slice of ImageHistory structures for the specified image // name by walking the image lineage. -func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { +func (daemon *Daemon) ImageHistory(name string) ([]*image.HistoryResponseItem, error) { start := time.Now() img, err := daemon.GetImage(name) if err != nil { return nil, err } - history := []*types.ImageHistory{} + history := []*image.HistoryResponseItem{} layerCounter := 0 rootFS := *img.RootFS @@ -46,7 +46,7 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { layerCounter++ } - history = append([]*types.ImageHistory{{ + history = append([]*image.HistoryResponseItem{{ ID: "", Created: h.Created.Unix(), CreatedBy: h.CreatedBy, diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 47f6bcfeb8..be48a09bef 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -14,10 +14,11 @@ swagger generate model -f api/swagger.yaml \ swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ - -n VolumesList \ - -n VolumesCreate \ + -n Authenticate \ -n ContainerChanges \ -n ContainerCreate \ -n ContainerUpdate \ - -n Authenticate \ - -n ContainerWait + -n ContainerWait \ + -n ImageHistory \ + -n VolumesCreate \ + -n VolumesList diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index 6b24a39122..a8de4725b3 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" ) @@ -109,7 +110,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) - var historydata []types.ImageHistory + var historydata []image.HistoryResponseItem err = json.Unmarshal(body, &historydata) c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))