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