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// APITagDescriptionClient is the apiManagement Client
30type APITagDescriptionClient struct {
31	BaseClient
32}
33
34// NewAPITagDescriptionClient creates an instance of the APITagDescriptionClient client.
35func NewAPITagDescriptionClient(subscriptionID string) APITagDescriptionClient {
36	return NewAPITagDescriptionClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPITagDescriptionClientWithBaseURI creates an instance of the APITagDescriptionClient client using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewAPITagDescriptionClientWithBaseURI(baseURI string, subscriptionID string) APITagDescriptionClient {
43	return APITagDescriptionClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate create/Update tag description in scope of the Api.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// serviceName - the name of the API Management service.
50// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
51// revision has ;rev=n as a suffix where n is the revision number.
52// tagDescriptionID - tag description identifier. Used when creating tagDescription for API/Tag association.
53// Based on API and Tag names.
54// parameters - create parameters.
55// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
56func (client APITagDescriptionClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, parameters TagDescriptionCreateParameters, ifMatch string) (result TagDescriptionContract, err error) {
57	if tracing.IsEnabled() {
58		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.CreateOrUpdate")
59		defer func() {
60			sc := -1
61			if result.Response.Response != nil {
62				sc = result.Response.Response.StatusCode
63			}
64			tracing.EndSpan(ctx, sc, err)
65		}()
66	}
67	if err := validation.Validate([]validation.Validation{
68		{TargetValue: serviceName,
69			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
70				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
71				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
72		{TargetValue: apiid,
73			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
74				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
75				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
76		{TargetValue: tagDescriptionID,
77			Constraints: []validation.Constraint{{Target: "tagDescriptionID", Name: validation.MaxLength, Rule: 80, Chain: nil},
78				{Target: "tagDescriptionID", Name: validation.MinLength, Rule: 1, Chain: nil},
79				{Target: "tagDescriptionID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
80		{TargetValue: parameters,
81			Constraints: []validation.Constraint{{Target: "parameters.TagDescriptionBaseProperties", Name: validation.Null, Rule: false,
82				Chain: []validation.Constraint{{Target: "parameters.TagDescriptionBaseProperties.ExternalDocsURL", Name: validation.Null, Rule: false,
83					Chain: []validation.Constraint{{Target: "parameters.TagDescriptionBaseProperties.ExternalDocsURL", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
84				}}}}}); err != nil {
85		return result, validation.NewError("apimanagement.APITagDescriptionClient", "CreateOrUpdate", err.Error())
86	}
87
88	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, tagDescriptionID, parameters, ifMatch)
89	if err != nil {
90		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "CreateOrUpdate", nil, "Failure preparing request")
91		return
92	}
93
94	resp, err := client.CreateOrUpdateSender(req)
95	if err != nil {
96		result.Response = autorest.Response{Response: resp}
97		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "CreateOrUpdate", resp, "Failure sending request")
98		return
99	}
100
101	result, err = client.CreateOrUpdateResponder(resp)
102	if err != nil {
103		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "CreateOrUpdate", resp, "Failure responding to request")
104	}
105
106	return
107}
108
109// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
110func (client APITagDescriptionClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, parameters TagDescriptionCreateParameters, ifMatch string) (*http.Request, error) {
111	pathParameters := map[string]interface{}{
112		"apiId":             autorest.Encode("path", apiid),
113		"resourceGroupName": autorest.Encode("path", resourceGroupName),
114		"serviceName":       autorest.Encode("path", serviceName),
115		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
116		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
117	}
118
119	const APIVersion = "2019-12-01"
120	queryParameters := map[string]interface{}{
121		"api-version": APIVersion,
122	}
123
124	preparer := autorest.CreatePreparer(
125		autorest.AsContentType("application/json; charset=utf-8"),
126		autorest.AsPut(),
127		autorest.WithBaseURL(client.BaseURI),
128		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
129		autorest.WithJSON(parameters),
130		autorest.WithQueryParameters(queryParameters))
131	if len(ifMatch) > 0 {
132		preparer = autorest.DecoratePreparer(preparer,
133			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
134	}
135	return preparer.Prepare((&http.Request{}).WithContext(ctx))
136}
137
138// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
139// http.Response Body if it receives an error.
140func (client APITagDescriptionClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
141	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
142}
143
144// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
145// closes the http.Response Body.
146func (client APITagDescriptionClient) CreateOrUpdateResponder(resp *http.Response) (result TagDescriptionContract, err error) {
147	err = autorest.Respond(
148		resp,
149		client.ByInspecting(),
150		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
151		autorest.ByUnmarshallingJSON(&result),
152		autorest.ByClosing())
153	result.Response = autorest.Response{Response: resp}
154	return
155}
156
157// Delete delete tag description for the Api.
158// Parameters:
159// resourceGroupName - the name of the resource group.
160// serviceName - the name of the API Management service.
161// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
162// revision has ;rev=n as a suffix where n is the revision number.
163// tagDescriptionID - tag description identifier. Used when creating tagDescription for API/Tag association.
164// Based on API and Tag names.
165// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
166// request or it should be * for unconditional update.
167func (client APITagDescriptionClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, ifMatch string) (result autorest.Response, err error) {
168	if tracing.IsEnabled() {
169		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.Delete")
170		defer func() {
171			sc := -1
172			if result.Response != nil {
173				sc = result.Response.StatusCode
174			}
175			tracing.EndSpan(ctx, sc, err)
176		}()
177	}
178	if err := validation.Validate([]validation.Validation{
179		{TargetValue: serviceName,
180			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
181				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
182				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
183		{TargetValue: apiid,
184			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
185				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
186				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
187		{TargetValue: tagDescriptionID,
188			Constraints: []validation.Constraint{{Target: "tagDescriptionID", Name: validation.MaxLength, Rule: 80, Chain: nil},
189				{Target: "tagDescriptionID", Name: validation.MinLength, Rule: 1, Chain: nil},
190				{Target: "tagDescriptionID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
191		return result, validation.NewError("apimanagement.APITagDescriptionClient", "Delete", err.Error())
192	}
193
194	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, tagDescriptionID, ifMatch)
195	if err != nil {
196		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Delete", nil, "Failure preparing request")
197		return
198	}
199
200	resp, err := client.DeleteSender(req)
201	if err != nil {
202		result.Response = resp
203		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Delete", resp, "Failure sending request")
204		return
205	}
206
207	result, err = client.DeleteResponder(resp)
208	if err != nil {
209		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Delete", resp, "Failure responding to request")
210	}
211
212	return
213}
214
215// DeletePreparer prepares the Delete request.
216func (client APITagDescriptionClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, ifMatch string) (*http.Request, error) {
217	pathParameters := map[string]interface{}{
218		"apiId":             autorest.Encode("path", apiid),
219		"resourceGroupName": autorest.Encode("path", resourceGroupName),
220		"serviceName":       autorest.Encode("path", serviceName),
221		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
222		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
223	}
224
225	const APIVersion = "2019-12-01"
226	queryParameters := map[string]interface{}{
227		"api-version": APIVersion,
228	}
229
230	preparer := autorest.CreatePreparer(
231		autorest.AsDelete(),
232		autorest.WithBaseURL(client.BaseURI),
233		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
234		autorest.WithQueryParameters(queryParameters),
235		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
236	return preparer.Prepare((&http.Request{}).WithContext(ctx))
237}
238
239// DeleteSender sends the Delete request. The method will close the
240// http.Response Body if it receives an error.
241func (client APITagDescriptionClient) DeleteSender(req *http.Request) (*http.Response, error) {
242	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
243}
244
245// DeleteResponder handles the response to the Delete request. The method always
246// closes the http.Response Body.
247func (client APITagDescriptionClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
248	err = autorest.Respond(
249		resp,
250		client.ByInspecting(),
251		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
252		autorest.ByClosing())
253	result.Response = resp
254	return
255}
256
257// Get get Tag description in scope of API
258// Parameters:
259// resourceGroupName - the name of the resource group.
260// serviceName - the name of the API Management service.
261// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
262// revision has ;rev=n as a suffix where n is the revision number.
263// tagDescriptionID - tag description identifier. Used when creating tagDescription for API/Tag association.
264// Based on API and Tag names.
265func (client APITagDescriptionClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (result TagDescriptionContract, err error) {
266	if tracing.IsEnabled() {
267		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.Get")
268		defer func() {
269			sc := -1
270			if result.Response.Response != nil {
271				sc = result.Response.Response.StatusCode
272			}
273			tracing.EndSpan(ctx, sc, err)
274		}()
275	}
276	if err := validation.Validate([]validation.Validation{
277		{TargetValue: serviceName,
278			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
279				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
280				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
281		{TargetValue: apiid,
282			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
283				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
284				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
285		{TargetValue: tagDescriptionID,
286			Constraints: []validation.Constraint{{Target: "tagDescriptionID", Name: validation.MaxLength, Rule: 80, Chain: nil},
287				{Target: "tagDescriptionID", Name: validation.MinLength, Rule: 1, Chain: nil},
288				{Target: "tagDescriptionID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
289		return result, validation.NewError("apimanagement.APITagDescriptionClient", "Get", err.Error())
290	}
291
292	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, tagDescriptionID)
293	if err != nil {
294		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Get", nil, "Failure preparing request")
295		return
296	}
297
298	resp, err := client.GetSender(req)
299	if err != nil {
300		result.Response = autorest.Response{Response: resp}
301		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Get", resp, "Failure sending request")
302		return
303	}
304
305	result, err = client.GetResponder(resp)
306	if err != nil {
307		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "Get", resp, "Failure responding to request")
308	}
309
310	return
311}
312
313// GetPreparer prepares the Get request.
314func (client APITagDescriptionClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (*http.Request, error) {
315	pathParameters := map[string]interface{}{
316		"apiId":             autorest.Encode("path", apiid),
317		"resourceGroupName": autorest.Encode("path", resourceGroupName),
318		"serviceName":       autorest.Encode("path", serviceName),
319		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
320		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
321	}
322
323	const APIVersion = "2019-12-01"
324	queryParameters := map[string]interface{}{
325		"api-version": APIVersion,
326	}
327
328	preparer := autorest.CreatePreparer(
329		autorest.AsGet(),
330		autorest.WithBaseURL(client.BaseURI),
331		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
332		autorest.WithQueryParameters(queryParameters))
333	return preparer.Prepare((&http.Request{}).WithContext(ctx))
334}
335
336// GetSender sends the Get request. The method will close the
337// http.Response Body if it receives an error.
338func (client APITagDescriptionClient) GetSender(req *http.Request) (*http.Response, error) {
339	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
340}
341
342// GetResponder handles the response to the Get request. The method always
343// closes the http.Response Body.
344func (client APITagDescriptionClient) GetResponder(resp *http.Response) (result TagDescriptionContract, err error) {
345	err = autorest.Respond(
346		resp,
347		client.ByInspecting(),
348		azure.WithErrorUnlessStatusCode(http.StatusOK),
349		autorest.ByUnmarshallingJSON(&result),
350		autorest.ByClosing())
351	result.Response = autorest.Response{Response: resp}
352	return
353}
354
355// GetEntityTag gets the entity state version of the tag specified by its identifier.
356// Parameters:
357// resourceGroupName - the name of the resource group.
358// serviceName - the name of the API Management service.
359// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
360// revision has ;rev=n as a suffix where n is the revision number.
361// tagDescriptionID - tag description identifier. Used when creating tagDescription for API/Tag association.
362// Based on API and Tag names.
363func (client APITagDescriptionClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (result autorest.Response, err error) {
364	if tracing.IsEnabled() {
365		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.GetEntityTag")
366		defer func() {
367			sc := -1
368			if result.Response != nil {
369				sc = result.Response.StatusCode
370			}
371			tracing.EndSpan(ctx, sc, err)
372		}()
373	}
374	if err := validation.Validate([]validation.Validation{
375		{TargetValue: serviceName,
376			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
377				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
378				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
379		{TargetValue: apiid,
380			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
381				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
382				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
383		{TargetValue: tagDescriptionID,
384			Constraints: []validation.Constraint{{Target: "tagDescriptionID", Name: validation.MaxLength, Rule: 80, Chain: nil},
385				{Target: "tagDescriptionID", Name: validation.MinLength, Rule: 1, Chain: nil},
386				{Target: "tagDescriptionID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
387		return result, validation.NewError("apimanagement.APITagDescriptionClient", "GetEntityTag", err.Error())
388	}
389
390	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, tagDescriptionID)
391	if err != nil {
392		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "GetEntityTag", nil, "Failure preparing request")
393		return
394	}
395
396	resp, err := client.GetEntityTagSender(req)
397	if err != nil {
398		result.Response = resp
399		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "GetEntityTag", resp, "Failure sending request")
400		return
401	}
402
403	result, err = client.GetEntityTagResponder(resp)
404	if err != nil {
405		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "GetEntityTag", resp, "Failure responding to request")
406	}
407
408	return
409}
410
411// GetEntityTagPreparer prepares the GetEntityTag request.
412func (client APITagDescriptionClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (*http.Request, error) {
413	pathParameters := map[string]interface{}{
414		"apiId":             autorest.Encode("path", apiid),
415		"resourceGroupName": autorest.Encode("path", resourceGroupName),
416		"serviceName":       autorest.Encode("path", serviceName),
417		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
418		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
419	}
420
421	const APIVersion = "2019-12-01"
422	queryParameters := map[string]interface{}{
423		"api-version": APIVersion,
424	}
425
426	preparer := autorest.CreatePreparer(
427		autorest.AsHead(),
428		autorest.WithBaseURL(client.BaseURI),
429		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
430		autorest.WithQueryParameters(queryParameters))
431	return preparer.Prepare((&http.Request{}).WithContext(ctx))
432}
433
434// GetEntityTagSender sends the GetEntityTag request. The method will close the
435// http.Response Body if it receives an error.
436func (client APITagDescriptionClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
437	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
438}
439
440// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
441// closes the http.Response Body.
442func (client APITagDescriptionClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
443	err = autorest.Respond(
444		resp,
445		client.ByInspecting(),
446		azure.WithErrorUnlessStatusCode(http.StatusOK),
447		autorest.ByClosing())
448	result.Response = resp
449	return
450}
451
452// ListByService lists all Tags descriptions in scope of API. Model similar to swagger - tagDescription is defined on
453// API level but tag may be assigned to the Operations
454// Parameters:
455// resourceGroupName - the name of the resource group.
456// serviceName - the name of the API Management service.
457// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
458// revision has ;rev=n as a suffix where n is the revision number.
459// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
460// |</br>|-------------|-------------|-------------|-------------|</br>| displayName | filter | ge, le, eq, ne,
461// gt, lt | substringof, contains, startswith, endswith | </br>| name | filter | ge, le, eq, ne, gt, lt |
462// substringof, contains, startswith, endswith | </br>
463// top - number of records to return.
464// skip - number of records to skip.
465func (client APITagDescriptionClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result TagDescriptionCollectionPage, err error) {
466	if tracing.IsEnabled() {
467		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.ListByService")
468		defer func() {
469			sc := -1
470			if result.tdc.Response.Response != nil {
471				sc = result.tdc.Response.Response.StatusCode
472			}
473			tracing.EndSpan(ctx, sc, err)
474		}()
475	}
476	if err := validation.Validate([]validation.Validation{
477		{TargetValue: serviceName,
478			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
479				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
480				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
481		{TargetValue: apiid,
482			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
483				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
484				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
485		{TargetValue: top,
486			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
487				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
488		{TargetValue: skip,
489			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
490				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
491		return result, validation.NewError("apimanagement.APITagDescriptionClient", "ListByService", err.Error())
492	}
493
494	result.fn = client.listByServiceNextResults
495	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
496	if err != nil {
497		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "ListByService", nil, "Failure preparing request")
498		return
499	}
500
501	resp, err := client.ListByServiceSender(req)
502	if err != nil {
503		result.tdc.Response = autorest.Response{Response: resp}
504		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "ListByService", resp, "Failure sending request")
505		return
506	}
507
508	result.tdc, err = client.ListByServiceResponder(resp)
509	if err != nil {
510		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "ListByService", resp, "Failure responding to request")
511	}
512
513	return
514}
515
516// ListByServicePreparer prepares the ListByService request.
517func (client APITagDescriptionClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) {
518	pathParameters := map[string]interface{}{
519		"apiId":             autorest.Encode("path", apiid),
520		"resourceGroupName": autorest.Encode("path", resourceGroupName),
521		"serviceName":       autorest.Encode("path", serviceName),
522		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
523	}
524
525	const APIVersion = "2019-12-01"
526	queryParameters := map[string]interface{}{
527		"api-version": APIVersion,
528	}
529	if len(filter) > 0 {
530		queryParameters["$filter"] = autorest.Encode("query", filter)
531	}
532	if top != nil {
533		queryParameters["$top"] = autorest.Encode("query", *top)
534	}
535	if skip != nil {
536		queryParameters["$skip"] = autorest.Encode("query", *skip)
537	}
538
539	preparer := autorest.CreatePreparer(
540		autorest.AsGet(),
541		autorest.WithBaseURL(client.BaseURI),
542		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions", pathParameters),
543		autorest.WithQueryParameters(queryParameters))
544	return preparer.Prepare((&http.Request{}).WithContext(ctx))
545}
546
547// ListByServiceSender sends the ListByService request. The method will close the
548// http.Response Body if it receives an error.
549func (client APITagDescriptionClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
550	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
551}
552
553// ListByServiceResponder handles the response to the ListByService request. The method always
554// closes the http.Response Body.
555func (client APITagDescriptionClient) ListByServiceResponder(resp *http.Response) (result TagDescriptionCollection, err error) {
556	err = autorest.Respond(
557		resp,
558		client.ByInspecting(),
559		azure.WithErrorUnlessStatusCode(http.StatusOK),
560		autorest.ByUnmarshallingJSON(&result),
561		autorest.ByClosing())
562	result.Response = autorest.Response{Response: resp}
563	return
564}
565
566// listByServiceNextResults retrieves the next set of results, if any.
567func (client APITagDescriptionClient) listByServiceNextResults(ctx context.Context, lastResults TagDescriptionCollection) (result TagDescriptionCollection, err error) {
568	req, err := lastResults.tagDescriptionCollectionPreparer(ctx)
569	if err != nil {
570		return result, autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", nil, "Failure preparing next results request")
571	}
572	if req == nil {
573		return
574	}
575	resp, err := client.ListByServiceSender(req)
576	if err != nil {
577		result.Response = autorest.Response{Response: resp}
578		return result, autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", resp, "Failure sending next results request")
579	}
580	result, err = client.ListByServiceResponder(resp)
581	if err != nil {
582		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", resp, "Failure responding to next results request")
583	}
584	return
585}
586
587// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
588func (client APITagDescriptionClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result TagDescriptionCollectionIterator, err error) {
589	if tracing.IsEnabled() {
590		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.ListByService")
591		defer func() {
592			sc := -1
593			if result.Response().Response.Response != nil {
594				sc = result.page.Response().Response.Response.StatusCode
595			}
596			tracing.EndSpan(ctx, sc, err)
597		}()
598	}
599	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
600	return
601}
602