Merge pull request #27117 from dnephin/swagger-gen

Add swagger.yaml and generate a few types from the spec
This commit is contained in:
Sebastiaan van Stijn 2016-10-21 18:15:28 -07:00 committed by GitHub
commit 0f7cb7208c
3 changed files with 16 additions and 16 deletions

View File

@ -31,7 +31,7 @@ type DiskUsageContext struct {
Context Context
Verbose bool Verbose bool
LayersSize int64 LayersSize int64
Images []*types.Image Images []*types.ImageSummary
Containers []*types.Container Containers []*types.Container
Volumes []*types.Volume Volumes []*types.Volume
} }
@ -155,7 +155,7 @@ func (ctx *DiskUsageContext) Write() {
type diskUsageImagesContext struct { type diskUsageImagesContext struct {
HeaderContext HeaderContext
totalSize int64 totalSize int64
images []*types.Image images []*types.ImageSummary
} }
func (c *diskUsageImagesContext) Type() string { func (c *diskUsageImagesContext) Type() string {

View File

@ -26,7 +26,7 @@ type ImageContext struct {
Digest bool Digest bool
} }
func isDangling(image types.Image) bool { func isDangling(image types.ImageSummary) bool {
return len(image.RepoTags) == 1 && image.RepoTags[0] == "<none>:<none>" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "<none>@<none>" return len(image.RepoTags) == 1 && image.RepoTags[0] == "<none>:<none>" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "<none>@<none>"
} }
@ -72,14 +72,14 @@ virtual_size: {{.Size}}
} }
// ImageWrite writes the formatter images using the ImageContext // ImageWrite writes the formatter images using the ImageContext
func ImageWrite(ctx ImageContext, images []types.Image) error { func ImageWrite(ctx ImageContext, images []types.ImageSummary) error {
render := func(format func(subContext subContext) error) error { render := func(format func(subContext subContext) error) error {
return imageFormat(ctx, images, format) return imageFormat(ctx, images, format)
} }
return ctx.Write(&imageContext{}, render) return ctx.Write(&imageContext{}, render)
} }
func imageFormat(ctx ImageContext, images []types.Image, format func(subContext subContext) error) error { func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subContext subContext) error) error {
for _, image := range images { for _, image := range images {
images := []*imageContext{} images := []*imageContext{}
if isDangling(image) { if isDangling(image) {
@ -184,7 +184,7 @@ func imageFormat(ctx ImageContext, images []types.Image, format func(subContext
type imageContext struct { type imageContext struct {
HeaderContext HeaderContext
trunc bool trunc bool
i types.Image i types.ImageSummary
repo string repo string
tag string tag string
digest string digest string

View File

@ -24,36 +24,36 @@ func TestImageContext(t *testing.T) {
call func() string call func() string
}{ }{
{imageContext{ {imageContext{
i: types.Image{ID: imageID}, i: types.ImageSummary{ID: imageID},
trunc: true, trunc: true,
}, stringid.TruncateID(imageID), imageIDHeader, ctx.ID}, }, stringid.TruncateID(imageID), imageIDHeader, ctx.ID},
{imageContext{ {imageContext{
i: types.Image{ID: imageID}, i: types.ImageSummary{ID: imageID},
trunc: false, trunc: false,
}, imageID, imageIDHeader, ctx.ID}, }, imageID, imageIDHeader, ctx.ID},
{imageContext{ {imageContext{
i: types.Image{Size: 10, VirtualSize: 10}, i: types.ImageSummary{Size: 10, VirtualSize: 10},
trunc: true, trunc: true,
}, "10 B", sizeHeader, ctx.Size}, }, "10 B", sizeHeader, ctx.Size},
{imageContext{ {imageContext{
i: types.Image{Created: unix}, i: types.ImageSummary{Created: unix},
trunc: true, trunc: true,
}, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt}, }, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt},
// FIXME // FIXME
// {imageContext{ // {imageContext{
// i: types.Image{Created: unix}, // i: types.ImageSummary{Created: unix},
// trunc: true, // trunc: true,
// }, units.HumanDuration(time.Unix(unix, 0)), createdSinceHeader, ctx.CreatedSince}, // }, units.HumanDuration(time.Unix(unix, 0)), createdSinceHeader, ctx.CreatedSince},
{imageContext{ {imageContext{
i: types.Image{}, i: types.ImageSummary{},
repo: "busybox", repo: "busybox",
}, "busybox", repositoryHeader, ctx.Repository}, }, "busybox", repositoryHeader, ctx.Repository},
{imageContext{ {imageContext{
i: types.Image{}, i: types.ImageSummary{},
tag: "latest", tag: "latest",
}, "latest", tagHeader, ctx.Tag}, }, "latest", tagHeader, ctx.Tag},
{imageContext{ {imageContext{
i: types.Image{}, i: types.ImageSummary{},
digest: "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", digest: "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a",
}, "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", digestHeader, ctx.Digest}, }, "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", digestHeader, ctx.Digest},
} }
@ -262,7 +262,7 @@ image_id: imageID3
} }
for _, testcase := range cases { for _, testcase := range cases {
images := []types.Image{ images := []types.ImageSummary{
{ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime}, {ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime},
{ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: unixTime}, {ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: unixTime},
{ID: "imageID3", RepoTags: []string{"<none>:<none>"}, RepoDigests: []string{"<none>@<none>"}, Created: unixTime}, {ID: "imageID3", RepoTags: []string{"<none>:<none>"}, RepoDigests: []string{"<none>@<none>"}, Created: unixTime},
@ -280,7 +280,7 @@ image_id: imageID3
func TestImageContextWriteWithNoImage(t *testing.T) { func TestImageContextWriteWithNoImage(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
images := []types.Image{} images := []types.ImageSummary{}
contexts := []struct { contexts := []struct {
context ImageContext context ImageContext