Skip to content

Commit d459e83

Browse files
committed
Generate VolumeList response from the swagger spec
Signed-off-by: Daniel Nephin <[email protected]>
1 parent 17aaa08 commit d459e83

10 files changed

Lines changed: 76 additions & 17 deletions

File tree

api/server/router/volume/volume_routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66

77
"github.com/docker/docker/api/server/httputils"
8+
volumetypes "github.com/docker/docker/api/server/types/volume"
89
"github.com/docker/docker/api/types"
910
"golang.org/x/net/context"
1011
)
@@ -18,7 +19,7 @@ func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter
1819
if err != nil {
1920
return err
2021
}
21-
return httputils.WriteJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes, Warnings: warnings})
22+
return httputils.WriteJSON(w, http.StatusOK, &volumetypes.VolumesListOKBody{Volumes: volumes, Warnings: warnings})
2223
}
2324

2425
func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package volume
2+
3+
// ----------------------------------------------------------------------------
4+
// DO NOT EDIT THIS FILE
5+
// This file was generated by `swagger generate operation`
6+
//
7+
// See hack/swagger-gen.sh
8+
// ----------------------------------------------------------------------------
9+
10+
import "github.com/docker/docker/api/types"
11+
12+
/*VolumesListOKBody volumes list o k body
13+
14+
swagger:model VolumesListOKBody
15+
*/
16+
type VolumesListOKBody struct {
17+
18+
/* List of volumes
19+
20+
Required: true
21+
*/
22+
Volumes []*types.Volume `json:"Volumes"`
23+
24+
/* Warnings that occurred when fetching the list of volumes
25+
26+
Required: true
27+
*/
28+
Warnings []string `json:"Warnings"`
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package {{ .Package }}
2+
3+
// ----------------------------------------------------------------------------
4+
// DO NOT EDIT THIS FILE
5+
// This file was generated by `swagger generate operation`
6+
//
7+
// See hack/swagger-gen.sh
8+
// ----------------------------------------------------------------------------
9+
10+
import (
11+
"net/http"
12+
13+
context "golang.org/x/net/context"
14+
15+
{{ range .DefaultImports }}{{ printf "%q" . }}
16+
{{ end }}
17+
{{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }}
18+
{{ end }}
19+
)
20+
21+
22+
{{ range .ExtraSchemas }}
23+
/*{{ .Name }} {{ template "docstring" . }}
24+
swagger:model {{ .Name }}
25+
*/
26+
{{ template "schema" . }}
27+
{{ end }}

api/types/types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,6 @@ type MountPoint struct {
410410
Propagation mount.Propagation
411411
}
412412

413-
// VolumesListResponse contains the response for the remote API:
414-
// GET "/volumes"
415-
type VolumesListResponse struct {
416-
Volumes []*Volume // Volumes is the list of volumes being returned
417-
Warnings []string // Warnings is a list of warnings that occurred when getting the list from the volume drivers
418-
}
419-
420413
// VolumeCreateRequest contains the request for the remote API:
421414
// POST "/volumes/create"
422415
type VolumeCreateRequest struct {

client/interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"time"
66

7+
volumetypes "github.com/docker/docker/api/server/types/volume"
78
"github.com/docker/docker/api/types"
89
"github.com/docker/docker/api/types/container"
910
"github.com/docker/docker/api/types/events"
@@ -136,7 +137,7 @@ type VolumeAPIClient interface {
136137
VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error)
137138
VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error)
138139
VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error)
139-
VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error)
140+
VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error)
140141
VolumeRemove(ctx context.Context, volumeID string, force bool) error
141142
VolumesPrune(ctx context.Context, cfg types.VolumesPruneConfig) (types.VolumesPruneReport, error)
142143
}

client/volume_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"encoding/json"
55
"net/url"
66

7-
"github.com/docker/docker/api/types"
7+
volumetypes "github.com/docker/docker/api/server/types/volume"
88
"github.com/docker/docker/api/types/filters"
99
"golang.org/x/net/context"
1010
)
1111

1212
// VolumeList returns the volumes configured in the docker host.
13-
func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) {
14-
var volumes types.VolumesListResponse
13+
func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) {
14+
var volumes volumetypes.VolumesListOKBody
1515
query := url.Values{}
1616

1717
if filter.Len() > 0 {

client/volume_list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
volumetypes "github.com/docker/docker/api/server/types/volume"
1213
"github.com/docker/docker/api/types"
1314
"github.com/docker/docker/api/types/filters"
1415
"golang.org/x/net/context"
@@ -68,7 +69,7 @@ func TestVolumeList(t *testing.T) {
6869
if actualFilters != listCase.expectedFilters {
6970
return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters)
7071
}
71-
content, err := json.Marshal(types.VolumesListResponse{
72+
content, err := json.Marshal(volumetypes.VolumesListOKBody{
7273
Volumes: []*types.Volume{
7374
{
7475
Name: "volume",

hack/generate-swagger-api.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ swagger generate model -f api/swagger.yaml \
77
-n Port \
88
-n ImageSummary \
99
-n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType
10+
11+
swagger generate operation -f api/swagger.yaml \
12+
-t api -s server -a types -m types \
13+
-T api/templates --skip-responses --skip-parameters --skip-validator \
14+
-n VolumesList

integration-cli/docker_api_volumes_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"path/filepath"
77

8+
volumetypes "github.com/docker/docker/api/server/types/volume"
89
"github.com/docker/docker/api/types"
910
"github.com/docker/docker/pkg/integration/checker"
1011
"github.com/go-check/check"
@@ -18,7 +19,7 @@ func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
1819
c.Assert(err, checker.IsNil)
1920
c.Assert(status, checker.Equals, http.StatusOK)
2021

21-
var volumes types.VolumesListResponse
22+
var volumes volumetypes.VolumesListOKBody
2223
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
2324

2425
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) {
4748
c.Assert(err, checker.IsNil)
4849
c.Assert(status, checker.Equals, http.StatusOK)
4950

50-
var volumes types.VolumesListResponse
51+
var volumes volumetypes.VolumesListOKBody
5152
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
5253
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
5354

@@ -75,7 +76,7 @@ func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
7576
c.Assert(err, checker.IsNil)
7677
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
7778

78-
var volumes types.VolumesListResponse
79+
var volumes volumetypes.VolumesListOKBody
7980
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
8081
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
8182

integration-cli/docker_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25+
volumetypes "github.com/docker/docker/api/server/types/volume"
2526
"github.com/docker/docker/api/types"
2627
"github.com/docker/docker/opts"
2728
"github.com/docker/docker/pkg/httputils"
@@ -325,7 +326,7 @@ func deleteAllVolumes() error {
325326
}
326327

327328
func getAllVolumes() ([]*types.Volume, error) {
328-
var volumes types.VolumesListResponse
329+
var volumes volumetypes.VolumesListOKBody
329330
_, b, err := sockRequest("GET", "/volumes", nil)
330331
if err != nil {
331332
return nil, err

0 commit comments

Comments
 (0)