From d459e83b1c993d63d5f94b85a7f8ddf3ac01beae Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 4 Oct 2016 11:40:17 -0400 Subject: [PATCH 01/13] Generate VolumeList response from the swagger spec Signed-off-by: Daniel Nephin --- api/server/router/volume/volume_routes.go | 3 ++- api/server/types/volume/volumes_list.go | 29 ++++++++++++++++++++++ api/templates/server/operation.gotmpl | 27 ++++++++++++++++++++ api/types/types.go | 7 ------ client/interface.go | 3 ++- client/volume_list.go | 6 ++--- client/volume_list_test.go | 3 ++- hack/generate-swagger-api.sh | 5 ++++ integration-cli/docker_api_volumes_test.go | 7 +++--- integration-cli/docker_utils.go | 3 ++- 10 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 api/server/types/volume/volumes_list.go create mode 100644 api/templates/server/operation.gotmpl 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 From 84a39c0830a3c9fa91d65db201ed9a925af7bfe6 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 6 Oct 2016 12:24:00 -0400 Subject: [PATCH 02/13] Cleanup volume swagger spec. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 48d9b1cad4..69d28458f1 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5451,20 +5451,17 @@ paths: driver name. type: "string" format: "json" - tags: - - "Volume" + tags: ["Volume"] /volumes/create: post: summary: "Create a volume" - operationId: "PostVolumesCreate" - consumes: - - "application/json" - produces: - - "application/json" + operationId: "VolumesCreate" + consumes: ["application/json"] + produces: ["application/json"] responses: 201: - description: "No error" + description: "The volume was created successfully" schema: $ref: "#/definitions/Volume" 500: @@ -5502,14 +5499,13 @@ paths: com.example.some-label: "some-value" com.example.some-other-label: "some-other-value" Driver: "custom" - tags: - - "Volume" + tags: ["Volume"] + /volumes/{name}: get: summary: "Inspect a volume" - operationId: "GetVolumesInspect" - produces: - - "application/json" + operationId: "VolumesInspect" + produces: ["application/json"] responses: 200: description: "No error" @@ -5529,15 +5525,15 @@ paths: required: true description: "Volume name or ID" type: "string" - tags: - - "Volume" + tags: ["Volume"] + delete: summary: "Remove a volume" description: "Instruct the driver to remove the volume." - operationId: "DeleteVolumes" + operationId: "VolumesDelete" responses: 204: - description: "No error" + description: "The volume was removed" 404: description: "No such volume or volume driver" schema: @@ -5556,8 +5552,8 @@ paths: required: true description: "Volume name or ID" type: "string" - tags: - - "Volume" + tags: ["Volume"] + /networks: get: summary: "List networks" From bc757385455dee272ca563031afece05c935320b Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 6 Oct 2016 12:40:38 -0400 Subject: [PATCH 03/13] Generate ErrorResponse struct from swagger spec. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 313 ++++++++++++++++++----------------- api/types/error_response.go | 17 ++ api/types/errors.go | 6 - hack/generate-swagger-api.sh | 3 +- 4 files changed, 176 insertions(+), 163 deletions(-) create mode 100644 api/types/error_response.go delete mode 100644 api/types/errors.go diff --git a/api/swagger.yaml b/api/swagger.yaml index 69d28458f1..cff1f754b3 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1063,7 +1063,7 @@ definitions: message: type: "integer" - Error: + ErrorResponse: description: "Represents an error." type: "object" required: ["message"] @@ -1071,6 +1071,7 @@ definitions: message: description: "The error message." type: "string" + x-nullable: false example: message: "Something went wrong." @@ -2382,11 +2383,11 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Container" /containers/create: @@ -2559,26 +2560,26 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 406: description: "impossible to attach" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "conflict" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Container" /containers/{id}/json: @@ -2851,14 +2852,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -2928,14 +2929,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -2970,14 +2971,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3060,14 +3061,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3089,14 +3090,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3213,14 +3214,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3249,14 +3250,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "cannot resize container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3283,18 +3284,18 @@ paths: 304: description: "container already started" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3317,18 +3318,18 @@ paths: 304: description: "container already stopped" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3351,14 +3352,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3382,14 +3383,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3425,14 +3426,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3475,18 +3476,18 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 409: description: "name already in use" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3514,14 +3515,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3541,14 +3542,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3648,18 +3649,18 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3714,18 +3715,18 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3782,14 +3783,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3808,18 +3809,18 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3853,18 +3854,18 @@ paths: 400: description: "client error, bad parameter, details in JSON response body, one of: must specify path parameter (path cannot be empty) not a directory (path was asserted to be a directory but exists as a file)" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "client error, resource not found, one of: 1) no such container (container id does not exist) 2) no such file or directory (path resource does not exist)" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3890,18 +3891,18 @@ paths: 400: description: "client error, bad parameter, details in JSON response body, one of: must specify path parameter (path cannot be empty) not a directory (path was asserted to be a directory but exists as a file)" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "client error, resource not found, one of: 1) no such container (container id does not exist) 2) no such file or directory (path resource does not exist)" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -3928,22 +3929,22 @@ paths: 400: description: "Bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 403: description: "Permission denied, the volume or container rootfs is marked as read-only." schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "No such container or path does not exist inside the container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -4005,7 +4006,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "all" in: "query" @@ -4155,7 +4156,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Image" /images/create: @@ -4174,7 +4175,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "fromImage" in: "query" @@ -4302,14 +4303,14 @@ paths: 404: description: "No such image" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such image: someimage (tag: latest)" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -4376,11 +4377,11 @@ paths: 404: description: "No such image" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -4407,11 +4408,11 @@ paths: 404: description: "No such image" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -4440,19 +4441,19 @@ paths: 400: description: "Bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "No such image" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "Conflict" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -4501,15 +4502,15 @@ paths: 404: description: "No such image" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "Conflict" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -4573,7 +4574,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "term" in: "query" @@ -4625,7 +4626,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "authConfig" in: "body" @@ -4840,7 +4841,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Misc" /version: @@ -4888,7 +4889,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Misc" /_ping: @@ -4907,7 +4908,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Misc" /commit: @@ -4933,14 +4934,14 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "containerConfig" in: "body" @@ -5043,7 +5044,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "since" in: "query" @@ -5108,7 +5109,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -5138,7 +5139,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "names" in: "query" @@ -5166,7 +5167,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "imagesTarball" in: "body" @@ -5205,18 +5206,18 @@ paths: 404: description: "no such container" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" examples: application/json: message: "No such container: c2ada9df5af8" 409: description: "container is paused" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "execConfig" in: "body" @@ -5275,11 +5276,11 @@ paths: 404: description: "No such exec instance" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "Container is stopped or paused" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "execStartConfig" in: "body" @@ -5313,7 +5314,7 @@ paths: 404: description: "No such exec instance" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5381,11 +5382,11 @@ paths: 404: description: "No such exec instance" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5434,7 +5435,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "filters" in: "query" @@ -5467,7 +5468,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "volumeConfig" in: "body" @@ -5514,11 +5515,11 @@ paths: 404: description: "No such volume" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -5537,15 +5538,15 @@ paths: 404: description: "No such volume or volume driver" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "Volume is in use and cannot be removed" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -5618,7 +5619,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "filters" in: "query" @@ -5647,7 +5648,7 @@ paths: 404: description: "Network not found" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5665,11 +5666,11 @@ paths: 404: description: "no such network" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5703,11 +5704,11 @@ paths: 404: description: "plugin not found" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "networkConfig" in: "body" @@ -5785,15 +5786,15 @@ paths: 403: description: "Operation not supported for swarm scoped networks" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "Network or container not found" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5831,15 +5832,15 @@ paths: 403: description: "Operation not supported for swarm scoped networks" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 404: description: "Network or container not found" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -5952,7 +5953,7 @@ paths: 500: description: "Server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Plugins" /plugins/pull: @@ -5996,7 +5997,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "query" @@ -6024,11 +6025,11 @@ paths: 404: description: "plugin is not installed" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -6048,11 +6049,11 @@ paths: 404: description: "plugin is not installed" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -6076,7 +6077,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -6095,7 +6096,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "name" in: "path" @@ -6118,7 +6119,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "filters" in: "query" @@ -6145,11 +6146,11 @@ paths: 404: description: "no such node" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6167,11 +6168,11 @@ paths: 404: description: "no such node" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6195,11 +6196,11 @@ paths: 404: description: "no such node" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6266,7 +6267,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" tags: - "Swarm" /swarm/init: @@ -6286,15 +6287,15 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 406: description: "node is already part of a swarm" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "body" in: "body" @@ -6334,15 +6335,15 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 406: description: "node is already part of a swarm" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "body" in: "body" @@ -6380,11 +6381,11 @@ paths: 406: description: "node is not part of a swarm" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "force" description: "Force leave swarm, even if this is the last manager or that it will break the cluster." @@ -6403,15 +6404,15 @@ paths: 400: description: "bad parameter" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 406: description: "node is not part of a swarm" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "body" in: "body" @@ -6450,7 +6451,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "filters" in: "query" @@ -6484,15 +6485,15 @@ paths: 406: description: "server error or node is not part of a swarm" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 409: description: "name conflicts with an existing service" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "body" in: "body" @@ -6563,11 +6564,11 @@ paths: 404: description: "no such service" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6585,11 +6586,11 @@ paths: 404: description: "no such service" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6608,11 +6609,11 @@ paths: 404: description: "no such service" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" @@ -6787,7 +6788,7 @@ paths: 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "filters" in: "query" @@ -6817,11 +6818,11 @@ paths: 404: description: "no such task" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" 500: description: "server error" schema: - $ref: "#/definitions/Error" + $ref: "#/definitions/ErrorResponse" parameters: - name: "id" in: "path" diff --git a/api/types/error_response.go b/api/types/error_response.go new file mode 100644 index 0000000000..bbe0cf0821 --- /dev/null +++ b/api/types/error_response.go @@ -0,0 +1,17 @@ +package types + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +/*ErrorResponse Represents an error. + +swagger:model ErrorResponse +*/ +type ErrorResponse struct { + + /* The error message. + + Required: true + */ + Message string `json:"message"` +} diff --git a/api/types/errors.go b/api/types/errors.go deleted file mode 100644 index 649ab95131..0000000000 --- a/api/types/errors.go +++ /dev/null @@ -1,6 +0,0 @@ -package types - -// ErrorResponse is the response body of API errors. -type ErrorResponse struct { - Message string `json:"message"` -} diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index bf6d03dd1f..12161b859c 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -6,7 +6,8 @@ swagger generate model -f api/swagger.yaml \ -n Volume \ -n Port \ -n ImageSummary \ - -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType + -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ + -n ErrorResponse swagger generate operation -f api/swagger.yaml \ -t api -s server -a types -m types \ From 5c2498fd3c41f4badb1788665886d30772537f73 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 6 Oct 2016 12:57:17 -0400 Subject: [PATCH 04/13] Generate VolumesCreateRequest from the swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/volume/volume_routes.go | 2 +- api/server/types/volume/volumes_create.go | 39 +++++++++++++++++++ api/swagger.yaml | 2 + api/types/types.go | 9 ----- cli/command/volume/create.go | 4 +- client/interface.go | 2 +- client/volume_create.go | 3 +- client/volume_create_test.go | 5 ++- .../cluster/executor/container/container.go | 5 ++- hack/generate-swagger-api.sh | 3 +- integration-cli/docker_api_volumes_test.go | 4 +- 11 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 api/server/types/volume/volumes_create.go diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index 43021591bd..b8a8b577a9 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -43,7 +43,7 @@ func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWri return err } - var req types.VolumeCreateRequest + var req volumetypes.VolumesCreateBody if err := json.NewDecoder(r.Body).Decode(&req); err != nil { return err } diff --git a/api/server/types/volume/volumes_create.go b/api/server/types/volume/volumes_create.go new file mode 100644 index 0000000000..98c12b9b10 --- /dev/null +++ b/api/server/types/volume/volumes_create.go @@ -0,0 +1,39 @@ +package volume + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +/*VolumesCreateBody volumes create body + +swagger:model VolumesCreateBody +*/ +type VolumesCreateBody struct { + + /* Name of the volume driver to use. + + Required: true + */ + Driver string `json:"Driver"` + + /* A mapping of driver options and values. These options are passed directly to the driver and are driver specific. + + Required: true + */ + DriverOpts map[string]string `json:"DriverOpts"` + + /* A mapping of arbitrary key/value data to set on the volume. + + Required: true + */ + Labels map[string]string `json:"Labels"` + + /* The new volume's name. If not specified, Docker generates a name. + + Required: true + */ + Name string `json:"Name"` +} diff --git a/api/swagger.yaml b/api/swagger.yaml index cff1f754b3..682797d09b 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5480,10 +5480,12 @@ paths: Name: description: "The new volume's name. If not specified, Docker generates a name." type: "string" + x-nullable: false Driver: description: "Name of the volume driver to use." type: "string" default: "local" + x-nullable: false DriverOpts: description: "A mapping of driver options and values. These options are passed directly to the driver and are driver specific." type: "object" diff --git a/api/types/types.go b/api/types/types.go index a1e909b01e..151e355cbe 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -410,15 +410,6 @@ type MountPoint struct { Propagation mount.Propagation } -// VolumeCreateRequest contains the request for the remote API: -// POST "/volumes/create" -type VolumeCreateRequest struct { - Name string // Name is the requested name of the volume - Driver string // Driver is the name of the driver that should be used to create the volume - DriverOpts map[string]string // DriverOpts holds the driver specific options to use for when creating the volume. - Labels map[string]string // Labels holds metadata specific to the volume being created. -} - // NetworkResource is the body of the "get network" http response message type NetworkResource struct { Name string // Name is the requested name of the network diff --git a/cli/command/volume/create.go b/cli/command/volume/create.go index fbf62a5ef1..f16e650bbc 100644 --- a/cli/command/volume/create.go +++ b/cli/command/volume/create.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/opts" @@ -55,7 +55,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { func runCreate(dockerCli *command.DockerCli, opts createOptions) error { client := dockerCli.Client() - volReq := types.VolumeCreateRequest{ + volReq := volumetypes.VolumesCreateBody{ Driver: opts.driver, DriverOpts: opts.driverOpts.GetAll(), Name: opts.name, diff --git a/client/interface.go b/client/interface.go index 613015f865..5ec750abe1 100644 --- a/client/interface.go +++ b/client/interface.go @@ -134,7 +134,7 @@ type SystemAPIClient interface { // VolumeAPIClient defines API client methods for the volumes type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) + VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (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) (volumetypes.VolumesListOKBody, error) diff --git a/client/volume_create.go b/client/volume_create.go index f3a79f1e11..b18e5fe600 100644 --- a/client/volume_create.go +++ b/client/volume_create.go @@ -3,12 +3,13 @@ package client import ( "encoding/json" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "golang.org/x/net/context" ) // VolumeCreate creates a volume in the docker host. -func (cli *Client) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) { +func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (types.Volume, error) { var volume types.Volume resp, err := cli.post(ctx, "/volumes/create", nil, options, nil) if err != nil { diff --git a/client/volume_create_test.go b/client/volume_create_test.go index 75085296cc..d5d3791685 100644 --- a/client/volume_create_test.go +++ b/client/volume_create_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + 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 TestVolumeCreateError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.VolumeCreate(context.Background(), types.VolumeCreateRequest{}) + _, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{}) if err == nil || err.Error() != "Error response from daemon: Server error" { t.Fatalf("expected a Server Error, got %v", err) } @@ -52,7 +53,7 @@ func TestVolumeCreate(t *testing.T) { }), } - volume, err := client.VolumeCreate(context.Background(), types.VolumeCreateRequest{ + volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{ Name: "myvolume", Driver: "mydriver", DriverOpts: map[string]string{ diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index 7b5203715f..ab5b0c35b5 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -9,6 +9,7 @@ import ( "github.com/Sirupsen/logrus" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" enginecontainer "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" @@ -335,7 +336,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig { } // This handles the case of volumes that are defined inside a service Mount -func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *types.VolumeCreateRequest { +func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *volumetypes.VolumesCreateBody { var ( driverName string driverOpts map[string]string @@ -349,7 +350,7 @@ func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *types.VolumeCre } if mount.VolumeOptions != nil { - return &types.VolumeCreateRequest{ + return &volumetypes.VolumesCreateBody{ Name: mount.Source, Driver: driverName, DriverOpts: driverOpts, diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 12161b859c..6f64d43130 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -12,4 +12,5 @@ swagger generate model -f api/swagger.yaml \ 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 + -n VolumesList \ + -n VolumesCreate diff --git a/integration-cli/docker_api_volumes_test.go b/integration-cli/docker_api_volumes_test.go index 5db607488e..d7f4c6fc13 100644 --- a/integration-cli/docker_api_volumes_test.go +++ b/integration-cli/docker_api_volumes_test.go @@ -26,7 +26,7 @@ func (s *DockerSuite) TestVolumesAPIList(c *check.C) { } func (s *DockerSuite) TestVolumesAPICreate(c *check.C) { - config := types.VolumeCreateRequest{ + config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := sockRequest("POST", "/volumes/create", config) @@ -65,7 +65,7 @@ func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) { } func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) { - config := types.VolumeCreateRequest{ + config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := sockRequest("POST", "/volumes/create", config) From 52a4737319b4008a0b636319905e2bfc7b3225ad Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 6 Oct 2016 13:58:39 -0400 Subject: [PATCH 05/13] Cleanup network swagger spec. Signed-off-by: Daniel Nephin --- api/swagger.yaml | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 682797d09b..9da6019657 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5560,7 +5560,7 @@ paths: /networks: get: summary: "List networks" - operationId: "GetNetworksList" + operationId: "NetworksList" produces: - "application/json" responses: @@ -5634,12 +5634,12 @@ paths: - `name=` Matches all or part of a network name. - `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. type: "string" - tags: - - "Network" + tags: ["Network"] + /networks/{id}: get: summary: "Inspect a network" - operationId: "GetNetworksInspect" + operationId: "NetworksInspect" produces: - "application/json" responses: @@ -5657,8 +5657,8 @@ paths: description: "Network ID or name" required: true type: "string" - tags: - - "Network" + tags: ["Network"] + delete: summary: "Remove a network" operationId: "DeleteNetworks" @@ -5679,12 +5679,12 @@ paths: description: "Network ID or name" required: true type: "string" - tags: - - "Network" + tags: ["Network"] + /networks/create: post: summary: "Create a network" - operationId: "PostNetworksCreate" + operationId: "NetworksCreate" consumes: - "application/json" produces: @@ -5774,12 +5774,12 @@ paths: Labels: com.example.some-label: "some-value" com.example.some-other-label: "some-other-value" - tags: - - "Network" + tags: ["Network"] + /networks/{id}/connect: post: summary: "Connect a container to a network" - operationId: "PostNetworksConnect" + operationId: "NetworksConnect" consumes: - "application/octet-stream" responses: @@ -5820,12 +5820,12 @@ paths: IPAMConfig: IPv4Address: "172.24.56.89" IPv6Address: "2001:db8::5689" - tags: - - "Network" + tags: ["Network"] + /networks/{id}/disconnect: post: summary: "Disconnect a container from a network" - operationId: "PostNetworksDisconnect" + operationId: "NetworksDisconnect" consumes: - "application/json" responses: @@ -5861,15 +5861,14 @@ paths: Force: type: "boolean" description: "Force the container to disconnect from the network." - tags: - - "Network" + tags: ["Network"] + /plugins: get: summary: "List plugins" - operationId: "GetPluginsList" + operationId: "PluginsList" description: "Returns information about installed plugins." - produces: - - "application/json" + produces: ["application/json"] responses: 200: description: "No error" @@ -5956,8 +5955,8 @@ paths: description: "Server error" schema: $ref: "#/definitions/ErrorResponse" - tags: - - "Plugins" + tags: ["Plugins"] + /plugins/pull: post: summary: "Install a plugin" From 8f81bb92a3e528d0b5facadd55738aefc279caf8 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 14 Oct 2016 12:46:39 -0400 Subject: [PATCH 06/13] Update to inline comments. Signed-off-by: Daniel Nephin --- api/server/types/volume/volumes_create.go | 30 ++++++++--------------- api/server/types/volume/volumes_list.go | 18 +++++--------- api/templates/server/operation.gotmpl | 5 ++-- api/types/error_response.go | 12 +++------ 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/api/server/types/volume/volumes_create.go b/api/server/types/volume/volumes_create.go index 98c12b9b10..5f9513a227 100644 --- a/api/server/types/volume/volumes_create.go +++ b/api/server/types/volume/volumes_create.go @@ -7,33 +7,23 @@ package volume // See hack/swagger-gen.sh // ---------------------------------------------------------------------------- -/*VolumesCreateBody volumes create body - -swagger:model VolumesCreateBody -*/ +// VolumesCreateBody volumes create body +// swagger:model VolumesCreateBody type VolumesCreateBody struct { - /* Name of the volume driver to use. - - Required: true - */ + // Name of the volume driver to use. + // Required: true Driver string `json:"Driver"` - /* A mapping of driver options and values. These options are passed directly to the driver and are driver specific. - - Required: true - */ + // A mapping of driver options and values. These options are passed directly to the driver and are driver specific. + // Required: true DriverOpts map[string]string `json:"DriverOpts"` - /* A mapping of arbitrary key/value data to set on the volume. - - Required: true - */ + // A mapping of arbitrary key/value data to set on the volume. + // Required: true Labels map[string]string `json:"Labels"` - /* The new volume's name. If not specified, Docker generates a name. - - Required: true - */ + // The new volume's name. If not specified, Docker generates a name. + // Required: true Name string `json:"Name"` } diff --git a/api/server/types/volume/volumes_list.go b/api/server/types/volume/volumes_list.go index f5cf443ffb..7770bcb8fc 100644 --- a/api/server/types/volume/volumes_list.go +++ b/api/server/types/volume/volumes_list.go @@ -9,21 +9,15 @@ package volume import "github.com/docker/docker/api/types" -/*VolumesListOKBody volumes list o k body - -swagger:model VolumesListOKBody -*/ +// VolumesListOKBody volumes list o k body +// swagger:model VolumesListOKBody type VolumesListOKBody struct { - /* List of volumes - - Required: true - */ + // List of volumes + // Required: true Volumes []*types.Volume `json:"Volumes"` - /* Warnings that occurred when fetching the list of volumes - - Required: true - */ + // 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 index 19c0e80a7a..3a3d7527da 100644 --- a/api/templates/server/operation.gotmpl +++ b/api/templates/server/operation.gotmpl @@ -20,8 +20,7 @@ import ( {{ range .ExtraSchemas }} -/*{{ .Name }} {{ template "docstring" . }} -swagger:model {{ .Name }} -*/ +// {{ .Name }} {{ template "docstring" . }} +// swagger:model {{ .Name }} {{ template "schema" . }} {{ end }} diff --git a/api/types/error_response.go b/api/types/error_response.go index bbe0cf0821..dc942d9d9e 100644 --- a/api/types/error_response.go +++ b/api/types/error_response.go @@ -3,15 +3,11 @@ package types // This file was generated by the swagger tool. // Editing this file might prove futile when you re-run the swagger generate command -/*ErrorResponse Represents an error. - -swagger:model ErrorResponse -*/ +// ErrorResponse Represents an error. +// swagger:model ErrorResponse type ErrorResponse struct { - /* The error message. - - Required: true - */ + // The error message. + // Required: true Message string `json:"message"` } From 29df3bdb117a058ae040686dd0f2565ae9ad743a Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 14 Oct 2016 16:20:13 -0400 Subject: [PATCH 07/13] Use a config to generate swagger api types Moves the resposne types to a package under api/types Signed-off-by: Daniel Nephin --- api/server/router/volume/volume_routes.go | 2 +- api/swagger-gen.yaml | 12 ++++++++++++ api/{server => }/types/volume/volumes_create.go | 0 api/{server => }/types/volume/volumes_list.go | 0 cli/command/volume/create.go | 2 +- client/interface.go | 2 +- client/volume_create.go | 2 +- client/volume_create_test.go | 2 +- client/volume_list.go | 2 +- client/volume_list_test.go | 2 +- daemon/cluster/executor/container/container.go | 2 +- hack/generate-swagger-api.sh | 4 ++-- integration-cli/docker_api_volumes_test.go | 2 +- integration-cli/docker_utils.go | 2 +- 14 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 api/swagger-gen.yaml rename api/{server => }/types/volume/volumes_create.go (100%) rename api/{server => }/types/volume/volumes_list.go (100%) diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index b8a8b577a9..e0398817c3 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -5,8 +5,8 @@ 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" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/api/swagger-gen.yaml b/api/swagger-gen.yaml new file mode 100644 index 0000000000..f07a02737f --- /dev/null +++ b/api/swagger-gen.yaml @@ -0,0 +1,12 @@ + +layout: + models: + - name: definition + source: asset:model + target: "{{ joinFilePath .Target .ModelPackage }}" + file_name: "{{ (snakize (pascalize .Name)) }}.go" + operations: + - name: handler + source: asset:serverOperation + target: "{{ joinFilePath .Target .APIPackage .Package }}" + file_name: "{{ (snakize (pascalize .Name)) }}.go" diff --git a/api/server/types/volume/volumes_create.go b/api/types/volume/volumes_create.go similarity index 100% rename from api/server/types/volume/volumes_create.go rename to api/types/volume/volumes_create.go diff --git a/api/server/types/volume/volumes_list.go b/api/types/volume/volumes_list.go similarity index 100% rename from api/server/types/volume/volumes_list.go rename to api/types/volume/volumes_list.go diff --git a/cli/command/volume/create.go b/cli/command/volume/create.go index f16e650bbc..7b2a7e3318 100644 --- a/cli/command/volume/create.go +++ b/cli/command/volume/create.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - volumetypes "github.com/docker/docker/api/server/types/volume" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/opts" diff --git a/client/interface.go b/client/interface.go index 5ec750abe1..1f20a8be73 100644 --- a/client/interface.go +++ b/client/interface.go @@ -4,7 +4,6 @@ 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" @@ -12,6 +11,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/client/volume_create.go b/client/volume_create.go index b18e5fe600..9620c87cbf 100644 --- a/client/volume_create.go +++ b/client/volume_create.go @@ -3,8 +3,8 @@ package client import ( "encoding/json" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/client/volume_create_test.go b/client/volume_create_test.go index d5d3791685..9f1b2540b5 100644 --- a/client/volume_create_test.go +++ b/client/volume_create_test.go @@ -9,8 +9,8 @@ import ( "strings" "testing" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/client/volume_list.go b/client/volume_list.go index 9923ecb82c..32247ce115 100644 --- a/client/volume_list.go +++ b/client/volume_list.go @@ -4,8 +4,8 @@ import ( "encoding/json" "net/url" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types/filters" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/client/volume_list_test.go b/client/volume_list_test.go index ffdd904b58..f29639be23 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -9,9 +9,9 @@ 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" + volumetypes "github.com/docker/docker/api/types/volume" "golang.org/x/net/context" ) diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index ab5b0c35b5..10b2a371f7 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -9,12 +9,12 @@ import ( "github.com/Sirupsen/logrus" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" enginecontainer "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" + volumetypes "github.com/docker/docker/api/types/volume" clustertypes "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/docker/reference" "github.com/docker/swarmkit/agent/exec" diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 6f64d43130..c30197f435 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -2,7 +2,7 @@ set -eu swagger generate model -f api/swagger.yaml \ - -t api -m types --skip-validator \ + -t api -m types --skip-validator -C api/swagger-gen.yaml \ -n Volume \ -n Port \ -n ImageSummary \ @@ -10,7 +10,7 @@ swagger generate model -f api/swagger.yaml \ -n ErrorResponse swagger generate operation -f api/swagger.yaml \ - -t api -s server -a types -m types \ + -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ -n VolumesCreate diff --git a/integration-cli/docker_api_volumes_test.go b/integration-cli/docker_api_volumes_test.go index d7f4c6fc13..d1d44005e0 100644 --- a/integration-cli/docker_api_volumes_test.go +++ b/integration-cli/docker_api_volumes_test.go @@ -5,8 +5,8 @@ import ( "net/http" "path/filepath" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 5adc555878..91dc88647b 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -22,8 +22,8 @@ import ( "strings" "time" - volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/httputils" icmd "github.com/docker/docker/pkg/integration/cmd" From bad849fc826b410c3aeb753a8c7f6b38f7ae12b0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 14 Oct 2016 16:28:47 -0400 Subject: [PATCH 08/13] Generate container create response from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/container/backend.go | 2 +- api/swagger.yaml | 8 +++++-- api/types/container/container_create.go | 21 +++++++++++++++++++ api/types/types.go | 10 --------- builder/builder.go | 2 +- cli/command/container/create.go | 2 +- client/container_create.go | 5 ++--- client/container_create_test.go | 3 +-- client/interface.go | 2 +- daemon/cluster/executor/backend.go | 2 +- daemon/cluster/executor/container/adapter.go | 3 ++- daemon/create.go | 19 +++++++++-------- hack/generate-swagger-api.sh | 3 ++- integration-cli/docker_api_containers_test.go | 16 +++++++------- 14 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 api/types/container/container_create.go diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index c81a9788d6..2a3fd8a091 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -32,7 +32,7 @@ type copyBackend interface { // stateBackend includes functions to implement to provide container state lifecycle functionality. type stateBackend interface { - ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) ContainerKill(name string, sig uint64) error ContainerPause(name string) error ContainerRename(oldName, newName string) error diff --git a/api/swagger.yaml b/api/swagger.yaml index 9da6019657..9d106b9dbf 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2393,7 +2393,7 @@ paths: /containers/create: post: summary: "Create a container" - operationId: "PostContainerCreate" + operationId: "ContainerCreate" consumes: - "application/json" - "application/octet-stream" @@ -2542,15 +2542,19 @@ paths: required: true responses: 201: - description: "no error" + description: "Container created successfully" schema: type: "object" + required: [Id, Warnings] properties: Id: description: "The ID of the created container" type: "string" + x-nullable: false Warnings: + description: "Warnings encountered when creating the container" type: "array" + x-nullable: false items: type: "string" examples: diff --git a/api/types/container/container_create.go b/api/types/container/container_create.go new file mode 100644 index 0000000000..d028e3b121 --- /dev/null +++ b/api/types/container/container_create.go @@ -0,0 +1,21 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerCreateCreatedBody container create created body +// swagger:model ContainerCreateCreatedBody +type ContainerCreateCreatedBody struct { + + // The ID of the created container + // Required: true + ID string `json:"Id"` + + // Warnings encountered when creating the container + // Required: true + Warnings []string `json:"Warnings"` +} diff --git a/api/types/types.go b/api/types/types.go index 151e355cbe..e06dcc853b 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,16 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerCreateResponse contains the information returned to a client on the -// creation of a new container. -type ContainerCreateResponse struct { - // ID is the ID of the created container. - ID string `json:"Id"` - - // Warnings are any warnings encountered during the creation of the container. - Warnings []string `json:"Warnings"` -} - // ContainerExecCreateResponse contains response of Remote API: // POST "/containers/{name:.*}/exec" type ContainerExecCreateResponse struct { diff --git a/builder/builder.go b/builder/builder.go index 0ed052731d..4aed1cb575 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -116,7 +116,7 @@ type Backend interface { // ContainerAttachRaw attaches to container. ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error // ContainerCreate creates a new Docker container and returns potential warnings - ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) // ContainerRm removes a container specified by `id`. ContainerRm(name string, config *types.ContainerRmConfig) error // Commit creates a new Docker image from an existing Docker container. diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 7bd3856971..7dc644d28c 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -148,7 +148,7 @@ func newCIDFile(path string) (*cidFile, error) { return &cidFile{path: path, file: f}, nil } -func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*types.ContainerCreateResponse, error) { +func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*container.ContainerCreateCreatedBody, error) { stderr := dockerCli.Err() var containerIDFile *cidFile diff --git a/client/container_create.go b/client/container_create.go index a862172956..c042b17468 100644 --- a/client/container_create.go +++ b/client/container_create.go @@ -5,7 +5,6 @@ import ( "net/url" "strings" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "golang.org/x/net/context" @@ -19,8 +18,8 @@ type configWrapper struct { // ContainerCreate creates a new container based in the given configuration. // It can be associated with a name, but it's not mandatory. -func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) { - var response types.ContainerCreateResponse +func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) { + var response container.ContainerCreateCreatedBody query := url.Values{} if containerName != "" { query.Set("name", containerName) diff --git a/client/container_create_test.go b/client/container_create_test.go index 5325156beb..89641038f7 100644 --- a/client/container_create_test.go +++ b/client/container_create_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -54,7 +53,7 @@ func TestContainerCreateWithName(t *testing.T) { if name != "container_name" { return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name) } - b, err := json.Marshal(types.ContainerCreateResponse{ + b, err := json.Marshal(container.ContainerCreateCreatedBody{ ID: "container_id", }) if err != nil { diff --git a/client/interface.go b/client/interface.go index 1f20a8be73..8f8bbaf55f 100644 --- a/client/interface.go +++ b/client/interface.go @@ -34,7 +34,7 @@ type CommonAPIClient interface { type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) - ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) + ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 2f91e78784..c34c2076e0 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -23,7 +23,7 @@ type Backend interface { FindNetwork(idName string) (libnetwork.Network, error) SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error) ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index 7b6d1069ef..bd5745cc5b 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -12,6 +12,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/versions" executorpkg "github.com/docker/docker/daemon/cluster/executor" @@ -187,7 +188,7 @@ func (c *containerAdapter) waitForDetach(ctx context.Context) error { } func (c *containerAdapter) create(ctx context.Context) error { - var cr types.ContainerCreateResponse + var cr containertypes.ContainerCreateCreatedBody var err error version := httputils.VersionFromContext(ctx) validateHostname := versions.GreaterThanOrEqualTo(version, "1.24") diff --git a/daemon/create.go b/daemon/create.go index bbb1cbc8ad..4ec17c486b 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -22,29 +22,29 @@ import ( ) // CreateManagedContainer creates a container that is managed by a Service -func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { return daemon.containerCreate(params, true, validateHostname) } // ContainerCreate creates a regular container -func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { return daemon.containerCreate(params, false, validateHostname) } -func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { start := time.Now() if params.Config == nil { - return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container") + return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container") } warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } err = daemon.verifyNetworkingConfig(params.NetworkingConfig) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } if params.HostConfig == nil { @@ -52,15 +52,16 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage } err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } container, err := daemon.create(params, managed) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err) + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err) } containerActions.WithValues("create").UpdateSince(start) - return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil + + return containertypes.ContainerCreateCreatedBody{ID: container.ID, Warnings: warnings}, nil } // Create creates a new container from the given configuration with a given name. diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index c30197f435..a5c02b10bc 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -13,4 +13,5 @@ swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ - -n VolumesCreate + -n VolumesCreate \ + -n ContainerCreate diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 97ae216378..e4415a81be 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -574,7 +574,7 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -597,7 +597,7 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -632,7 +632,7 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -657,7 +657,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1349,7 +1349,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check. c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1381,7 +1381,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) { c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1413,7 +1413,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) { c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1443,7 +1443,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted( c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) From 01883c136d9ef06962d80aa81e27d1d90eb6d199 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 15:56:45 -0700 Subject: [PATCH 09/13] Add an IDResponse type Generated from a swagger spec and use it for container exec response Signed-off-by: Daniel Nephin --- api/server/router/container/exec.go | 2 +- api/swagger.yaml | 24 +++++++++++------------- api/types/id_response.go | 13 +++++++++++++ api/types/types.go | 7 ------- client/container_exec.go | 4 ++-- client/container_exec_test.go | 2 +- client/interface.go | 2 +- hack/generate-swagger-api.sh | 3 ++- 8 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 api/types/id_response.go diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go index f840e54d70..8d49de7dac 100644 --- a/api/server/router/container/exec.go +++ b/api/server/router/container/exec.go @@ -49,7 +49,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re return err } - return httputils.WriteJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{ + return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ ID: id, }) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 9d106b9dbf..d624790eee 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1075,6 +1075,16 @@ definitions: example: message: "Something went wrong." + IdResponse: + description: "Response to an API call that returns just an Id" + type: "object" + required: ["Id"] + properties: + Id: + description: "The id of the newly created object." + type: "string" + x-nullable: false + EndpointSettings: description: "Configuration for a network endpoint." type: "object" @@ -5194,19 +5204,7 @@ paths: 201: description: "no error" schema: - type: "object" - properties: - Id: - description: "The ID of the exec instance created." - type: "string" - Warnings: - type: "array" - items: - type: "string" - examples: - application/json: - Id: "f90e34656806" - Warnings: [] + $ref: "#/definitions/IdResponse" 404: description: "no such container" schema: diff --git a/api/types/id_response.go b/api/types/id_response.go new file mode 100644 index 0000000000..7592d2f8b1 --- /dev/null +++ b/api/types/id_response.go @@ -0,0 +1,13 @@ +package types + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// IDResponse Response to an API call that returns just an Id +// swagger:model IdResponse +type IDResponse struct { + + // The id of the newly created object. + // Required: true + ID string `json:"Id"` +} diff --git a/api/types/types.go b/api/types/types.go index e06dcc853b..33c4f26a62 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,13 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerExecCreateResponse contains response of Remote API: -// POST "/containers/{name:.*}/exec" -type ContainerExecCreateResponse struct { - // ID is the exec ID. - ID string `json:"Id"` -} - // ContainerUpdateResponse contains response of Remote API: // POST "/containers/{name:.*}/update" type ContainerUpdateResponse struct { diff --git a/client/container_exec.go b/client/container_exec.go index 34173d3194..f6df722918 100644 --- a/client/container_exec.go +++ b/client/container_exec.go @@ -8,8 +8,8 @@ import ( ) // ContainerExecCreate creates a new exec configuration to run an exec process. -func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) { - var response types.ContainerExecCreateResponse +func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) { + var response types.IDResponse resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil) if err != nil { return response, err diff --git a/client/container_exec_test.go b/client/container_exec_test.go index 42146ae8a5..0e296a50ad 100644 --- a/client/container_exec_test.go +++ b/client/container_exec_test.go @@ -45,7 +45,7 @@ func TestContainerExecCreate(t *testing.T) { if execConfig.User != "user" { return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig) } - b, err := json.Marshal(types.ContainerExecCreateResponse{ + b, err := json.Marshal(types.IDResponse{ ID: "exec_id", }) if err != nil { diff --git a/client/interface.go b/client/interface.go index 8f8bbaf55f..0575ce5c3b 100644 --- a/client/interface.go +++ b/client/interface.go @@ -37,7 +37,7 @@ type ContainerAPIClient interface { ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) - ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) + ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index a5c02b10bc..13977dbb8c 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -7,7 +7,8 @@ swagger generate model -f api/swagger.yaml \ -n Port \ -n ImageSummary \ -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ - -n ErrorResponse + -n ErrorResponse \ + -n IdResponse swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ From c8d5e7203e1ae140a5cca312b6699063b521cf83 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 17:27:55 -0700 Subject: [PATCH 10/13] Use IDResponse for container create response. Signed-off-by: Daniel Nephin --- api/server/router/image/image_routes.go | 2 +- api/swagger.yaml | 9 +-------- api/types/types.go | 6 ------ client/container_commit.go | 8 ++++---- client/container_commit_test.go | 2 +- client/interface.go | 2 +- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index 961c547aab..bbc2d2bfad 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -63,7 +63,7 @@ func (s *imageRouter) postCommit(ctx context.Context, w http.ResponseWriter, r * return err } - return httputils.WriteJSON(w, http.StatusCreated, &types.ContainerCommitResponse{ + return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ ID: string(imgID), }) } diff --git a/api/swagger.yaml b/api/swagger.yaml index d624790eee..ad3c067e03 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4937,14 +4937,7 @@ paths: 201: description: "no error" schema: - type: "object" - properties: - Id: - description: "The ID of the image created" - type: "string" - examples: - application/json: - Id: "596069db4bf5" + $ref: "#/definitions/IdResponse" 404: description: "no such container" schema: diff --git a/api/types/types.go b/api/types/types.go index 33c4f26a62..6dc833979a 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -38,12 +38,6 @@ type ContainerWaitResponse struct { StatusCode int `json:"StatusCode"` } -// ContainerCommitResponse contains response of Remote API: -// POST "/commit?container="+containerID -type ContainerCommitResponse struct { - ID string `json:"Id"` -} - // ContainerChange contains response of Remote API: // GET "/containers/{name:.*}/changes" type ContainerChange struct { diff --git a/client/container_commit.go b/client/container_commit.go index 363950cc24..c766d62e40 100644 --- a/client/container_commit.go +++ b/client/container_commit.go @@ -12,16 +12,16 @@ import ( ) // ContainerCommit applies changes into a container and creates a new tagged image. -func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) { +func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) { var repository, tag string if options.Reference != "" { distributionRef, err := distreference.ParseNamed(options.Reference) if err != nil { - return types.ContainerCommitResponse{}, err + return types.IDResponse{}, err } if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical { - return types.ContainerCommitResponse{}, errors.New("refusing to create a tag with a digest reference") + return types.IDResponse{}, errors.New("refusing to create a tag with a digest reference") } tag = reference.GetTagFromNamedRef(distributionRef) @@ -41,7 +41,7 @@ func (cli *Client) ContainerCommit(ctx context.Context, container string, option query.Set("pause", "0") } - var response types.ContainerCommitResponse + var response types.IDResponse resp, err := cli.post(ctx, "/commit", query, options.Config, nil) if err != nil { return response, err diff --git a/client/container_commit_test.go b/client/container_commit_test.go index 8f1b58be81..a844675368 100644 --- a/client/container_commit_test.go +++ b/client/container_commit_test.go @@ -67,7 +67,7 @@ func TestContainerCommit(t *testing.T) { if len(changes) != len(expectedChanges) { return nil, fmt.Errorf("expected container changes size to be '%d', got %d", len(expectedChanges), len(changes)) } - b, err := json.Marshal(types.ContainerCommitResponse{ + b, err := json.Marshal(types.IDResponse{ ID: "new_container_id", }) if err != nil { diff --git a/client/interface.go b/client/interface.go index 0575ce5c3b..2a355fa8ad 100644 --- a/client/interface.go +++ b/client/interface.go @@ -33,7 +33,7 @@ type CommonAPIClient interface { // ContainerAPIClient defines API client methods for the containers type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) - ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) + ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) From f196cf6a090556ccb42198043a71d133482b510d Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 17:35:45 -0700 Subject: [PATCH 11/13] Generate container update response from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/container/backend.go | 2 +- api/swagger.yaml | 10 ++++------ api/types/container/container_update.go | 17 +++++++++++++++++ api/types/types.go | 7 ------- client/container_update.go | 5 ++--- client/container_update_test.go | 3 +-- client/interface.go | 2 +- daemon/update.go | 9 ++++----- hack/generate-swagger-api.sh | 3 ++- 9 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 api/types/container/container_update.go diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index 2a3fd8a091..0c9f081471 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -42,7 +42,7 @@ type stateBackend interface { ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ContainerUnpause(name string) error - ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (types.ContainerUpdateResponse, error) + ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (container.ContainerUpdateOKBody, error) ContainerWait(name string, timeout time.Duration) (int, error) } diff --git a/api/swagger.yaml b/api/swagger.yaml index ad3c067e03..64ad015d41 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3422,14 +3422,12 @@ paths: post: summary: "Update a container" description: "Change various configuration options of a container without having to recreate it." - operationId: "PostContainerUpdate" - consumes: - - "application/json" - produces: - - "application/json" + operationId: "ContainerUpdate" + consumes: ["application/json"] + produces: ["application/json"] responses: 200: - description: "no error" + description: "The container has been updated." schema: type: "object" properties: diff --git a/api/types/container/container_update.go b/api/types/container/container_update.go new file mode 100644 index 0000000000..81ee12c678 --- /dev/null +++ b/api/types/container/container_update.go @@ -0,0 +1,17 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerUpdateOKBody container update o k body +// swagger:model ContainerUpdateOKBody +type ContainerUpdateOKBody struct { + + // warnings + // Required: true + Warnings []string `json:"Warnings"` +} diff --git a/api/types/types.go b/api/types/types.go index 6dc833979a..fd58d4d856 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,13 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerUpdateResponse contains response of Remote API: -// POST "/containers/{name:.*}/update" -type ContainerUpdateResponse struct { - // Warnings are any warnings encountered during the updating of the container. - Warnings []string `json:"Warnings"` -} - // AuthResponse contains response of Remote API: // POST "/auth" type AuthResponse struct { diff --git a/client/container_update.go b/client/container_update.go index 48b75bee30..5082f22dfa 100644 --- a/client/container_update.go +++ b/client/container_update.go @@ -3,14 +3,13 @@ package client import ( "encoding/json" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) // ContainerUpdate updates resources of a container -func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error) { - var response types.ContainerUpdateResponse +func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) { + var response container.ContainerUpdateOKBody serverResp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil) if err != nil { return response, err diff --git a/client/container_update_test.go b/client/container_update_test.go index e151637a2b..715bb7ca23 100644 --- a/client/container_update_test.go +++ b/client/container_update_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -33,7 +32,7 @@ func TestContainerUpdate(t *testing.T) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal(types.ContainerUpdateResponse{}) + b, err := json.Marshal(container.ContainerUpdateOKBody{}) if err != nil { return nil, err } diff --git a/client/interface.go b/client/interface.go index 2a355fa8ad..b303d2fde8 100644 --- a/client/interface.go +++ b/client/interface.go @@ -58,7 +58,7 @@ type ContainerAPIClient interface { ContainerStop(ctx context.Context, container string, timeout *time.Duration) error ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) ContainerUnpause(ctx context.Context, container string) error - ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error) + ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) ContainerWait(ctx context.Context, container string) (int, error) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error diff --git a/daemon/update.go b/daemon/update.go index 46a3d35e5f..3e05047ae2 100644 --- a/daemon/update.go +++ b/daemon/update.go @@ -3,24 +3,23 @@ package daemon import ( "fmt" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" ) // ContainerUpdate updates configuration of the container -func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (types.ContainerUpdateResponse, error) { +func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (container.ContainerUpdateOKBody, error) { var warnings []string warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true, validateHostname) if err != nil { - return types.ContainerUpdateResponse{Warnings: warnings}, err + return container.ContainerUpdateOKBody{Warnings: warnings}, err } if err := daemon.update(name, hostConfig); err != nil { - return types.ContainerUpdateResponse{Warnings: warnings}, err + return container.ContainerUpdateOKBody{Warnings: warnings}, err } - return types.ContainerUpdateResponse{Warnings: warnings}, nil + return container.ContainerUpdateOKBody{Warnings: warnings}, nil } // ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID. diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 13977dbb8c..43e8da75e9 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -15,4 +15,5 @@ swagger generate operation -f api/swagger.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ -n VolumesCreate \ - -n ContainerCreate + -n ContainerCreate \ + -n ContainerUpdate From 2732b8a9bb3edb92121d0b0dcc144e5f557e2fbf Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 17:52:46 -0700 Subject: [PATCH 12/13] generate AuthResponse type from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/system/system_routes.go | 3 ++- api/swagger.yaml | 16 ++++++++-------- api/types/registry/authenticate.go | 21 +++++++++++++++++++++ api/types/types.go | 11 ----------- client/interface.go | 2 +- client/login.go | 9 +++++---- hack/generate-swagger-api.sh | 3 ++- 7 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 api/types/registry/authenticate.go diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go index 5e508610d7..89ff1a79b4 100644 --- a/api/server/router/system/system_routes.go +++ b/api/server/router/system/system_routes.go @@ -13,6 +13,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/pkg/ioutils" @@ -154,7 +155,7 @@ func (s *systemRouter) postAuth(ctx context.Context, w http.ResponseWriter, r *h if err != nil { return err } - return httputils.WriteJSON(w, http.StatusOK, &types.AuthResponse{ + return httputils.WriteJSON(w, http.StatusOK, ®istry.AuthenticateOKBody{ Status: status, IdentityToken: token, }) diff --git a/api/swagger.yaml b/api/swagger.yaml index 64ad015d41..79cde950a5 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4612,23 +4612,24 @@ paths: post: summary: "Check auth configuration" description: "Validate credentials for a registry and, if available, get an identity token for accessing the registry without password." - operationId: "checkAuthentication" - consumes: - - "application/json" - produces: - - "application/json" + operationId: "Authenticate" + consumes: ["application/json"] + produces: ["application/json"] responses: 200: - description: "No error" + description: "An identity token was generated successfully." schema: type: "object" + required: [Status] properties: Status: description: "The status of the authentication" type: "string" + x-nullable: false IdentityToken: description: "An opaque token used to authenticate a user after a successful login" type: "string" + x-nullable: false examples: application/json: Status: "Login Succeeded" @@ -4645,8 +4646,7 @@ paths: description: "Authentication to check" schema: $ref: "#/definitions/AuthConfig" - tags: - - "Misc" + tags: ["Registry"] /info: get: summary: "Get system information" diff --git a/api/types/registry/authenticate.go b/api/types/registry/authenticate.go new file mode 100644 index 0000000000..5e37d19bd4 --- /dev/null +++ b/api/types/registry/authenticate.go @@ -0,0 +1,21 @@ +package registry + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// AuthenticateOKBody authenticate o k body +// swagger:model AuthenticateOKBody +type AuthenticateOKBody struct { + + // An opaque token used to authenticate a user after a successful login + // Required: true + IdentityToken string `json:"IdentityToken"` + + // The status of the authentication + // Required: true + Status string `json:"Status"` +} diff --git a/api/types/types.go b/api/types/types.go index fd58d4d856..6f5f753c8b 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,17 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// AuthResponse contains response of Remote API: -// POST "/auth" -type AuthResponse struct { - // Status is the authentication status - Status string `json:"Status"` - - // IdentityToken is an opaque token used for authenticating - // a user after a successful login. - IdentityToken string `json:"IdentityToken,omitempty"` -} - // ContainerWaitResponse contains response of Remote API: // POST "/containers/"+containerID+"/wait" type ContainerWaitResponse struct { diff --git a/client/interface.go b/client/interface.go index b303d2fde8..f044c32352 100644 --- a/client/interface.go +++ b/client/interface.go @@ -127,7 +127,7 @@ type SwarmAPIClient interface { type SystemAPIClient interface { Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) Info(ctx context.Context) (types.Info, error) - RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) + RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) DiskUsage(ctx context.Context) (types.DiskUsage, error) Ping(ctx context.Context) (bool, error) } diff --git a/client/login.go b/client/login.go index d8d277ccba..600dc7196f 100644 --- a/client/login.go +++ b/client/login.go @@ -6,22 +6,23 @@ import ( "net/url" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" "golang.org/x/net/context" ) // RegistryLogin authenticates the docker server with a given docker registry. // It returns UnauthorizerError when the authentication fails. -func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) { +func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) { resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) if resp.statusCode == http.StatusUnauthorized { - return types.AuthResponse{}, unauthorizedError{err} + return registry.AuthenticateOKBody{}, unauthorizedError{err} } if err != nil { - return types.AuthResponse{}, err + return registry.AuthenticateOKBody{}, err } - var response types.AuthResponse + var response registry.AuthenticateOKBody err = json.NewDecoder(resp.body).Decode(&response) ensureReaderClosed(resp) return response, err diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 43e8da75e9..2a7c8f2053 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -16,4 +16,5 @@ swagger generate operation -f api/swagger.yaml \ -n VolumesList \ -n VolumesCreate \ -n ContainerCreate \ - -n ContainerUpdate + -n ContainerUpdate \ + -n Authenticate From 181562c2e54225d6ce737d98b03d3157451a5dbc Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 20 Oct 2016 15:56:27 -0700 Subject: [PATCH 13/13] Generate ContainerWait response from the swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/container/container_routes.go | 4 ++-- api/swagger.yaml | 9 +++++---- api/types/container/container_wait.go | 17 +++++++++++++++++ api/types/types.go | 7 ------- client/container_wait.go | 6 +++--- client/container_wait_test.go | 4 ++-- client/interface.go | 2 +- daemon/cluster/executor/backend.go | 2 +- hack/generate-swagger-api.sh | 3 ++- integration-cli/docker_api_containers_test.go | 4 ++-- 10 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 api/types/container/container_wait.go diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index f721268ba8..c0c008c010 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -283,8 +283,8 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons return err } - return httputils.WriteJSON(w, http.StatusOK, &types.ContainerWaitResponse{ - StatusCode: status, + return httputils.WriteJSON(w, http.StatusOK, &container.ContainerWaitOKBody{ + StatusCode: int64(status), }) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 79cde950a5..94cc36a172 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3780,18 +3780,19 @@ paths: post: summary: "Wait for a container" description: "Block until a container stops, then returns the exit code." - operationId: "PostContainerWait" - produces: - - "application/json" + operationId: "ContainerWait" + produces: ["application/json"] responses: 200: - description: "no error" + description: "The container has exit." schema: type: "object" + required: [StatusCode] properties: StatusCode: description: "Exit code of the container" type: "integer" + x-nullable: false 404: description: "no such container" schema: diff --git a/api/types/container/container_wait.go b/api/types/container/container_wait.go new file mode 100644 index 0000000000..16cf335321 --- /dev/null +++ b/api/types/container/container_wait.go @@ -0,0 +1,17 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerWaitOKBody container wait o k body +// swagger:model ContainerWaitOKBody +type ContainerWaitOKBody struct { + + // Exit code of the container + // Required: true + StatusCode int64 `json:"StatusCode"` +} diff --git a/api/types/types.go b/api/types/types.go index 6f5f753c8b..bd9bf7bf6a 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,13 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerWaitResponse contains response of Remote API: -// POST "/containers/"+containerID+"/wait" -type ContainerWaitResponse struct { - // StatusCode is the status code of the wait job - StatusCode int `json:"StatusCode"` -} - // ContainerChange contains response of Remote API: // GET "/containers/{name:.*}/changes" type ContainerChange struct { diff --git a/client/container_wait.go b/client/container_wait.go index 8a858f0ea3..93212c70ee 100644 --- a/client/container_wait.go +++ b/client/container_wait.go @@ -5,19 +5,19 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // ContainerWait pauses execution until a container exits. // It returns the API status code as response of its readiness. -func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int, error) { +func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int64, error) { resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil) if err != nil { return -1, err } defer ensureReaderClosed(resp) - var res types.ContainerWaitResponse + var res container.ContainerWaitOKBody if err := json.NewDecoder(resp.body).Decode(&res); err != nil { return -1, err } diff --git a/client/container_wait_test.go b/client/container_wait_test.go index dab5acbdd3..9300bc0a54 100644 --- a/client/container_wait_test.go +++ b/client/container_wait_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -36,7 +36,7 @@ func TestContainerWait(t *testing.T) { if !strings.HasPrefix(req.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal(types.ContainerWaitResponse{ + b, err := json.Marshal(container.ContainerWaitOKBody{ StatusCode: 15, }) if err != nil { diff --git a/client/interface.go b/client/interface.go index f044c32352..a78cb759cd 100644 --- a/client/interface.go +++ b/client/interface.go @@ -59,7 +59,7 @@ type ContainerAPIClient interface { ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) ContainerUnpause(ctx context.Context, container string) error ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) - ContainerWait(ctx context.Context, container string) (int, error) + ContainerWait(ctx context.Context, container string) (int64, error) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error ContainersPrune(ctx context.Context, cfg types.ContainersPruneConfig) (types.ContainersPruneReport, error) diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index c34c2076e0..fba4adec18 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -23,7 +23,7 @@ type Backend interface { FindNetwork(idName string) (libnetwork.Network, error) SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error) + CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 2a7c8f2053..d46eaa33de 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -17,4 +17,5 @@ swagger generate operation -f api/swagger.yaml \ -n VolumesCreate \ -n ContainerCreate \ -n ContainerUpdate \ - -n Authenticate + -n Authenticate \ + -n ContainerWait diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index e4415a81be..766d676be9 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -957,9 +957,9 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) { c.Assert(status, checker.Equals, http.StatusOK) c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil) - var waitres types.ContainerWaitResponse + var waitres containertypes.ContainerWaitOKBody c.Assert(json.Unmarshal(body, &waitres), checker.IsNil) - c.Assert(waitres.StatusCode, checker.Equals, 0) + c.Assert(waitres.StatusCode, checker.Equals, int64(0)) } func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {