Generate ImageHistory from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-11-09 16:32:53 -05:00
parent b83d9bf6a9
commit b462c93edb
10 changed files with 66 additions and 31 deletions

View File

@ -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

View File

@ -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"

View File

@ -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"`
}

View File

@ -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 {

View File

@ -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

View File

@ -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"},

View File

@ -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)

View File

@ -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: "<missing>",
Created: h.Created.Unix(),
CreatedBy: h.CreatedBy,

View File

@ -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

View File

@ -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"))