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.
40func NewAPIIssueClientWithBaseURI(baseURI string, subscriptionID string) APIIssueClient {
41	return APIIssueClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates a new Issue for an API or updates an existing one.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// apiid - API identifier. Must be unique in the current API Management service instance.
49// issueID - issue identifier. Must be unique in the current API Management service instance.
50// parameters - create parameters.
51// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
52func (client APIIssueClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (result IssueContract, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.CreateOrUpdate")
55		defer func() {
56			sc := -1
57			if result.Response.Response != nil {
58				sc = result.Response.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: serviceName,
65			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
66				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
67				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
68		{TargetValue: apiid,
69			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
70				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
71		{TargetValue: issueID,
72			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
73				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
74				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
75		{TargetValue: parameters,
76			Constraints: []validation.Constraint{{Target: "parameters.IssueContractProperties", Name: validation.Null, Rule: false,
77				Chain: []validation.Constraint{{Target: "parameters.IssueContractProperties.Title", Name: validation.Null, Rule: true, Chain: nil},
78					{Target: "parameters.IssueContractProperties.Description", Name: validation.Null, Rule: true, Chain: nil},
79					{Target: "parameters.IssueContractProperties.UserID", Name: validation.Null, Rule: true, Chain: nil},
80				}}}}}); err != nil {
81		return result, validation.NewError("apimanagement.APIIssueClient", "CreateOrUpdate", err.Error())
82	}
83
84	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, parameters, ifMatch)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", nil, "Failure preparing request")
87		return
88	}
89
90	resp, err := client.CreateOrUpdateSender(req)
91	if err != nil {
92		result.Response = autorest.Response{Response: resp}
93		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure sending request")
94		return
95	}
96
97	result, err = client.CreateOrUpdateResponder(resp)
98	if err != nil {
99		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure responding to request")
100	}
101
102	return
103}
104
105// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
106func (client APIIssueClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (*http.Request, error) {
107	pathParameters := map[string]interface{}{
108		"apiId":             autorest.Encode("path", apiid),
109		"issueId":           autorest.Encode("path", issueID),
110		"resourceGroupName": autorest.Encode("path", resourceGroupName),
111		"serviceName":       autorest.Encode("path", serviceName),
112		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
113	}
114
115	const APIVersion = "2019-01-01"
116	queryParameters := map[string]interface{}{
117		"api-version": APIVersion,
118	}
119
120	preparer := autorest.CreatePreparer(
121		autorest.AsContentType("application/json; charset=utf-8"),
122		autorest.AsPut(),
123		autorest.WithBaseURL(client.BaseURI),
124		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
125		autorest.WithJSON(parameters),
126		autorest.WithQueryParameters(queryParameters))
127	if len(ifMatch) > 0 {
128		preparer = autorest.DecoratePreparer(preparer,
129			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
130	}
131	return preparer.Prepare((&http.Request{}).WithContext(ctx))
132}
133
134// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
135// http.Response Body if it receives an error.
136func (client APIIssueClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
137	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
138	return autorest.SendWithSender(client, req, sd...)
139}
140
141// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
142// closes the http.Response Body.
143func (client APIIssueClient) CreateOrUpdateResponder(resp *http.Response) (result IssueContract, err error) {
144	err = autorest.Respond(
145		resp,
146		client.ByInspecting(),
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	}
205
206	return
207}
208
209// DeletePreparer prepares the Delete request.
210func (client APIIssueClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (*http.Request, error) {
211	pathParameters := map[string]interface{}{
212		"apiId":             autorest.Encode("path", apiid),
213		"issueId":           autorest.Encode("path", issueID),
214		"resourceGroupName": autorest.Encode("path", resourceGroupName),
215		"serviceName":       autorest.Encode("path", serviceName),
216		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
217	}
218
219	const APIVersion = "2019-01-01"
220	queryParameters := map[string]interface{}{
221		"api-version": APIVersion,
222	}
223
224	preparer := autorest.CreatePreparer(
225		autorest.AsDelete(),
226		autorest.WithBaseURL(client.BaseURI),
227		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
228		autorest.WithQueryParameters(queryParameters),
229		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
230	return preparer.Prepare((&http.Request{}).WithContext(ctx))
231}
232
233// DeleteSender sends the Delete request. The method will close the
234// http.Response Body if it receives an error.
235func (client APIIssueClient) DeleteSender(req *http.Request) (*http.Response, error) {
236	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
237	return autorest.SendWithSender(client, req, sd...)
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		client.ByInspecting(),
246		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
247		autorest.ByClosing())
248	result.Response = resp
249	return
250}
251
252// Get gets the details of the Issue for an API specified by its identifier.
253// Parameters:
254// resourceGroupName - the name of the resource group.
255// serviceName - the name of the API Management service.
256// apiid - API identifier. Must be unique in the current API Management service instance.
257// issueID - issue identifier. Must be unique in the current API Management service instance.
258// expandCommentsAttachments - expand the comment attachments.
259func (client APIIssueClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, expandCommentsAttachments *bool) (result IssueContract, err error) {
260	if tracing.IsEnabled() {
261		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Get")
262		defer func() {
263			sc := -1
264			if result.Response.Response != nil {
265				sc = result.Response.Response.StatusCode
266			}
267			tracing.EndSpan(ctx, sc, err)
268		}()
269	}
270	if err := validation.Validate([]validation.Validation{
271		{TargetValue: serviceName,
272			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
273				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
274				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
275		{TargetValue: apiid,
276			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
277				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
278		{TargetValue: issueID,
279			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
280				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
281				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
282		return result, validation.NewError("apimanagement.APIIssueClient", "Get", err.Error())
283	}
284
285	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, issueID, expandCommentsAttachments)
286	if err != nil {
287		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", nil, "Failure preparing request")
288		return
289	}
290
291	resp, err := client.GetSender(req)
292	if err != nil {
293		result.Response = autorest.Response{Response: resp}
294		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure sending request")
295		return
296	}
297
298	result, err = client.GetResponder(resp)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure responding to request")
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 = "2019-01-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	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
336	return autorest.SendWithSender(client, req, sd...)
337}
338
339// GetResponder handles the response to the Get request. The method always
340// closes the http.Response Body.
341func (client APIIssueClient) GetResponder(resp *http.Response) (result IssueContract, err error) {
342	err = autorest.Respond(
343		resp,
344		client.ByInspecting(),
345		azure.WithErrorUnlessStatusCode(http.StatusOK),
346		autorest.ByUnmarshallingJSON(&result),
347		autorest.ByClosing())
348	result.Response = autorest.Response{Response: resp}
349	return
350}
351
352// GetEntityTag gets the entity state (Etag) version of the Issue for an API specified by its identifier.
353// Parameters:
354// resourceGroupName - the name of the resource group.
355// serviceName - the name of the API Management service.
356// apiid - API identifier. Must be unique in the current API Management service instance.
357// issueID - issue identifier. Must be unique in the current API Management service instance.
358func (client APIIssueClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (result autorest.Response, err error) {
359	if tracing.IsEnabled() {
360		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.GetEntityTag")
361		defer func() {
362			sc := -1
363			if result.Response != nil {
364				sc = result.Response.StatusCode
365			}
366			tracing.EndSpan(ctx, sc, err)
367		}()
368	}
369	if err := validation.Validate([]validation.Validation{
370		{TargetValue: serviceName,
371			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
372				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
373				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
374		{TargetValue: apiid,
375			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
376				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
377		{TargetValue: issueID,
378			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
379				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
380				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
381		return result, validation.NewError("apimanagement.APIIssueClient", "GetEntityTag", err.Error())
382	}
383
384	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, issueID)
385	if err != nil {
386		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "GetEntityTag", nil, "Failure preparing request")
387		return
388	}
389
390	resp, err := client.GetEntityTagSender(req)
391	if err != nil {
392		result.Response = resp
393		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "GetEntityTag", resp, "Failure sending request")
394		return
395	}
396
397	result, err = client.GetEntityTagResponder(resp)
398	if err != nil {
399		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "GetEntityTag", resp, "Failure responding to request")
400	}
401
402	return
403}
404
405// GetEntityTagPreparer prepares the GetEntityTag request.
406func (client APIIssueClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) {
407	pathParameters := map[string]interface{}{
408		"apiId":             autorest.Encode("path", apiid),
409		"issueId":           autorest.Encode("path", issueID),
410		"resourceGroupName": autorest.Encode("path", resourceGroupName),
411		"serviceName":       autorest.Encode("path", serviceName),
412		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
413	}
414
415	const APIVersion = "2019-01-01"
416	queryParameters := map[string]interface{}{
417		"api-version": APIVersion,
418	}
419
420	preparer := autorest.CreatePreparer(
421		autorest.AsHead(),
422		autorest.WithBaseURL(client.BaseURI),
423		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
424		autorest.WithQueryParameters(queryParameters))
425	return preparer.Prepare((&http.Request{}).WithContext(ctx))
426}
427
428// GetEntityTagSender sends the GetEntityTag request. The method will close the
429// http.Response Body if it receives an error.
430func (client APIIssueClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
431	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
432	return autorest.SendWithSender(client, req, sd...)
433}
434
435// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
436// closes the http.Response Body.
437func (client APIIssueClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
438	err = autorest.Respond(
439		resp,
440		client.ByInspecting(),
441		azure.WithErrorUnlessStatusCode(http.StatusOK),
442		autorest.ByClosing())
443	result.Response = resp
444	return
445}
446
447// ListByService lists all issues associated with the specified API.
448// Parameters:
449// resourceGroupName - the name of the resource group.
450// serviceName - the name of the API Management service.
451// apiid - API identifier. Must be unique in the current API Management service instance.
452// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
453// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
454// | substringof, contains, startswith, endswith | </br>| userId | filter | ge, le, eq, ne, gt, lt |
455// substringof, contains, startswith, endswith | </br>| state | filter | eq |     | </br>
456// expandCommentsAttachments - expand the comment attachments.
457// top - number of records to return.
458// skip - number of records to skip.
459func (client APIIssueClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, expandCommentsAttachments *bool, top *int32, skip *int32) (result IssueCollectionPage, err error) {
460	if tracing.IsEnabled() {
461		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.ListByService")
462		defer func() {
463			sc := -1
464			if result.ic.Response.Response != nil {
465				sc = result.ic.Response.Response.StatusCode
466			}
467			tracing.EndSpan(ctx, sc, err)
468		}()
469	}
470	if err := validation.Validate([]validation.Validation{
471		{TargetValue: serviceName,
472			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
473				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
474				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
475		{TargetValue: apiid,
476			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
477				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
478		{TargetValue: top,
479			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
480				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
481		{TargetValue: skip,
482			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
483				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
484		return result, validation.NewError("apimanagement.APIIssueClient", "ListByService", err.Error())
485	}
486
487	result.fn = client.listByServiceNextResults
488	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, expandCommentsAttachments, top, skip)
489	if err != nil {
490		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "ListByService", nil, "Failure preparing request")
491		return
492	}
493
494	resp, err := client.ListByServiceSender(req)
495	if err != nil {
496		result.ic.Response = autorest.Response{Response: resp}
497		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "ListByService", resp, "Failure sending request")
498		return
499	}
500
501	result.ic, err = client.ListByServiceResponder(resp)
502	if err != nil {
503		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "ListByService", resp, "Failure responding to request")
504	}
505
506	return
507}
508
509// ListByServicePreparer prepares the ListByService request.
510func (client APIIssueClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, expandCommentsAttachments *bool, top *int32, skip *int32) (*http.Request, error) {
511	pathParameters := map[string]interface{}{
512		"apiId":             autorest.Encode("path", apiid),
513		"resourceGroupName": autorest.Encode("path", resourceGroupName),
514		"serviceName":       autorest.Encode("path", serviceName),
515		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
516	}
517
518	const APIVersion = "2019-01-01"
519	queryParameters := map[string]interface{}{
520		"api-version": APIVersion,
521	}
522	if len(filter) > 0 {
523		queryParameters["$filter"] = autorest.Encode("query", filter)
524	}
525	if expandCommentsAttachments != nil {
526		queryParameters["expandCommentsAttachments"] = autorest.Encode("query", *expandCommentsAttachments)
527	}
528	if top != nil {
529		queryParameters["$top"] = autorest.Encode("query", *top)
530	}
531	if skip != nil {
532		queryParameters["$skip"] = autorest.Encode("query", *skip)
533	}
534
535	preparer := autorest.CreatePreparer(
536		autorest.AsGet(),
537		autorest.WithBaseURL(client.BaseURI),
538		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues", pathParameters),
539		autorest.WithQueryParameters(queryParameters))
540	return preparer.Prepare((&http.Request{}).WithContext(ctx))
541}
542
543// ListByServiceSender sends the ListByService request. The method will close the
544// http.Response Body if it receives an error.
545func (client APIIssueClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
546	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
547	return autorest.SendWithSender(client, req, sd...)
548}
549
550// ListByServiceResponder handles the response to the ListByService request. The method always
551// closes the http.Response Body.
552func (client APIIssueClient) ListByServiceResponder(resp *http.Response) (result IssueCollection, err error) {
553	err = autorest.Respond(
554		resp,
555		client.ByInspecting(),
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 autorest.Response, err error) {
610	if tracing.IsEnabled() {
611		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Update")
612		defer func() {
613			sc := -1
614			if result.Response != nil {
615				sc = result.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 = 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	}
652
653	return
654}
655
656// UpdatePreparer prepares the Update request.
657func (client APIIssueClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueUpdateContract, ifMatch string) (*http.Request, error) {
658	pathParameters := map[string]interface{}{
659		"apiId":             autorest.Encode("path", apiid),
660		"issueId":           autorest.Encode("path", issueID),
661		"resourceGroupName": autorest.Encode("path", resourceGroupName),
662		"serviceName":       autorest.Encode("path", serviceName),
663		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
664	}
665
666	const APIVersion = "2019-01-01"
667	queryParameters := map[string]interface{}{
668		"api-version": APIVersion,
669	}
670
671	preparer := autorest.CreatePreparer(
672		autorest.AsContentType("application/json; charset=utf-8"),
673		autorest.AsPatch(),
674		autorest.WithBaseURL(client.BaseURI),
675		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters),
676		autorest.WithJSON(parameters),
677		autorest.WithQueryParameters(queryParameters),
678		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
679	return preparer.Prepare((&http.Request{}).WithContext(ctx))
680}
681
682// UpdateSender sends the Update request. The method will close the
683// http.Response Body if it receives an error.
684func (client APIIssueClient) UpdateSender(req *http.Request) (*http.Response, error) {
685	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
686	return autorest.SendWithSender(client, req, sd...)
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 autorest.Response, err error) {
692	err = autorest.Respond(
693		resp,
694		client.ByInspecting(),
695		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
696		autorest.ByClosing())
697	result.Response = resp
698	return
699}
700