Prechádzať zdrojové kódy

api/types: move ServiceCreateResponse, and generate from swagger

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 rokov pred
rodič
commit
ec69501e94

+ 1 - 1
api/server/router/swarm/backend.go

@@ -19,7 +19,7 @@ type Backend interface {
 	UnlockSwarm(req swarm.UnlockRequest) error
 	UnlockSwarm(req swarm.UnlockRequest) error
 	GetServices(types.ServiceListOptions) ([]swarm.Service, error)
 	GetServices(types.ServiceListOptions) ([]swarm.Service, error)
 	GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
 	GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
-	CreateService(swarm.ServiceSpec, string, bool) (*types.ServiceCreateResponse, error)
+	CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
 	UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
 	UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
 	RemoveService(string) error
 	RemoveService(string) error
 	ServiceLogs(context.Context, *backend.LogSelector, *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error)
 	ServiceLogs(context.Context, *backend.LogSelector, *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error)

+ 26 - 13
api/swagger.yaml

@@ -4487,6 +4487,29 @@ definitions:
         description: "The image ID of an image that was deleted"
         description: "The image ID of an image that was deleted"
         type: "string"
         type: "string"
 
 
+  ServiceCreateResponse:
+    type: "object"
+    description: |
+      contains the information returned to a client on the
+      creation of a new service.
+    properties:
+      ID:
+        description: "The ID of the created service."
+        type: "string"
+        x-nullable: false
+        example: "ak7w3gjqoa3kuz8xcpnyy0pvl"
+      Warnings:
+        description: |
+          Optional warning message.
+
+          FIXME(thaJeztah): this should have "omitempty" in the generated type.
+        type: "array"
+        x-nullable: true
+        items:
+          type: "string"
+        example:
+          - "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
+
   ServiceUpdateResponse:
   ServiceUpdateResponse:
     type: "object"
     type: "object"
     properties:
     properties:
@@ -4496,7 +4519,8 @@ definitions:
         items:
         items:
           type: "string"
           type: "string"
     example:
     example:
-      Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
+      Warnings:
+        - "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
 
 
   ContainerSummary:
   ContainerSummary:
     type: "object"
     type: "object"
@@ -11099,18 +11123,7 @@ paths:
         201:
         201:
           description: "no error"
           description: "no error"
           schema:
           schema:
-            type: "object"
-            title: "ServiceCreateResponse"
-            properties:
-              ID:
-                description: "The ID of the created service."
-                type: "string"
-              Warning:
-                description: "Optional warning message"
-                type: "string"
-            example:
-              ID: "ak7w3gjqoa3kuz8xcpnyy0pvl"
-              Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
+            $ref: "#/definitions/ServiceCreateResponse"
         400:
         400:
           description: "bad parameter"
           description: "bad parameter"
           schema:
           schema:

+ 0 - 9
api/types/client.go

@@ -322,15 +322,6 @@ type ServiceCreateOptions struct {
 	QueryRegistry bool
 	QueryRegistry bool
 }
 }
 
 
