1package apimanagement
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// APIReleaseClient is the apiManagement Client
19type APIReleaseClient struct {
20	BaseClient
21}
22
23// NewAPIReleaseClient creates an instance of the APIReleaseClient client.
24func NewAPIReleaseClient(subscriptionID string) APIReleaseClient {
25	return NewAPIReleaseClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAPIReleaseClientWithBaseURI creates an instance of the APIReleaseClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAPIReleaseClientWithBaseURI(baseURI string, subscriptionID string) APIReleaseClient {
31	return APIReleaseClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates a new Release for the API.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// apiid - API identifier. Must be unique in the current API Management service instance.
39// releaseID - release identifier within an API. Must be unique in the current API Management service instance.
40// parameters - create parameters.
41// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
42func (client APIReleaseClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, parameters APIReleaseContract, ifMatch string) (result APIReleaseContract, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.CreateOrUpdate")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: serviceName,
55			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
56				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
58		{TargetValue: apiid,
59			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
60				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
61		{TargetValue: releaseID,
62			Constraints: []validation.Constraint{{Target: "releaseID", Name: validation.MaxLength, Rule: 80, Chain: nil},
63				{Target: "releaseID", Name: validation.MinLength, Rule: 1, Chain: nil},
64				{Target: "releaseID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
65		return result, validation.NewError("apimanagement.APIReleaseClient", "CreateOrUpdate", err.Error())
66	}
67
68	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, releaseID, parameters, ifMatch)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "CreateOrUpdate", nil, "Failure preparing request")
71		return
72	}
73
74	resp, err := client.CreateOrUpdateSender(req)
75	if err != nil {
76		result.Response = autorest.Response{Response: resp}
77		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "CreateOrUpdate", resp, "Failure sending request")
78		return
79	}
80
81	result, err = client.CreateOrUpdateResponder(resp)
82	if err != nil {
83		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "CreateOrUpdate", resp, "Failure responding to request")
84		return
85	}
86
87	return
88}
89
90// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
91func (client APIReleaseClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, parameters APIReleaseContract, ifMatch string) (*http.Request, error) {
92	pathParameters := map[string]interface{}{
93		"apiId":             autorest.Encode("path", apiid),
94		"releaseId":         autorest.Encode("path", releaseID),
95		"resourceGroupName": autorest.Encode("path", resourceGroupName),
96		"serviceName":       autorest.Encode("path", serviceName),
97		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
98	}
99
100	const APIVersion = "2019-12-01-preview"
101	queryParameters := map[string]interface{}{
102		"api-version": APIVersion,
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsContentType("application/json; charset=utf-8"),
107		autorest.AsPut(),
108		autorest.WithBaseURL(client.BaseURI),
109		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases/{releaseId}", pathParameters),
110		autorest.WithJSON(parameters),
111		autorest.WithQueryParameters(queryParameters))
112	if len(ifMatch) > 0 {
113		preparer = autorest.DecoratePreparer(preparer,
114			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
115	}
116	return preparer.Prepare((&http.Request{}).WithContext(ctx))
117}
118
119// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
120// http.Response Body if it receives an error.
121func (client APIReleaseClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
122	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
123}
124
125// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
126// closes the http.Response Body.
127func (client APIReleaseClient) CreateOrUpdateResponder(resp *http.Response) (result APIReleaseContract, err error) {
128	err = autorest.Respond(
129		resp,
130		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
131		autorest.ByUnmarshallingJSON(&result),
132		autorest.ByClosing())
133	result.Response = autorest.Response{Response: resp}
134	return
135}
136
137// Delete deletes the specified release in the API.
138// Parameters:
139// resourceGroupName - the name of the resource group.
140// serviceName - the name of the API Management service.
141// apiid - API identifier. Must be unique in the current API Management service instance.
142// releaseID - release identifier within an API. Must be unique in the current API Management service instance.
143// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
144// request or it should be * for unconditional update.
145func (client APIReleaseClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, ifMatch string) (result autorest.Response, err error) {
146	if tracing.IsEnabled() {
147		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.Delete")
148		defer func() {
149			sc := -1
150			if result.Response != nil {
151				sc = result.Response.StatusCode
152			}
153			tracing.EndSpan(ctx, sc, err)
154		}()
155	}
156	if err := validation.Validate([]validation.Validation{
157		{TargetValue: serviceName,
158			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
159				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
160				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
161		{TargetValue: apiid,
162			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
163				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
164		{TargetValue: releaseID,
165			Constraints: []validation.Constraint{{Target: "releaseID", Name: validation.MaxLength, Rule: 80, Chain: nil},
166				{Target: "releaseID", Name: validation.MinLength, Rule: 1, Chain: nil},
167				{Target: "releaseID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
168		return result, validation.NewError("apimanagement.APIReleaseClient", "Delete", err.Error())
169	}
170
171	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, releaseID, ifMatch)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Delete", nil, "Failure preparing request")
174		return
175	}
176
177	resp, err := client.DeleteSender(req)
178	if err != nil {
179		result.Response = resp
180		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Delete", resp, "Failure sending request")
181		return
182	}
183
184	result, err = client.DeleteResponder(resp)
185	if err != nil {
186		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Delete", resp, "Failure responding to request")
187		return
188	}
189
190	return
191}
192
193// DeletePreparer prepares the Delete request.
194func (client APIReleaseClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, ifMatch string) (*http.Request, error) {
195	pathParameters := map[string]interface{}{
196		"apiId":             autorest.Encode("path", apiid),
197		"releaseId":         autorest.Encode("path", releaseID),
198		"resourceGroupName": autorest.Encode("path", resourceGroupName),
199		"serviceName":       autorest.Encode("path", serviceName),
200		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
201	}
202
203	const APIVersion = "2019-12-01-preview"
204	queryParameters := map[string]interface{}{
205		"api-version": APIVersion,
206	}
207
208	preparer := autorest.CreatePreparer(
209		autorest.AsDelete(),
210		autorest.WithBaseURL(client.BaseURI),
211		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases/{releaseId}", pathParameters),
212		autorest.WithQueryParameters(queryParameters),
213		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
214	return preparer.Prepare((&http.Request{}).WithContext(ctx))
215}
216
217// DeleteSender sends the Delete request. The method will close the
218// http.Response Body if it receives an error.
219func (client APIReleaseClient) DeleteSender(req *http.Request) (*http.Response, error) {
220	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
221}
222
223// DeleteResponder handles the response to the Delete request. The method always
224// closes the http.Response Body.
225func (client APIReleaseClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
226	err = autorest.Respond(
227		resp,
228		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
229		autorest.ByClosing())
230	result.Response = resp
231	return
232}
233
234// Get returns the details of an API release.
235// Parameters:
236// resourceGroupName - the name of the resource group.
237// serviceName - the name of the API Management service.
238// apiid - API identifier. Must be unique in the current API Management service instance.
239// releaseID - release identifier within an API. Must be unique in the current API Management service instance.
240func (client APIReleaseClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string) (result APIReleaseContract, err error) {
241	if tracing.IsEnabled() {
242		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.Get")
243		defer func() {
244			sc := -1
245			if result.Response.Response != nil {
246				sc = result.Response.Response.StatusCode
247			}
248			tracing.EndSpan(ctx, sc, err)
249		}()
250	}
251	if err := validation.Validate([]validation.Validation{
252		{TargetValue: serviceName,
253			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
254				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
255				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
256		{TargetValue: apiid,
257			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
258				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
259		{TargetValue: releaseID,
260			Constraints: []validation.Constraint{{Target: "releaseID", Name: validation.MaxLength, Rule: 80, Chain: nil},
261				{Target: "releaseID", Name: validation.MinLength, Rule: 1, Chain: nil},
262				{Target: "releaseID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
263		return result, validation.NewError("apimanagement.APIReleaseClient", "Get", err.Error())
264	}
265
266	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, releaseID)
267	if err != nil {
268		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Get", nil, "Failure preparing request")
269		return
270	}
271
272	resp, err := client.GetSender(req)
273	if err != nil {
274		result.Response = autorest.Response{Response: resp}
275		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Get", resp, "Failure sending request")
276		return
277	}
278
279	result, err = client.GetResponder(resp)
280	if err != nil {
281		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Get", resp, "Failure responding to request")
282		return
283	}
284
285	return
286}
287
288// GetPreparer prepares the Get request.
289func (client APIReleaseClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string) (*http.Request, error) {
290	pathParameters := map[string]interface{}{
291		"apiId":             autorest.Encode("path", apiid),
292		"releaseId":         autorest.Encode("path", releaseID),
293		"resourceGroupName": autorest.Encode("path", resourceGroupName),
294		"serviceName":       autorest.Encode("path", serviceName),
295		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
296	}
297
298	const APIVersion = "2019-12-01-preview"
299	queryParameters := map[string]interface{}{
300		"api-version": APIVersion,
301	}
302
303	preparer := autorest.CreatePreparer(
304		autorest.AsGet(),
305		autorest.WithBaseURL(client.BaseURI),
306		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases/{releaseId}", pathParameters),
307		autorest.WithQueryParameters(queryParameters))
308	return preparer.Prepare((&http.Request{}).WithContext(ctx))
309}
310
311// GetSender sends the Get request. The method will close the
312// http.Response Body if it receives an error.
313func (client APIReleaseClient) GetSender(req *http.Request) (*http.Response, error) {
314	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
315}
316
317// GetResponder handles the response to the Get request. The method always
318// closes the http.Response Body.
319func (client APIReleaseClient) GetResponder(resp *http.Response) (result APIReleaseContract, err error) {
320	err = autorest.Respond(
321		resp,
322		azure.WithErrorUnlessStatusCode(http.StatusOK),
323		autorest.ByUnmarshallingJSON(&result),
324		autorest.ByClosing())
325	result.Response = autorest.Response{Response: resp}
326	return
327}
328
329// GetEntityTag returns the etag of an API release.
330// Parameters:
331// resourceGroupName - the name of the resource group.
332// serviceName - the name of the API Management service.
333// apiid - API identifier. Must be unique in the current API Management service instance.
334// releaseID - release identifier within an API. Must be unique in the current API Management service instance.
335func (client APIReleaseClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string) (result autorest.Response, err error) {
336	if tracing.IsEnabled() {
337		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.GetEntityTag")
338		defer func() {
339			sc := -1
340			if result.Response != nil {
341				sc = result.Response.StatusCode
342			}
343			tracing.EndSpan(ctx, sc, err)
344		}()
345	}
346	if err := validation.Validate([]validation.Validation{
347		{TargetValue: serviceName,
348			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
349				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
350				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
351		{TargetValue: apiid,
352			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
353				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
354		{TargetValue: releaseID,
355			Constraints: []validation.Constraint{{Target: "releaseID", Name: validation.MaxLength, Rule: 80, Chain: nil},
356				{Target: "releaseID", Name: validation.MinLength, Rule: 1, Chain: nil},
357				{Target: "releaseID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
358		return result, validation.NewError("apimanagement.APIReleaseClient", "GetEntityTag", err.Error())
359	}
360
361	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, releaseID)
362	if err != nil {
363		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "GetEntityTag", nil, "Failure preparing request")
364		return
365	}
366
367	resp, err := client.GetEntityTagSender(req)
368	if err != nil {
369		result.Response = resp
370		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "GetEntityTag", resp, "Failure sending request")
371		return
372	}
373
374	result, err = client.GetEntityTagResponder(resp)
375	if err != nil {
376		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "GetEntityTag", resp, "Failure responding to request")
377		return
378	}
379
380	return
381}
382
383// GetEntityTagPreparer prepares the GetEntityTag request.
384func (client APIReleaseClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string) (*http.Request, error) {
385	pathParameters := map[string]interface{}{
386		"apiId":             autorest.Encode("path", apiid),
387		"releaseId":         autorest.Encode("path", releaseID),
388		"resourceGroupName": autorest.Encode("path", resourceGroupName),
389		"serviceName":       autorest.Encode("path", serviceName),
390		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
391	}
392
393	const APIVersion = "2019-12-01-preview"
394	queryParameters := map[string]interface{}{
395		"api-version": APIVersion,
396	}
397
398	preparer := autorest.CreatePreparer(
399		autorest.AsHead(),
400		autorest.WithBaseURL(client.BaseURI),
401		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases/{releaseId}", pathParameters),
402		autorest.WithQueryParameters(queryParameters))
403	return preparer.Prepare((&http.Request{}).WithContext(ctx))
404}
405
406// GetEntityTagSender sends the GetEntityTag request. The method will close the
407// http.Response Body if it receives an error.
408func (client APIReleaseClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
409	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
410}
411
412// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
413// closes the http.Response Body.
414func (client APIReleaseClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
415	err = autorest.Respond(
416		resp,
417		azure.WithErrorUnlessStatusCode(http.StatusOK),
418		autorest.ByClosing())
419	result.Response = resp
420	return
421}
422
423// ListByService lists all releases of an API. An API release is created when making an API Revision current. Releases
424// are also used to rollback to previous revisions. Results will be paged and can be constrained by the $top and $skip
425// parameters.
426// Parameters:
427// resourceGroupName - the name of the resource group.
428// serviceName - the name of the API Management service.
429// apiid - API identifier. Must be unique in the current API Management service instance.
430// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
431// |</br>|-------------|-------------|-------------|-------------|</br>| notes | filter | ge, le, eq, ne, gt,
432// lt | substringof, contains, startswith, endswith | </br>
433// top - number of records to return.
434// skip - number of records to skip.
435func (client APIReleaseClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIReleaseCollectionPage, err error) {
436	if tracing.IsEnabled() {
437		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.ListByService")
438		defer func() {
439			sc := -1
440			if result.arc.Response.Response != nil {
441				sc = result.arc.Response.Response.StatusCode
442			}
443			tracing.EndSpan(ctx, sc, err)
444		}()
445	}
446	if err := validation.Validate([]validation.Validation{
447		{TargetValue: serviceName,
448			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
449				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
450				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
451		{TargetValue: apiid,
452			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
453				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
454		{TargetValue: top,
455			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
456				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
457		{TargetValue: skip,
458			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
459				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
460		return result, validation.NewError("apimanagement.APIReleaseClient", "ListByService", err.Error())
461	}
462
463	result.fn = client.listByServiceNextResults
464	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
465	if err != nil {
466		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "ListByService", nil, "Failure preparing request")
467		return
468	}
469
470	resp, err := client.ListByServiceSender(req)
471	if err != nil {
472		result.arc.Response = autorest.Response{Response: resp}
473		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "ListByService", resp, "Failure sending request")
474		return
475	}
476
477	result.arc, err = client.ListByServiceResponder(resp)
478	if err != nil {
479		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "ListByService", resp, "Failure responding to request")
480		return
481	}
482	if result.arc.hasNextLink() && result.arc.IsEmpty() {
483		err = result.NextWithContext(ctx)
484		return
485	}
486
487	return
488}
489
490// ListByServicePreparer prepares the ListByService request.
491func (client APIReleaseClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) {
492	pathParameters := map[string]interface{}{
493		"apiId":             autorest.Encode("path", apiid),
494		"resourceGroupName": autorest.Encode("path", resourceGroupName),
495		"serviceName":       autorest.Encode("path", serviceName),
496		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
497	}
498
499	const APIVersion = "2019-12-01-preview"
500	queryParameters := map[string]interface{}{
501		"api-version": APIVersion,
502	}
503	if len(filter) > 0 {
504		queryParameters["$filter"] = autorest.Encode("query", filter)
505	}
506	if top != nil {
507		queryParameters["$top"] = autorest.Encode("query", *top)
508	}
509	if skip != nil {
510		queryParameters["$skip"] = autorest.Encode("query", *skip)
511	}
512
513	preparer := autorest.CreatePreparer(
514		autorest.AsGet(),
515		autorest.WithBaseURL(client.BaseURI),
516		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases", pathParameters),
517		autorest.WithQueryParameters(queryParameters))
518	return preparer.Prepare((&http.Request{}).WithContext(ctx))
519}
520
521// ListByServiceSender sends the ListByService request. The method will close the
522// http.Response Body if it receives an error.
523func (client APIReleaseClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
524	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
525}
526
527// ListByServiceResponder handles the response to the ListByService request. The method always
528// closes the http.Response Body.
529func (client APIReleaseClient) ListByServiceResponder(resp *http.Response) (result APIReleaseCollection, err error) {
530	err = autorest.Respond(
531		resp,
532		azure.WithErrorUnlessStatusCode(http.StatusOK),
533		autorest.ByUnmarshallingJSON(&result),
534		autorest.ByClosing())
535	result.Response = autorest.Response{Response: resp}
536	return
537}
538
539// listByServiceNextResults retrieves the next set of results, if any.
540func (client APIReleaseClient) listByServiceNextResults(ctx context.Context, lastResults APIReleaseCollection) (result APIReleaseCollection, err error) {
541	req, err := lastResults.aPIReleaseCollectionPreparer(ctx)
542	if err != nil {
543		return result, autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "listByServiceNextResults", nil, "Failure preparing next results request")
544	}
545	if req == nil {
546		return
547	}
548	resp, err := client.ListByServiceSender(req)
549	if err != nil {
550		result.Response = autorest.Response{Response: resp}
551		return result, autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "listByServiceNextResults", resp, "Failure sending next results request")
552	}
553	result, err = client.ListByServiceResponder(resp)
554	if err != nil {
555		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "listByServiceNextResults", resp, "Failure responding to next results request")
556	}
557	return
558}
559
560// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
561func (client APIReleaseClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIReleaseCollectionIterator, err error) {
562	if tracing.IsEnabled() {
563		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.ListByService")
564		defer func() {
565			sc := -1
566			if result.Response().Response.Response != nil {
567				sc = result.page.Response().Response.Response.StatusCode
568			}
569			tracing.EndSpan(ctx, sc, err)
570		}()
571	}
572	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
573	return
574}
575
576// Update updates the details of the release of the API specified by its identifier.
577// Parameters:
578// resourceGroupName - the name of the resource group.
579// serviceName - the name of the API Management service.
580// apiid - API identifier. Must be unique in the current API Management service instance.
581// releaseID - release identifier within an API. Must be unique in the current API Management service instance.
582// parameters - API Release Update parameters.
583// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
584// request or it should be * for unconditional update.
585func (client APIReleaseClient) Update(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, parameters APIReleaseContract, ifMatch string) (result autorest.Response, err error) {
586	if tracing.IsEnabled() {
587		ctx = tracing.StartSpan(ctx, fqdn+"/APIReleaseClient.Update")
588		defer func() {
589			sc := -1
590			if result.Response != nil {
591				sc = result.Response.StatusCode
592			}
593			tracing.EndSpan(ctx, sc, err)
594		}()
595	}
596	if err := validation.Validate([]validation.Validation{
597		{TargetValue: serviceName,
598			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
599				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
600				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
601		{TargetValue: apiid,
602			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
603				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
604		{TargetValue: releaseID,
605			Constraints: []validation.Constraint{{Target: "releaseID", Name: validation.MaxLength, Rule: 80, Chain: nil},
606				{Target: "releaseID", Name: validation.MinLength, Rule: 1, Chain: nil},
607				{Target: "releaseID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
608		return result, validation.NewError("apimanagement.APIReleaseClient", "Update", err.Error())
609	}
610
611	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, apiid, releaseID, parameters, ifMatch)
612	if err != nil {
613		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Update", nil, "Failure preparing request")
614		return
615	}
616
617	resp, err := client.UpdateSender(req)
618	if err != nil {
619		result.Response = resp
620		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Update", resp, "Failure sending request")
621		return
622	}
623
624	result, err = client.UpdateResponder(resp)
625	if err != nil {
626		err = autorest.NewErrorWithError(err, "apimanagement.APIReleaseClient", "Update", resp, "Failure responding to request")
627		return
628	}
629
630	return
631}
632
633// UpdatePreparer prepares the Update request.
634func (client APIReleaseClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, releaseID string, parameters APIReleaseContract, ifMatch string) (*http.Request, error) {
635	pathParameters := map[string]interface{}{
636		"apiId":             autorest.Encode("path", apiid),
637		"releaseId":         autorest.Encode("path", releaseID),
638		"resourceGroupName": autorest.Encode("path", resourceGroupName),
639		"serviceName":       autorest.Encode("path", serviceName),
640		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
641	}
642
643	const APIVersion = "2019-12-01-preview"
644	queryParameters := map[string]interface{}{
645		"api-version": APIVersion,
646	}
647
648	preparer := autorest.CreatePreparer(
649		autorest.AsContentType("application/json; charset=utf-8"),
650		autorest.AsPatch(),
651		autorest.WithBaseURL(client.BaseURI),
652		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/releases/{releaseId}", pathParameters),
653		autorest.WithJSON(parameters),
654		autorest.WithQueryParameters(queryParameters),
655		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
656	return preparer.Prepare((&http.Request{}).WithContext(ctx))
657}
658
659// UpdateSender sends the Update request. The method will close the
660// http.Response Body if it receives an error.
661func (client APIReleaseClient) UpdateSender(req *http.Request) (*http.Response, error) {
662	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
663}
664
665// UpdateResponder handles the response to the Update request. The method always
666// closes the http.Response Body.
667func (client APIReleaseClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
668	err = autorest.Respond(
669		resp,
670		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
671		autorest.ByClosing())
672	result.Response = resp
673	return
674}
675