diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index 02cf53fd55..43021591bd 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/docker/docker/api/server/httputils" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter if err != nil { return err } - return httputils.WriteJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes, Warnings: warnings}) + return httputils.WriteJSON(w, http.StatusOK, &volumetypes.VolumesListOKBody{Volumes: volumes, Warnings: warnings}) } func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { diff --git a/api/server/types/volume/volumes_list.go b/api/server/types/volume/volumes_list.go new file mode 100644 index 0000000000..f5cf443ffb --- /dev/null +++ b/api/server/types/volume/volumes_list.go @@ -0,0 +1,29 @@ +package volume + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +import "github.com/docker/docker/api/types" + +/*VolumesListOKBody volumes list o k body + +swagger:model VolumesListOKBody +*/ +type VolumesListOKBody struct { + + /* List of volumes + + Required: true + */ + Volumes []*types.Volume `json:"Volumes"` + + /* Warnings that occurred when fetching the list of volumes + + Required: true + */ + Warnings []string `json:"Warnings"` +} diff --git a/api/templates/server/operation.gotmpl b/api/templates/server/operation.gotmpl new file mode 100644 index 0000000000..19c0e80a7a --- /dev/null +++ b/api/templates/server/operation.gotmpl @@ -0,0 +1,27 @@ +package {{ .Package }} + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +import ( + "net/http" + + context "golang.org/x/net/context" + + {{ range .DefaultImports }}{{ printf "%q" . }} + {{ end }} + {{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }} + {{ end }} +) + + +{{ range .ExtraSchemas }} +/*{{ .Name }} {{ template "docstring" . }} +swagger:model {{ .Name }} +*/ +{{ template "schema" . }} +{{ end }} diff --git a/api/types/types.go b/api/types/types.go index 0477592e19..a1e909b01e 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -410,13 +410,6 @@ type MountPoint struct { Propagation mount.Propagation } -// VolumesListResponse contains the response for the remote API: -// GET "/volumes" -type VolumesListResponse struct { - Volumes []*Volume // Volumes is the list of volumes being returned - Warnings []string // Warnings is a list of warnings that occurred when getting the list from the volume drivers -} - // VolumeCreateRequest contains the request for the remote API: // POST "/volumes/create" type VolumeCreateRequest struct { diff --git a/client/interface.go b/client/interface.go index 8abdb0f6fc..613015f865 100644 --- a/client/interface.go +++ b/client/interface.go @@ -4,6 +4,7 @@ import ( "io" "time" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" @@ -136,7 +137,7 @@ type VolumeAPIClient interface { VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) - VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) + VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, cfg types.VolumesPruneConfig) (types.VolumesPruneReport, error) } diff --git a/client/volume_list.go b/client/volume_list.go index 44f03cfac7..9923ecb82c 100644 --- a/client/volume_list.go +++ b/client/volume_list.go @@ -4,14 +4,14 @@ import ( "encoding/json" "net/url" - "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types/filters" "golang.org/x/net/context" ) // VolumeList returns the volumes configured in the docker host. -func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) { - var volumes types.VolumesListResponse +func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) { + var volumes volumetypes.VolumesListOKBody query := url.Values{} if filter.Len() > 0 { diff --git a/client/volume_list_test.go b/client/volume_list_test.go index 0af420eaff..ffdd904b58 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "golang.org/x/net/context" @@ -68,7 +69,7 @@ func TestVolumeList(t *testing.T) { if actualFilters != listCase.expectedFilters { return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) } - content, err := json.Marshal(types.VolumesListResponse{ + content, err := json.Marshal(volumetypes.VolumesListOKBody{ Volumes: []*types.Volume{ { Name: "volume", diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index c33900eb04..bf6d03dd1f 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -7,3 +7,8 @@ swagger generate model -f api/swagger.yaml \ -n Port \ -n ImageSummary \ -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType + +swagger generate operation -f api/swagger.yaml \ + -t api -s server -a types -m types \ + -T api/templates --skip-responses --skip-parameters --skip-validator \ + -n VolumesList diff --git a/integration-cli/docker_api_volumes_test.go b/integration-cli/docker_api_volumes_test.go index 5809932ef1..5db607488e 100644 --- a/integration-cli/docker_api_volumes_test.go +++ b/integration-cli/docker_api_volumes_test.go @@ -5,6 +5,7 @@ import ( "net/http" "path/filepath" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" @@ -18,7 +19,7 @@ func (s *DockerSuite) TestVolumesAPIList(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) - var volumes types.VolumesListResponse + var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) @@ -47,7 +48,7 @@ func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) - var volumes types.VolumesListResponse + var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) @@ -75,7 +76,7 @@ func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) - var volumes types.VolumesListResponse + var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 87bbc6b8b1..5adc555878 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -22,6 +22,7 @@ import ( "strings" "time" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/httputils" @@ -325,7 +326,7 @@ func deleteAllVolumes() error { } func getAllVolumes() ([]*types.Volume, error) { - var volumes types.VolumesListResponse + var volumes volumetypes.VolumesListOKBody _, b, err := sockRequest("GET", "/volumes", nil) if err != nil { return nil, err