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