-// ServiceCreateResponse contains the information returned to a client
-// on the creation of a new service.
-type ServiceCreateResponse struct {
-	// ID is the ID of the created service.
-	ID string
-	// Warnings is a set of non-fatal warning messages to pass on to the user.
-	Warnings []string `json:",omitempty"`
-}
-
 // Values for RegistryAuthFrom in ServiceUpdateOptions
 // Values for RegistryAuthFrom in ServiceUpdateOptions
 const (
 const (
 	RegistryAuthFromSpec         = "spec"
 	RegistryAuthFromSpec         = "spec"

+ 20 - 0
api/types/swarm/service_create_response.go

@@ -0,0 +1,20 @@
+package swarm
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the swagger generate command
+
+// ServiceCreateResponse contains the information returned to a client on the
+// creation of a new service.
+//
+// swagger:model ServiceCreateResponse
+type ServiceCreateResponse struct {
+
+	// The ID of the created service.
+	ID string `json:"ID,omitempty"`
+
+	// Optional warning message.
+	//
+	// FIXME(thaJeztah): this should have "omitempty" in the generated type.
+	//
+	Warnings []string `json:"Warnings"`
+}

+ 6 - 0
api/types/types_deprecated.go

@@ -80,6 +80,12 @@ type ImageSummary = image.Summary
 // Deprecated: use [image.Metadata].
 // Deprecated: use [image.Metadata].
 type ImageMetadata = image.Metadata
 type ImageMetadata = image.Metadata
 
 
+// ServiceCreateResponse contains the information returned to a client
+// on the creation of a new service.
+//
+// Deprecated: use [swarm.ServiceCreateResponse].
+type ServiceCreateResponse = swarm.ServiceCreateResponse
+
 // ServiceUpdateResponse service update response.
 // ServiceUpdateResponse service update response.
 //
 //
 // Deprecated: use [swarm.ServiceUpdateResponse].
 // Deprecated: use [swarm.ServiceUpdateResponse].

+ 1 - 1
client/interface.go

@@ -141,7 +141,7 @@ type PluginAPIClient interface {
 
 
 // ServiceAPIClient defines API client methods for the services
 // ServiceAPIClient defines API client methods for the services
 type ServiceAPIClient interface {
 type ServiceAPIClient interface {
-	ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error)
+	ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
 	ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
 	ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
 	ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
 	ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
 	ServiceRemove(ctx context.Context, serviceID string) error
 	ServiceRemove(ctx context.Context, serviceID string) error

+ 2 - 2
client/service_create.go

@@ -17,8 +17,8 @@ import (
 )
 )
 
 
 // ServiceCreate creates a new service.
 // ServiceCreate creates a new service.
-func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) {
-	var response types.ServiceCreateResponse
+func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
+	var response swarm.ServiceCreateResponse
 
 
 	// Make sure we negotiated (if the client is configured to do so),
 	// Make sure we negotiated (if the client is configured to do so),
 	// as code below contains API-version specific handling of options.
 	// as code below contains API-version specific handling of options.

+ 3 - 3
client/service_create_test.go

@@ -38,7 +38,7 @@ func TestServiceCreate(t *testing.T) {
 			if req.Method != http.MethodPost {
 			if req.Method != http.MethodPost {
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
 			}
 			}
-			b, err := json.Marshal(types.ServiceCreateResponse{
+			b, err := json.Marshal(swarm.ServiceCreateResponse{
 				ID: "service_id",
 				ID: "service_id",
 			})
 			})
 			if err != nil {
 			if err != nil {
@@ -77,7 +77,7 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
 				assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1))
 				assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1))
 
 
 				p := serviceSpec.TaskTemplate.Placement.Platforms[0]
 				p := serviceSpec.TaskTemplate.Placement.Platforms[0]
-				b, err := json.Marshal(types.ServiceCreateResponse{
+				b, err := json.Marshal(swarm.ServiceCreateResponse{
 					ID: "service_" + p.OS + "_" + p.Architecture,
 					ID: "service_" + p.OS + "_" + p.Architecture,
 				})
 				})
 				if err != nil {
 				if err != nil {
@@ -153,7 +153,7 @@ func TestServiceCreateDigestPinning(t *testing.T) {
 				}
 				}
 				serviceCreateImage = service.TaskTemplate.ContainerSpec.Image
 				serviceCreateImage = service.TaskTemplate.ContainerSpec.Image
 
 
-				b, err := json.Marshal(types.ServiceCreateResponse{
+				b, err := json.Marshal(swarm.ServiceCreateResponse{
 					ID: "service_id",
 					ID: "service_id",
 				})
 				})
 				if err != nil {
 				if err != nil {

+ 3 - 3
daemon/cluster/services.go

@@ -180,8 +180,8 @@ func (c *Cluster) GetService(input string, insertDefaults bool) (swarm.Service,
 }
 }
 
 
 // CreateService creates a new service in a managed swarm cluster.
 // CreateService creates a new service in a managed swarm cluster.
-func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRegistry bool) (*types.ServiceCreateResponse, error) {
-	var resp *types.ServiceCreateResponse
+func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRegistry bool) (*swarm.ServiceCreateResponse, error) {
+	var resp *swarm.ServiceCreateResponse
 	err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
 	err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
 		err := c.populateNetworkID(ctx, state.controlClient, &s)
 		err := c.populateNetworkID(ctx, state.controlClient, &s)
 		if err != nil {
 		if err != nil {
@@ -193,7 +193,7 @@ func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRe
 			return errdefs.InvalidParameter(err)
 			return errdefs.InvalidParameter(err)
 		}
 		}
 
 
-		resp = &types.ServiceCreateResponse{}
+		resp = &swarm.ServiceCreateResponse{}
 
 
 		switch serviceSpec.Task.Runtime.(type) {
 		switch serviceSpec.Task.Runtime.(type) {
 		case *swarmapi.TaskSpec_Attachment:
 		case *swarmapi.TaskSpec_Attachment:

+ 1 - 0
hack/generate-swagger-api.sh

@@ -42,4 +42,5 @@ swagger generate operation -f api/swagger.yaml \
 
 
 swagger generate model -f api/swagger.yaml \
 swagger generate model -f api/swagger.yaml \
 	-t api -m types/swarm --skip-validator -C api/swagger-gen.yaml \
 	-t api -m types/swarm --skip-validator -C api/swagger-gen.yaml \
+	-n ServiceCreateResponse \
 	-n ServiceUpdateResponse
 	-n ServiceUpdateResponse