Browse code

Generate ImageHistory from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/11/10 06:32:53
Showing 10 changed files
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"github.com/docker/docker/api/types"
7 7
 	"github.com/docker/docker/api/types/backend"
8 8
 	"github.com/docker/docker/api/types/filters"
9
+	"github.com/docker/docker/api/types/image"
9 10
 	"github.com/docker/docker/api/types/registry"
10 11
 	"golang.org/x/net/context"
11 12
 )
... ...
@@ -25,7 +26,7 @@ type containerBackend interface {
25 25
 
26 26
 type imageBackend interface {
27 27
 	ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error)
28
-	ImageHistory(imageName string) ([]*types.ImageHistory, error)
28
+	ImageHistory(imageName string) ([]*image.HistoryResponseItem, error)
29 29
 	Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error)
30 30
 	LookupImage(name string) (*types.ImageInspect, error)
31 31
 	TagImage(imageName, repository, tag string) error
... ...
@@ -4627,23 +4627,27 @@ paths:
4627 4627
       summary: "Get the history of an image"
4628 4628
       description: "Return parent layers of an image."
4629 4629
       operationId: "ImageHistory"
4630
-      produces:
4631
-        - "application/json"
4630
+      produces: ["application/json"]
4632 4631
       responses:
4633 4632
         200:
4634
-          description: "No error"
4633
+          description: "List of image layers"
4635 4634
           schema:
4636 4635
             type: "array"
4637 4636
             items:
4638 4637
               type: "object"
4638
+              x-go-name: HistoryResponseItem
4639
+              required: [Id, Created, CreatedBy, Tags, Size, Comment]
4639 4640
               properties:
4640 4641
                 Id:
4641 4642
                   type: "string"
4643
+                  x-nullable: false
4642 4644
                 Created:
4643 4645
                   type: "integer"
4644 4646
                   format: "int64"
4647
+                  x-nullable: false
4645 4648
                 CreatedBy:
4646 4649
                   type: "string"
4650
+                  x-nullable: false
4647 4651
                 Tags:
4648 4652
                   type: "array"
4649 4653
                   items:
... ...
@@ -4651,8 +4655,10 @@ paths:
4651 4651
                 Size:
4652 4652
                   type: "integer"
4653 4653
                   format: "int64"
4654
+                  x-nullable: false
4654 4655
                 Comment:
4655 4656
                   type: "string"
4657
+                  x-nullable: false
4656 4658
           examples:
4657 4659
             application/json:
4658 4660
               - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710"
4659 4661
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+package image
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/swagger-gen.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// HistoryResponseItem history response item
10
+// swagger:model HistoryResponseItem
11
+type HistoryResponseItem struct {
12
+
13
+	// comment
14
+	// Required: true
15
+	Comment string `json:"Comment"`
16
+
17
+	// created
18
+	// Required: true
19
+	Created int64 `json:"Created"`
20
+
21
+	// created by
22
+	// Required: true
23
+	CreatedBy string `json:"CreatedBy"`
24
+
25
+	// Id
26
+	// Required: true
27
+	ID string `json:"Id"`
28
+
29
+	// size
30
+	// Required: true
31
+	Size int64 `json:"Size"`
32
+
33
+	// tags
34
+	// Required: true
35
+	Tags []string `json:"Tags"`
36
+}
... ...
@@ -17,18 +17,6 @@ import (
17 17
 	"github.com/docker/go-connections/nat"
18 18
 )
19 19
 
20
-
21
-// ImageHistory contains response of Engine API:
22
-// GET "/images/{name:.*}/history"
23
-type ImageHistory struct {
24
-	ID        string `json:"Id"`
25
-	Created   int64
26
-	CreatedBy string
27
-	Tags      []string
28
-	Size      int64
29
-	Comment   string
30
-}
31
-
32 20
 // ImageDelete contains response of Engine API:
33 21
 // DELETE "/images/{name:.*}"
34 22
 type ImageDelete struct {
... ...
@@ -4,13 +4,13 @@ import (
4 4
 	"encoding/json"
5 5
 	"net/url"
6 6
 
7
-	"github.com/docker/docker/api/types"
7
+	"github.com/docker/docker/api/types/image"
8 8
 	"golang.org/x/net/context"
9 9
 )
10 10
 
11 11
 // ImageHistory returns the changes in an image in history format.
12
-func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error) {
13
-	var history []types.ImageHistory
12
+func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]image.HistoryResponseItem, error) {
13
+	var history []image.HistoryResponseItem
14 14
 	serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil)
15 15
 	if err != nil {
16 16
 		return history, err
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/docker/docker/api/types"
12
+	"github.com/docker/docker/api/types/image"
13 13
 	"golang.org/x/net/context"
14 14
 )
15 15
 
... ...
@@ -30,7 +30,7 @@ func TestImageHistory(t *testing.T) {
30 30
 			if !strings.HasPrefix(r.URL.Path, expectedURL) {
31 31
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
32 32
 			}
33
-			b, err := json.Marshal([]types.ImageHistory{
33
+			b, err := json.Marshal([]image.HistoryResponseItem{
34 34
 				{
35 35
 					ID:   "image_id1",
36 36
 					Tags: []string{"tag1", "tag2"},
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/docker/api/types/events"
10 10
 	"github.com/docker/docker/api/types/filters"
11
+	"github.com/docker/docker/api/types/image"
11 12
 	"github.com/docker/docker/api/types/network"
12 13
 	"github.com/docker/docker/api/types/registry"
13 14
 	"github.com/docker/docker/api/types/swarm"
... ...
@@ -71,7 +72,7 @@ type ContainerAPIClient interface {
71 71
 type ImageAPIClient interface {
72 72
 	ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
73 73
 	ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
74
-	ImageHistory(ctx context.Context, image string) ([]types.ImageHistory, error)
74
+	ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
75 75
 	ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error)
76 76
 	ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
77 77
 	ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
... ...
@@ -4,21 +4,21 @@ import (
4 4
 	"fmt"
5 5
 	"time"
6 6
 
7
-	"github.com/docker/docker/api/types"
7
+	"github.com/docker/docker/api/types/image"
8 8
 	"github.com/docker/docker/layer"
9 9
 	"github.com/docker/docker/reference"
10 10
 )
11 11
 
12 12
 // ImageHistory returns a slice of ImageHistory structures for the specified image
13 13
 // name by walking the image lineage.
14
-func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
14
+func (daemon *Daemon) ImageHistory(name string) ([]*image.HistoryResponseItem, error) {
15 15
 	start := time.Now()
16 16
 	img, err := daemon.GetImage(name)
17 17
 	if err != nil {
18 18
 		return nil, err
19 19
 	}
20 20
 
21
-	history := []*types.ImageHistory{}
21
+	history := []*image.HistoryResponseItem{}
22 22
 
23 23
 	layerCounter := 0
24 24
 	rootFS := *img.RootFS
... ...
@@ -46,7 +46,7 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
46 46
 			layerCounter++
47 47
 		}
48 48
 
49
-		history = append([]*types.ImageHistory{{
49
+		history = append([]*image.HistoryResponseItem{{
50 50
 			ID:        "<missing>",
51 51
 			Created:   h.Created.Unix(),
52 52
 			CreatedBy: h.CreatedBy,
... ...
@@ -14,10 +14,11 @@ swagger generate model -f api/swagger.yaml \
14 14
 swagger generate operation -f api/swagger.yaml \
15 15
     -t api -a types -m types -C api/swagger-gen.yaml \
16 16
     -T api/templates --skip-responses --skip-parameters --skip-validator \
17
-    -n VolumesList \
18
-    -n VolumesCreate \
17
+    -n Authenticate \
19 18
     -n ContainerChanges \
20 19
     -n ContainerCreate \
21 20
     -n ContainerUpdate \
22
-    -n Authenticate \
23
-    -n ContainerWait
21
+    -n ContainerWait \
22
+    -n ImageHistory \
23
+    -n VolumesCreate \
24
+    -n VolumesList
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"strings"
8 8
 
9 9
 	"github.com/docker/docker/api/types"
10
+	"github.com/docker/docker/api/types/image"
10 11
 	"github.com/docker/docker/integration-cli/checker"
11 12
 	"github.com/go-check/check"
12 13
 )
... ...
@@ -109,7 +110,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
109 109
 	c.Assert(err, checker.IsNil)
110 110
 	c.Assert(status, checker.Equals, http.StatusOK)
111 111
 
112
-	var historydata []types.ImageHistory
112
+	var historydata []image.HistoryResponseItem
113 113
 	err = json.Unmarshal(body, &historydata)
114 114
 	c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
115 115