mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Generate VolumeList response from the swagger spec
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
17aaa0890a
commit
d459e83b1c
10 changed files with 76 additions and 17 deletions
|
@ -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 {
|
||||
|
|
29
api/server/types/volume/volumes_list.go
Normal file
29
api/server/types/volume/volumes_list.go
Normal file
|
@ -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"`
|
||||
}
|
27
api/templates/server/operation.gotmpl
Normal file
27
api/templates/server/operation.gotmpl
Normal file
|
@ -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 }}
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue