Skip to content

Commit ec69501

Browse files
committed
api/types: move ServiceCreateResponse, and generate from swagger
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 5b3e655 commit ec69501

10 files changed

Lines changed: 63 additions & 32 deletions

File tree

api/server/router/swarm/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Backend interface {
1919
UnlockSwarm(req swarm.UnlockRequest) error
2020
GetServices(types.ServiceListOptions) ([]swarm.Service, error)
2121
GetService(idOrName string, insertDefaults bool) (swarm.Service, error)
22-
CreateService(swarm.ServiceSpec, string, bool) (*types.ServiceCreateResponse, error)
22+
CreateService(swarm.ServiceSpec, string, bool) (*swarm.ServiceCreateResponse, error)
2323
UpdateService(string, uint64, swarm.ServiceSpec, types.ServiceUpdateOptions, bool) (*swarm.ServiceUpdateResponse, error)
2424
RemoveService(string) error
2525
ServiceLogs(context.Context, *backend.LogSelector, *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error)

api/swagger.yaml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4487,6 +4487,29 @@ definitions:
44874487
description: "The image ID of an image that was deleted"
44884488
type: "string"
44894489

4490+
ServiceCreateResponse:
4491+
type: "object"
4492+
description: |
4493+
contains the information returned to a client on the
4494+
creation of a new service.
4495+
properties:
4496+
ID:
4497+
description: "The ID of the created service."
4498+
type: "string"
4499+
x-nullable: false
4500+
example: "ak7w3gjqoa3kuz8xcpnyy0pvl"
4501+
Warnings:
4502+
description: |
4503+
Optional warning message.
4504+
4505+
FIXME(thaJeztah): this should have "omitempty" in the generated type.
4506+
type: "array"
4507+
x-nullable: true
4508+
items:
4509+
type: "string"
4510+
example:
4511+
- "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
4512+
44904513
ServiceUpdateResponse:
44914514
type: "object"
44924515
properties:
@@ -4496,7 +4519,8 @@ definitions:
44964519
items:
44974520
type: "string"
44984521
example:
4499-
Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
4522+
Warnings:
4523+
- "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
45004524

45014525
ContainerSummary:
45024526
type: "object"
@@ -11099,18 +11123,7 @@ paths:
1109911123
201:
1110011124
description: "no error"
1110111125
schema:
11102-
type: "object"
11103-
title: "ServiceCreateResponse"
11104-
properties:
11105-
ID:
11106-
description: "The ID of the created service."
11107-
type: "string"
11108-
Warning:
11109-
description: "Optional warning message"
11110-
type: "string"
11111-
example:
11112-
ID: "ak7w3gjqoa3kuz8xcpnyy0pvl"
11113-
Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
11126+
$ref: "#/definitions/ServiceCreateResponse"
1111411127
400:
1111511128
description: "bad parameter"
1111611129
schema:

api/types/client.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,6 @@ type ServiceCreateOptions struct {
322322
QueryRegistry bool
323323
}
324324

325-
// ServiceCreateResponse contains the information returned to a client
326-
// on the creation of a new service.
327-
type ServiceCreateResponse struct {
328-
// ID is the ID of the created service.
329-
ID string
330-
// Warnings is a set of non-fatal warning messages to pass on to the user.
331-
Warnings []string `json:",omitempty"`
332-
}
333-
334325
// Values for RegistryAuthFrom in ServiceUpdateOptions
335326
const (
336327
RegistryAuthFromSpec = "spec"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package swarm
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
// ServiceCreateResponse contains the information returned to a client on the
7+
// creation of a new service.
8+
//
9+
// swagger:model ServiceCreateResponse
10+
type ServiceCreateResponse struct {
11+
12+
// The ID of the created service.
13+
ID string `json:"ID,omitempty"`
14+
15+
// Optional warning message.
16+
//
17+
// FIXME(thaJeztah): this should have "omitempty" in the generated type.
18+
//
19+
Warnings []string `json:"Warnings"`
20+
}

api/types/types_deprecated.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ type ImageSummary = image.Summary
8080
// Deprecated: use [image.Metadata].
8181
type ImageMetadata = image.Metadata
8282

83+
// ServiceCreateResponse contains the information returned to a client
84+
// on the creation of a new service.
85+
//
86+
// Deprecated: use [swarm.ServiceCreateResponse].
87+
type ServiceCreateResponse = swarm.ServiceCreateResponse
88+
8389
// ServiceUpdateResponse service update response.
8490
//
8591
// Deprecated: use [swarm.ServiceUpdateResponse].

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type PluginAPIClient interface {
141141

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

client/service_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
)
1818

1919
// ServiceCreate creates a new service.
20-
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) {
21-
var response types.ServiceCreateResponse
20+
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
21+
var response swarm.ServiceCreateResponse
2222

2323
// Make sure we negotiated (if the client is configured to do so),
2424
// as code below contains API-version specific handling of options.

client/service_create_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestServiceCreate(t *testing.T) {
3838
if req.Method != http.MethodPost {
3939
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
4040
}
41-
b, err := json.Marshal(types.ServiceCreateResponse{
41+
b, err := json.Marshal(swarm.ServiceCreateResponse{
4242
ID: "service_id",
4343
})
4444
if err != nil {
@@ -77,7 +77,7 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
7777
assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1))
7878

7979
p := serviceSpec.TaskTemplate.Placement.Platforms[0]
80-
b, err := json.Marshal(types.ServiceCreateResponse{
80+
b, err := json.Marshal(swarm.ServiceCreateResponse{
8181
ID: "service_" + p.OS + "_" + p.Architecture,
8282
})
8383
if err != nil {
@@ -153,7 +153,7 @@ func TestServiceCreateDigestPinning(t *testing.T) {
153153
}
154154
serviceCreateImage = service.TaskTemplate.ContainerSpec.Image
155155

156-
b, err := json.Marshal(types.ServiceCreateResponse{
156+
b, err := json.Marshal(swarm.ServiceCreateResponse{
157157
ID: "service_id",
158158
})
159159
if err != nil {

daemon/cluster/services.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func (c *Cluster) GetService(input string, insertDefaults bool) (swarm.Service,
180180
}
181181

182182
// CreateService creates a new service in a managed swarm cluster.
183-
func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRegistry bool) (*types.ServiceCreateResponse, error) {
184-
var resp *types.ServiceCreateResponse
183+
func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRegistry bool) (*swarm.ServiceCreateResponse, error) {
184+
var resp *swarm.ServiceCreateResponse
185185
err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
186186
err := c.populateNetworkID(ctx, state.controlClient, &s)
187187
if err != nil {
@@ -193,7 +193,7 @@ func (c *Cluster) CreateService(s swarm.ServiceSpec, encodedAuth string, queryRe
193193
return errdefs.InvalidParameter(err)
194194
}
195195

196-
resp = &types.ServiceCreateResponse{}
196+
resp = &swarm.ServiceCreateResponse{}
197197

198198
switch serviceSpec.Task.Runtime.(type) {
199199
case *swarmapi.TaskSpec_Attachment:

hack/generate-swagger-api.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ swagger generate operation -f api/swagger.yaml \
4242

4343
swagger generate model -f api/swagger.yaml \
4444
-t api -m types/swarm --skip-validator -C api/swagger-gen.yaml \
45+
-n ServiceCreateResponse \
4546
-n ServiceUpdateResponse

0 commit comments

Comments
 (0)