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// APIClient is the apiManagement Client
30type APIClient struct {
31	BaseClient
32}
33
34// NewAPIClient creates an instance of the APIClient client.
35func NewAPIClient(subscriptionID string) APIClient {
36	return NewAPIClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPIClientWithBaseURI creates an instance of the APIClient client using a custom endpoint.  Use this when
40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewAPIClientWithBaseURI(baseURI string, subscriptionID string) APIClient {
42	return APIClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate creates new or updates existing specified API of the API Management service instance.
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// parameters - create or update parameters.
52// ifMatch - eTag of the Api Entity. For Create Api Etag should not be specified. For Update Etag should match
53// the existing Entity or it can be * for unconditional update.
54func (client APIClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APICreateOrUpdateParameter, ifMatch string) (result APIContract, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.CreateOrUpdate")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	if err := validation.Validate([]validation.Validation{
66		{TargetValue: serviceName,
67			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
68				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
70		{TargetValue: apiid,
71			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
72				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
73				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
74		return result, validation.NewError("apimanagement.APIClient", "CreateOrUpdate", err.Error())
75	}
76
77	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, parameters, ifMatch)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "CreateOrUpdate", nil, "Failure preparing request")
80		return
81	}
82
83	resp, err := client.CreateOrUpdateSender(req)
84	if err != nil {
85		result.Response = autorest.Response{Response: resp}
86		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "CreateOrUpdate", resp, "Failure sending request")
87		return
88	}
89
90	result, err = client.CreateOrUpdateResponder(resp)
91	if err != nil {
92		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "CreateOrUpdate", resp, "Failure responding to request")
93	}
94
95	return
96}
97
98// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
99func (client APIClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APICreateOrUpdateParameter, ifMatch string) (*http.Request, error) {
100	pathParameters := map[string]interface{}{
101		"apiId":             autorest.Encode("path", apiid),
102		"resourceGroupName": autorest.Encode("path", resourceGroupName),
103		"serviceName":       autorest.Encode("path", serviceName),
104		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
105	}
106
107	const APIVersion = "2017-03-01"
108	queryParameters := map[string]interface{}{
109		"api-version": APIVersion,
110	}
111
112	preparer := autorest.CreatePreparer(
113		autorest.AsContentType("application/json; charset=utf-8"),
114		autorest.AsPut(),
115		autorest.WithBaseURL(client.BaseURI),
116		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
117		autorest.WithJSON(parameters),
118		autorest.WithQueryParameters(queryParameters))
119	if len(ifMatch) > 0 {
120		preparer = autorest.DecoratePreparer(preparer,
121			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
122	}
123	return preparer.Prepare((&http.Request{}).WithContext(ctx))
124}
125
126// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
127// http.Response Body if it receives an error.
128func (client APIClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
129	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
130}
131
132// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
133// closes the http.Response Body.
134func (client APIClient) CreateOrUpdateResponder(resp *http.Response) (result APIContract, err error) {
135	err = autorest.Respond(
136		resp,
137		client.ByInspecting(),
138		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
139		autorest.ByUnmarshallingJSON(&result),
140		autorest.ByClosing())
141	result.Response = autorest.Response{Response: resp}
142	return
143}
144
145// Delete deletes the specified API of the API Management service instance.
146// Parameters:
147// resourceGroupName - the name of the resource group.
148// serviceName - the name of the API Management service.
149// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
150// revision has ;rev=n as a suffix where n is the revision number.
151// ifMatch - eTag of the API Entity. ETag should match the current entity state from the header response of the
152// GET request or it should be * for unconditional update.
153func (client APIClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, ifMatch string) (result autorest.Response, err error) {
154	if tracing.IsEnabled() {
155		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Delete")
156		defer func() {
157			sc := -1
158			if result.Response != nil {
159				sc = result.Response.StatusCode
160			}
161			tracing.EndSpan(ctx, sc, err)
162		}()
163	}
164	if err := validation.Validate([]validation.Validation{
165		{TargetValue: serviceName,
166			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
167				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
168				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
169		{TargetValue: apiid,
170			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
171				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
172				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
173		return result, validation.NewError("apimanagement.APIClient", "Delete", err.Error())
174	}
175
176	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, ifMatch)
177	if err != nil {
178		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", nil, "Failure preparing request")
179		return
180	}
181
182	resp, err := client.DeleteSender(req)
183	if err != nil {
184		result.Response = resp
185		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", resp, "Failure sending request")
186		return
187	}
188
189	result, err = client.DeleteResponder(resp)
190	if err != nil {
191		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Delete", resp, "Failure responding to request")
192	}
193
194	return
195}
196
197// DeletePreparer prepares the Delete request.
198func (client APIClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, ifMatch string) (*http.Request, error) {
199	pathParameters := map[string]interface{}{
200		"apiId":             autorest.Encode("path", apiid),
201		"resourceGroupName": autorest.Encode("path", resourceGroupName),
202		"serviceName":       autorest.Encode("path", serviceName),
203		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
204	}
205
206	const APIVersion = "2017-03-01"
207	queryParameters := map[string]interface{}{
208		"api-version": APIVersion,
209	}
210
211	preparer := autorest.CreatePreparer(
212		autorest.AsDelete(),
213		autorest.WithBaseURL(client.BaseURI),
214		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
215		autorest.WithQueryParameters(queryParameters),
216		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
217	return preparer.Prepare((&http.Request{}).WithContext(ctx))
218}
219
220// DeleteSender sends the Delete request. The method will close the
221// http.Response Body if it receives an error.
222func (client APIClient) DeleteSender(req *http.Request) (*http.Response, error) {
223	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
224}
225
226// DeleteResponder handles the response to the Delete request. The method always
227// closes the http.Response Body.
228func (client APIClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
229	err = autorest.Respond(
230		resp,
231		client.ByInspecting(),
232		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
233		autorest.ByClosing())
234	result.Response = resp
235	return
236}
237
238// Get gets the details of the API specified by its identifier.
239// Parameters:
240// resourceGroupName - the name of the resource group.
241// serviceName - the name of the API Management service.
242// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
243// revision has ;rev=n as a suffix where n is the revision number.
244func (client APIClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (result APIContract, err error) {
245	if tracing.IsEnabled() {
246		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Get")
247		defer func() {
248			sc := -1
249			if result.Response.Response != nil {
250				sc = result.Response.Response.StatusCode
251			}
252			tracing.EndSpan(ctx, sc, err)
253		}()
254	}
255	if err := validation.Validate([]validation.Validation{
256		{TargetValue: serviceName,
257			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
258				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
259				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
260		{TargetValue: apiid,
261			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
262				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
263				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
264		return result, validation.NewError("apimanagement.APIClient", "Get", err.Error())
265	}
266
267	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid)
268	if err != nil {
269		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Get", nil, "Failure preparing request")
270		return
271	}
272
273	resp, err := client.GetSender(req)
274	if err != nil {
275		result.Response = autorest.Response{Response: resp}
276		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Get", resp, "Failure sending request")
277		return
278	}
279
280	result, err = client.GetResponder(resp)
281	if err != nil {
282		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Get", resp, "Failure responding to request")
283	}
284
285	return
286}
287
288// GetPreparer prepares the Get request.
289func (client APIClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (*http.Request, error) {
290	pathParameters := map[string]interface{}{
291		"apiId":             autorest.Encode("path", apiid),
292		"resourceGroupName": autorest.Encode("path", resourceGroupName),
293		"serviceName":       autorest.Encode("path", serviceName),
294		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
295	}
296
297	const APIVersion = "2017-03-01"
298	queryParameters := map[string]interface{}{
299		"api-version": APIVersion,
300	}
301
302	preparer := autorest.CreatePreparer(
303		autorest.AsGet(),
304		autorest.WithBaseURL(client.BaseURI),
305		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
306		autorest.WithQueryParameters(queryParameters))
307	return preparer.Prepare((&http.Request{}).WithContext(ctx))
308}
309
310// GetSender sends the Get request. The method will close the
311// http.Response Body if it receives an error.
312func (client APIClient) GetSender(req *http.Request) (*http.Response, error) {
313	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
314}
315
316// GetResponder handles the response to the Get request. The method always
317// closes the http.Response Body.
318func (client APIClient) GetResponder(resp *http.Response) (result APIContract, err error) {
319	err = autorest.Respond(
320		resp,
321		client.ByInspecting(),
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 gets the entity state (Etag) version of the API specified by its identifier.
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.
334func (client APIClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (result autorest.Response, err error) {
335	if tracing.IsEnabled() {
336		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.GetEntityTag")
337		defer func() {
338			sc := -1
339			if result.Response != nil {
340				sc = result.Response.StatusCode
341			}
342			tracing.EndSpan(ctx, sc, err)
343		}()
344	}
345	if err := validation.Validate([]validation.Validation{
346		{TargetValue: serviceName,
347			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
348				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
349				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
350		{TargetValue: apiid,
351			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
352				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
353				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
354		return result, validation.NewError("apimanagement.APIClient", "GetEntityTag", err.Error())
355	}
356
357	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid)
358	if err != nil {
359		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", nil, "Failure preparing request")
360		return
361	}
362
363	resp, err := client.GetEntityTagSender(req)
364	if err != nil {
365		result.Response = resp
366		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", resp, "Failure sending request")
367		return
368	}
369
370	result, err = client.GetEntityTagResponder(resp)
371	if err != nil {
372		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "GetEntityTag", resp, "Failure responding to request")
373	}
374
375	return
376}
377
378// GetEntityTagPreparer prepares the GetEntityTag request.
379func (client APIClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (*http.Request, error) {
380	pathParameters := map[string]interface{}{
381		"apiId":             autorest.Encode("path", apiid),
382		"resourceGroupName": autorest.Encode("path", resourceGroupName),
383		"serviceName":       autorest.Encode("path", serviceName),
384		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
385	}
386
387	const APIVersion = "2017-03-01"
388	queryParameters := map[string]interface{}{
389		"api-version": APIVersion,
390	}
391
392	preparer := autorest.CreatePreparer(
393		autorest.AsHead(),
394		autorest.WithBaseURL(client.BaseURI),
395		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
396		autorest.WithQueryParameters(queryParameters))
397	return preparer.Prepare((&http.Request{}).WithContext(ctx))
398}
399
400// GetEntityTagSender sends the GetEntityTag request. The method will close the
401// http.Response Body if it receives an error.
402func (client APIClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
403	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
404}
405
406// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
407// closes the http.Response Body.
408func (client APIClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
409	err = autorest.Respond(
410		resp,
411		client.ByInspecting(),
412		azure.WithErrorUnlessStatusCode(http.StatusOK),
413		autorest.ByClosing())
414	result.Response = resp
415	return
416}
417
418// ListByService lists all APIs of the API Management service instance.
419// Parameters:
420// resourceGroupName - the name of the resource group.
421// serviceName - the name of the API Management service.
422// filter - | Field       | Supported operators    | Supported functions               |
423// |-------------|------------------------|-----------------------------------|
424// | id          | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
425// | name        | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
426// | description | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
427// | serviceUrl  | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
428// | path        | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
429// top - number of records to return.
430// skip - number of records to skip.
431// expandAPIVersionSet - include full ApiVersionSet resource in response
432func (client APIClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandAPIVersionSet *bool) (result APICollectionPage, err error) {
433	if tracing.IsEnabled() {
434		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByService")
435		defer func() {
436			sc := -1
437			if result.ac.Response.Response != nil {
438				sc = result.ac.Response.Response.StatusCode
439			}
440			tracing.EndSpan(ctx, sc, err)
441		}()
442	}
443	if err := validation.Validate([]validation.Validation{
444		{TargetValue: serviceName,
445			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
446				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
447				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
448		{TargetValue: top,
449			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
450				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
451		{TargetValue: skip,
452			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
453				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
454		return result, validation.NewError("apimanagement.APIClient", "ListByService", err.Error())
455	}
456
457	result.fn = client.listByServiceNextResults
458	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip, expandAPIVersionSet)
459	if err != nil {
460		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", nil, "Failure preparing request")
461		return
462	}
463
464	resp, err := client.ListByServiceSender(req)
465	if err != nil {
466		result.ac.Response = autorest.Response{Response: resp}
467		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", resp, "Failure sending request")
468		return
469	}
470
471	result.ac, err = client.ListByServiceResponder(resp)
472	if err != nil {
473		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByService", resp, "Failure responding to request")
474	}
475
476	return
477}
478
479// ListByServicePreparer prepares the ListByService request.
480func (client APIClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandAPIVersionSet *bool) (*http.Request, error) {
481	pathParameters := map[string]interface{}{
482		"resourceGroupName": autorest.Encode("path", resourceGroupName),
483		"serviceName":       autorest.Encode("path", serviceName),
484		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
485	}
486
487	const APIVersion = "2017-03-01"
488	queryParameters := map[string]interface{}{
489		"api-version": APIVersion,
490	}
491	if len(filter) > 0 {
492		queryParameters["$filter"] = autorest.Encode("query", filter)
493	}
494	if top != nil {
495		queryParameters["$top"] = autorest.Encode("query", *top)
496	}
497	if skip != nil {
498		queryParameters["$skip"] = autorest.Encode("query", *skip)
499	}
500	if expandAPIVersionSet != nil {
501		queryParameters["expandApiVersionSet"] = autorest.Encode("query", *expandAPIVersionSet)
502	} else {
503		queryParameters["expandApiVersionSet"] = autorest.Encode("query", false)
504	}
505
506	preparer := autorest.CreatePreparer(
507		autorest.AsGet(),
508		autorest.WithBaseURL(client.BaseURI),
509		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis", pathParameters),
510		autorest.WithQueryParameters(queryParameters))
511	return preparer.Prepare((&http.Request{}).WithContext(ctx))
512}
513
514// ListByServiceSender sends the ListByService request. The method will close the
515// http.Response Body if it receives an error.
516func (client APIClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
517	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
518}
519
520// ListByServiceResponder handles the response to the ListByService request. The method always
521// closes the http.Response Body.
522func (client APIClient) ListByServiceResponder(resp *http.Response) (result APICollection, err error) {
523	err = autorest.Respond(
524		resp,
525		client.ByInspecting(),
526		azure.WithErrorUnlessStatusCode(http.StatusOK),
527		autorest.ByUnmarshallingJSON(&result),
528		autorest.ByClosing())
529	result.Response = autorest.Response{Response: resp}
530	return
531}
532
533// listByServiceNextResults retrieves the next set of results, if any.
534func (client APIClient) listByServiceNextResults(ctx context.Context, lastResults APICollection) (result APICollection, err error) {
535	req, err := lastResults.aPICollectionPreparer(ctx)
536	if err != nil {
537		return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", nil, "Failure preparing next results request")
538	}
539	if req == nil {
540		return
541	}
542	resp, err := client.ListByServiceSender(req)
543	if err != nil {
544		result.Response = autorest.Response{Response: resp}
545		return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", resp, "Failure sending next results request")
546	}
547	result, err = client.ListByServiceResponder(resp)
548	if err != nil {
549		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByServiceNextResults", resp, "Failure responding to next results request")
550	}
551	return
552}
553
554// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
555func (client APIClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32, expandAPIVersionSet *bool) (result APICollectionIterator, err error) {
556	if tracing.IsEnabled() {
557		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByService")
558		defer func() {
559			sc := -1
560			if result.Response().Response.Response != nil {
561				sc = result.page.Response().Response.Response.StatusCode
562			}
563			tracing.EndSpan(ctx, sc, err)
564		}()
565	}
566	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip, expandAPIVersionSet)
567	return
568}
569
570// ListByTags lists a collection of apis associated with tags.
571// Parameters:
572// resourceGroupName - the name of the resource group.
573// serviceName - the name of the API Management service.
574// filter - | Field       | Supported operators    | Supported functions                         |
575// |-------------|------------------------|---------------------------------------------|
576// | id          | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
577// | name        | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
578// | aid         | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
579// | apiRevision | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
580// | path        | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
581// | description | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
582// | serviceUrl  | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
583// | isCurrent   | eq                     | substringof, contains, startswith, endswith |
584// top - number of records to return.
585// skip - number of records to skip.
586func (client APIClient) ListByTags(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result TagResourceCollectionPage, err error) {
587	if tracing.IsEnabled() {
588		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByTags")
589		defer func() {
590			sc := -1
591			if result.trc.Response.Response != nil {
592				sc = result.trc.Response.Response.StatusCode
593			}
594			tracing.EndSpan(ctx, sc, err)
595		}()
596	}
597	if err := validation.Validate([]validation.Validation{
598		{TargetValue: serviceName,
599			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
600				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
601				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
602		{TargetValue: top,
603			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
604				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
605		{TargetValue: skip,
606			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
607				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
608		return result, validation.NewError("apimanagement.APIClient", "ListByTags", err.Error())
609	}
610
611	result.fn = client.listByTagsNextResults
612	req, err := client.ListByTagsPreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
613	if err != nil {
614		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", nil, "Failure preparing request")
615		return
616	}
617
618	resp, err := client.ListByTagsSender(req)
619	if err != nil {
620		result.trc.Response = autorest.Response{Response: resp}
621		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", resp, "Failure sending request")
622		return
623	}
624
625	result.trc, err = client.ListByTagsResponder(resp)
626	if err != nil {
627		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "ListByTags", resp, "Failure responding to request")
628	}
629
630	return
631}
632
633// ListByTagsPreparer prepares the ListByTags request.
634func (client APIClient) ListByTagsPreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
635	pathParameters := map[string]interface{}{
636		"resourceGroupName": autorest.Encode("path", resourceGroupName),
637		"serviceName":       autorest.Encode("path", serviceName),
638		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
639	}
640
641	const APIVersion = "2017-03-01"
642	queryParameters := map[string]interface{}{
643		"api-version": APIVersion,
644	}
645	if len(filter) > 0 {
646		queryParameters["$filter"] = autorest.Encode("query", filter)
647	}
648	if top != nil {
649		queryParameters["$top"] = autorest.Encode("query", *top)
650	}
651	if skip != nil {
652		queryParameters["$skip"] = autorest.Encode("query", *skip)
653	}
654
655	preparer := autorest.CreatePreparer(
656		autorest.AsGet(),
657		autorest.WithBaseURL(client.BaseURI),
658		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apisByTags", pathParameters),
659		autorest.WithQueryParameters(queryParameters))
660	return preparer.Prepare((&http.Request{}).WithContext(ctx))
661}
662
663// ListByTagsSender sends the ListByTags request. The method will close the
664// http.Response Body if it receives an error.
665func (client APIClient) ListByTagsSender(req *http.Request) (*http.Response, error) {
666	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
667}
668
669// ListByTagsResponder handles the response to the ListByTags request. The method always
670// closes the http.Response Body.
671func (client APIClient) ListByTagsResponder(resp *http.Response) (result TagResourceCollection, err error) {
672	err = autorest.Respond(
673		resp,
674		client.ByInspecting(),
675		azure.WithErrorUnlessStatusCode(http.StatusOK),
676		autorest.ByUnmarshallingJSON(&result),
677		autorest.ByClosing())
678	result.Response = autorest.Response{Response: resp}
679	return
680}
681
682// listByTagsNextResults retrieves the next set of results, if any.
683func (client APIClient) listByTagsNextResults(ctx context.Context, lastResults TagResourceCollection) (result TagResourceCollection, err error) {
684	req, err := lastResults.tagResourceCollectionPreparer(ctx)
685	if err != nil {
686		return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", nil, "Failure preparing next results request")
687	}
688	if req == nil {
689		return
690	}
691	resp, err := client.ListByTagsSender(req)
692	if err != nil {
693		result.Response = autorest.Response{Response: resp}
694		return result, autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", resp, "Failure sending next results request")
695	}
696	result, err = client.ListByTagsResponder(resp)
697	if err != nil {
698		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "listByTagsNextResults", resp, "Failure responding to next results request")
699	}
700	return
701}
702
703// ListByTagsComplete enumerates all values, automatically crossing page boundaries as required.
704func (client APIClient) ListByTagsComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result TagResourceCollectionIterator, err error) {
705	if tracing.IsEnabled() {
706		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.ListByTags")
707		defer func() {
708			sc := -1
709			if result.Response().Response.Response != nil {
710				sc = result.page.Response().Response.Response.StatusCode
711			}
712			tracing.EndSpan(ctx, sc, err)
713		}()
714	}
715	result.page, err = client.ListByTags(ctx, resourceGroupName, serviceName, filter, top, skip)
716	return
717}
718
719// Update updates the specified API of the API Management service instance.
720// Parameters:
721// resourceGroupName - the name of the resource group.
722// serviceName - the name of the API Management service.
723// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
724// revision has ;rev=n as a suffix where n is the revision number.
725// parameters - API Update Contract parameters.
726// ifMatch - eTag of the API entity. ETag should match the current entity state in the header response of the
727// GET request or it should be * for unconditional update.
728func (client APIClient) Update(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APIUpdateContract, ifMatch string) (result autorest.Response, err error) {
729	if tracing.IsEnabled() {
730		ctx = tracing.StartSpan(ctx, fqdn+"/APIClient.Update")
731		defer func() {
732			sc := -1
733			if result.Response != nil {
734				sc = result.Response.StatusCode
735			}
736			tracing.EndSpan(ctx, sc, err)
737		}()
738	}
739	if err := validation.Validate([]validation.Validation{
740		{TargetValue: serviceName,
741			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
742				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
743				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
744		{TargetValue: apiid,
745			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
746				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
747				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
748		return result, validation.NewError("apimanagement.APIClient", "Update", err.Error())
749	}
750
751	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, apiid, parameters, ifMatch)
752	if err != nil {
753		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", nil, "Failure preparing request")
754		return
755	}
756
757	resp, err := client.UpdateSender(req)
758	if err != nil {
759		result.Response = resp
760		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", resp, "Failure sending request")
761		return
762	}
763
764	result, err = client.UpdateResponder(resp)
765	if err != nil {
766		err = autorest.NewErrorWithError(err, "apimanagement.APIClient", "Update", resp, "Failure responding to request")
767	}
768
769	return
770}
771
772// UpdatePreparer prepares the Update request.
773func (client APIClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, parameters APIUpdateContract, ifMatch string) (*http.Request, error) {
774	pathParameters := map[string]interface{}{
775		"apiId":             autorest.Encode("path", apiid),
776		"resourceGroupName": autorest.Encode("path", resourceGroupName),
777		"serviceName":       autorest.Encode("path", serviceName),
778		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
779	}
780
781	const APIVersion = "2017-03-01"
782	queryParameters := map[string]interface{}{
783		"api-version": APIVersion,
784	}
785
786	preparer := autorest.CreatePreparer(
787		autorest.AsContentType("application/json; charset=utf-8"),
788		autorest.AsPatch(),
789		autorest.WithBaseURL(client.BaseURI),
790		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters),
791		autorest.WithJSON(parameters),
792		autorest.WithQueryParameters(queryParameters),
793		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
794	return preparer.Prepare((&http.Request{}).WithContext(ctx))
795}
796
797// UpdateSender sends the Update request. The method will close the
798// http.Response Body if it receives an error.
799func (client APIClient) UpdateSender(req *http.Request) (*http.Response, error) {
800	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
801}
802
803// UpdateResponder handles the response to the Update request. The method always
804// closes the http.Response Body.
805func (client APIClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
806	err = autorest.Respond(
807		resp,
808		client.ByInspecting(),
809		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
810		autorest.ByClosing())
811	result.Response = resp
812	return
813}
814