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		return
105	}
106
107	return
108}
109
110// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
111func (client APITagDescriptionClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, parameters TagDescriptionCreateParameters, ifMatch string) (*http.Request, error) {
112	pathParameters := map[string]interface{}{
113		"apiId":             autorest.Encode("path", apiid),
114		"resourceGroupName": autorest.Encode("path", resourceGroupName),
115		"serviceName":       autorest.Encode("path", serviceName),
116		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
117		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
118	}
119
120	const APIVersion = "2020-12-01"
121	queryParameters := map[string]interface{}{
122		"api-version": APIVersion,
123	}
124
125	preparer := autorest.CreatePreparer(
126		autorest.AsContentType("application/json; charset=utf-8"),
127		autorest.AsPut(),
128		autorest.WithBaseURL(client.BaseURI),
129		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
130		autorest.WithJSON(parameters),
131		autorest.WithQueryParameters(queryParameters))
132	if len(ifMatch) > 0 {
133		preparer = autorest.DecoratePreparer(preparer,
134			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
135	}
136	return preparer.Prepare((&http.Request{}).WithContext(ctx))
137}
138
139// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
140// http.Response Body if it receives an error.
141func (client APITagDescriptionClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
142	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
143}
144
145// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
146// closes the http.Response Body.
147func (client APITagDescriptionClient) CreateOrUpdateResponder(resp *http.Response) (result TagDescriptionContract, err error) {
148	err = autorest.Respond(
149		resp,
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		return
211	}
212
213	return
214}
215
216// DeletePreparer prepares the Delete request.
217func (client APITagDescriptionClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string, ifMatch string) (*http.Request, error) {
218	pathParameters := map[string]interface{}{
219		"apiId":             autorest.Encode("path", apiid),
220		"resourceGroupName": autorest.Encode("path", resourceGroupName),
221		"serviceName":       autorest.Encode("path", serviceName),
222		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
223		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
224	}
225
226	const APIVersion = "2020-12-01"
227	queryParameters := map[string]interface{}{
228		"api-version": APIVersion,
229	}
230
231	preparer := autorest.CreatePreparer(
232		autorest.AsDelete(),
233		autorest.WithBaseURL(client.BaseURI),
234		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
235		autorest.WithQueryParameters(queryParameters),
236		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
237	return preparer.Prepare((&http.Request{}).WithContext(ctx))
238}
239
240// DeleteSender sends the Delete request. The method will close the
241// http.Response Body if it receives an error.
242func (client APITagDescriptionClient) DeleteSender(req *http.Request) (*http.Response, error) {
243	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
244}
245
246// DeleteResponder handles the response to the Delete request. The method always
247// closes the http.Response Body.
248func (client APITagDescriptionClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
249	err = autorest.Respond(
250		resp,
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		return
309	}
310
311	return
312}
313
314// GetPreparer prepares the Get request.
315func (client APITagDescriptionClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (*http.Request, error) {
316	pathParameters := map[string]interface{}{
317		"apiId":             autorest.Encode("path", apiid),
318		"resourceGroupName": autorest.Encode("path", resourceGroupName),
319		"serviceName":       autorest.Encode("path", serviceName),
320		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
321		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
322	}
323
324	const APIVersion = "2020-12-01"
325	queryParameters := map[string]interface{}{
326		"api-version": APIVersion,
327	}
328
329	preparer := autorest.CreatePreparer(
330		autorest.AsGet(),
331		autorest.WithBaseURL(client.BaseURI),
332		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
333		autorest.WithQueryParameters(queryParameters))
334	return preparer.Prepare((&http.Request{}).WithContext(ctx))
335}
336
337// GetSender sends the Get request. The method will close the
338// http.Response Body if it receives an error.
339func (client APITagDescriptionClient) GetSender(req *http.Request) (*http.Response, error) {
340	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
341}
342
343// GetResponder handles the response to the Get request. The method always
344// closes the http.Response Body.
345func (client APITagDescriptionClient) GetResponder(resp *http.Response) (result TagDescriptionContract, err error) {
346	err = autorest.Respond(
347		resp,
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		return
407	}
408
409	return
410}
411
412// GetEntityTagPreparer prepares the GetEntityTag request.
413func (client APITagDescriptionClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, tagDescriptionID string) (*http.Request, error) {
414	pathParameters := map[string]interface{}{
415		"apiId":             autorest.Encode("path", apiid),
416		"resourceGroupName": autorest.Encode("path", resourceGroupName),
417		"serviceName":       autorest.Encode("path", serviceName),
418		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
419		"tagDescriptionId":  autorest.Encode("path", tagDescriptionID),
420	}
421
422	const APIVersion = "2020-12-01"
423	queryParameters := map[string]interface{}{
424		"api-version": APIVersion,
425	}
426
427	preparer := autorest.CreatePreparer(
428		autorest.AsHead(),
429		autorest.WithBaseURL(client.BaseURI),
430		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions/{tagDescriptionId}", pathParameters),
431		autorest.WithQueryParameters(queryParameters))
432	return preparer.Prepare((&http.Request{}).WithContext(ctx))
433}
434
435// GetEntityTagSender sends the GetEntityTag request. The method will close the
436// http.Response Body if it receives an error.
437func (client APITagDescriptionClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
438	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
439}
440
441// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
442// closes the http.Response Body.
443func (client APITagDescriptionClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
444	err = autorest.Respond(
445		resp,
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		return
512	}
513	if result.tdc.hasNextLink() && result.tdc.IsEmpty() {
514		err = result.NextWithContext(ctx)
515		return
516	}
517
518	return
519}
520
521// ListByServicePreparer prepares the ListByService request.
522func (client APITagDescriptionClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) {
523	pathParameters := map[string]interface{}{
524		"apiId":             autorest.Encode("path", apiid),
525		"resourceGroupName": autorest.Encode("path", resourceGroupName),
526		"serviceName":       autorest.Encode("path", serviceName),
527		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
528	}
529
530	const APIVersion = "2020-12-01"
531	queryParameters := map[string]interface{}{
532		"api-version": APIVersion,
533	}
534	if len(filter) > 0 {
535		queryParameters["$filter"] = autorest.Encode("query", filter)
536	}
537	if top != nil {
538		queryParameters["$top"] = autorest.Encode("query", *top)
539	}
540	if skip != nil {
541		queryParameters["$skip"] = autorest.Encode("query", *skip)
542	}
543
544	preparer := autorest.CreatePreparer(
545		autorest.AsGet(),
546		autorest.WithBaseURL(client.BaseURI),
547		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/tagDescriptions", pathParameters),
548		autorest.WithQueryParameters(queryParameters))
549	return preparer.Prepare((&http.Request{}).WithContext(ctx))
550}
551
552// ListByServiceSender sends the ListByService request. The method will close the
553// http.Response Body if it receives an error.
554func (client APITagDescriptionClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
555	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
556}
557
558// ListByServiceResponder handles the response to the ListByService request. The method always
559// closes the http.Response Body.
560func (client APITagDescriptionClient) ListByServiceResponder(resp *http.Response) (result TagDescriptionCollection, err error) {
561	err = autorest.Respond(
562		resp,
563		azure.WithErrorUnlessStatusCode(http.StatusOK),
564		autorest.ByUnmarshallingJSON(&result),
565		autorest.ByClosing())
566	result.Response = autorest.Response{Response: resp}
567	return
568}
569
570// listByServiceNextResults retrieves the next set of results, if any.
571func (client APITagDescriptionClient) listByServiceNextResults(ctx context.Context, lastResults TagDescriptionCollection) (result TagDescriptionCollection, err error) {
572	req, err := lastResults.tagDescriptionCollectionPreparer(ctx)
573	if err != nil {
574		return result, autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", nil, "Failure preparing next results request")
575	}
576	if req == nil {
577		return
578	}
579	resp, err := client.ListByServiceSender(req)
580	if err != nil {
581		result.Response = autorest.Response{Response: resp}
582		return result, autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", resp, "Failure sending next results request")
583	}
584	result, err = client.ListByServiceResponder(resp)
585	if err != nil {
586		err = autorest.NewErrorWithError(err, "apimanagement.APITagDescriptionClient", "listByServiceNextResults", resp, "Failure responding to next results request")
587	}
588	return
589}
590
591// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
592func (client APITagDescriptionClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result TagDescriptionCollectionIterator, err error) {
593	if tracing.IsEnabled() {
594		ctx = tracing.StartSpan(ctx, fqdn+"/APITagDescriptionClient.ListByService")
595		defer func() {
596			sc := -1
597			if result.Response().Response.Response != nil {
598				sc = result.page.Response().Response.Response.StatusCode
599			}
600			tracing.EndSpan(ctx, sc, err)
601		}()
602	}
603	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
604	return
605}
606