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