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// APISchemaClient is the apiManagement Client
30type APISchemaClient struct {
31	BaseClient
32}
33
34// NewAPISchemaClient creates an instance of the APISchemaClient client.
35func NewAPISchemaClient(subscriptionID string) APISchemaClient {
36	return NewAPISchemaClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPISchemaClientWithBaseURI creates an instance of the APISchemaClient client.
40func NewAPISchemaClientWithBaseURI(baseURI string, subscriptionID string) APISchemaClient {
41	return APISchemaClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates schema configuration for the API.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
49// revision has ;rev=n as a suffix where n is the revision number.
50// schemaID - schema identifier within an API. Must be unique in the current API Management service instance.
51// parameters - the schema contents to apply.
52// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
53func (client APISchemaClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string, parameters SchemaContract, ifMatch string) (result SchemaContract, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.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: 256, Chain: nil},
71				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
72				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
73		{TargetValue: schemaID,
74			Constraints: []validation.Constraint{{Target: "schemaID", Name: validation.MaxLength, Rule: 80, Chain: nil},
75				{Target: "schemaID", Name: validation.MinLength, Rule: 1, Chain: nil},
76				{Target: "schemaID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
77		{TargetValue: parameters,
78			Constraints: []validation.Constraint{{Target: "parameters.SchemaContractProperties", Name: validation.Null, Rule: false,
79				Chain: []validation.Constraint{{Target: "parameters.SchemaContractProperties.ContentType", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
80		return result, validation.NewError("apimanagement.APISchemaClient", "CreateOrUpdate", err.Error())
81	}
82
83	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, schemaID, parameters, ifMatch)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "CreateOrUpdate", nil, "Failure preparing request")
86		return
87	}
88
89	resp, err := client.CreateOrUpdateSender(req)
90	if err != nil {
91		result.Response = autorest.Response{Response: resp}
92		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "CreateOrUpdate", resp, "Failure sending request")
93		return
94	}
95
96	result, err = client.CreateOrUpdateResponder(resp)
97	if err != nil {
98		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "CreateOrUpdate", resp, "Failure responding to request")
99	}
100
101	return
102}
103
104// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
105func (client APISchemaClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string, parameters SchemaContract, ifMatch string) (*http.Request, error) {
106	pathParameters := map[string]interface{}{
107		"apiId":             autorest.Encode("path", apiid),
108		"resourceGroupName": autorest.Encode("path", resourceGroupName),
109		"schemaId":          autorest.Encode("path", schemaID),
110		"serviceName":       autorest.Encode("path", serviceName),
111		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
112	}
113
114	const APIVersion = "2018-06-01-preview"
115	queryParameters := map[string]interface{}{
116		"api-version": APIVersion,
117	}
118
119	preparer := autorest.CreatePreparer(
120		autorest.AsContentType("application/json; charset=utf-8"),
121		autorest.AsPut(),
122		autorest.WithBaseURL(client.BaseURI),
123		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/schemas/{schemaId}", pathParameters),
124		autorest.WithJSON(parameters),
125		autorest.WithQueryParameters(queryParameters))
126	if len(ifMatch) > 0 {
127		preparer = autorest.DecoratePreparer(preparer,
128			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
129	}
130	return preparer.Prepare((&http.Request{}).WithContext(ctx))
131}
132
133// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
134// http.Response Body if it receives an error.
135func (client APISchemaClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
136	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
137	return autorest.SendWithSender(client, req, sd...)
138}
139
140// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
141// closes the http.Response Body.
142func (client APISchemaClient) CreateOrUpdateResponder(resp *http.Response) (result SchemaContract, err error) {
143	err = autorest.Respond(
144		resp,
145		client.ByInspecting(),
146		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
147		autorest.ByUnmarshallingJSON(&result),
148		autorest.ByClosing())
149	result.Response = autorest.Response{Response: resp}
150	return
151}
152
153// Delete deletes the schema configuration at the Api.
154// Parameters:
155// resourceGroupName - the name of the resource group.
156// serviceName - the name of the API Management service.
157// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
158// revision has ;rev=n as a suffix where n is the revision number.
159// schemaID - schema identifier within an API. 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.
162// force - if true removes all references to the schema before deleting it.
163func (client APISchemaClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string, ifMatch string, force *bool) (result autorest.Response, err error) {
164	if tracing.IsEnabled() {
165		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.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: 256, Chain: nil},
181				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
182				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
183		{TargetValue: schemaID,
184			Constraints: []validation.Constraint{{Target: "schemaID", Name: validation.MaxLength, Rule: 80, Chain: nil},
185				{Target: "schemaID", Name: validation.MinLength, Rule: 1, Chain: nil},
186				{Target: "schemaID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
187		return result, validation.NewError("apimanagement.APISchemaClient", "Delete", err.Error())
188	}
189
190	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, schemaID, ifMatch, force)
191	if err != nil {
192		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "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.APISchemaClient", "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.APISchemaClient", "Delete", resp, "Failure responding to request")
206	}
207
208	return
209}
210
211// DeletePreparer prepares the Delete request.
212func (client APISchemaClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string, ifMatch string, force *bool) (*http.Request, error) {
213	pathParameters := map[string]interface{}{
214		"apiId":             autorest.Encode("path", apiid),
215		"resourceGroupName": autorest.Encode("path", resourceGroupName),
216		"schemaId":          autorest.Encode("path", schemaID),
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	if force != nil {
226		queryParameters["force"] = autorest.Encode("query", *force)
227	}
228
229	preparer := autorest.CreatePreparer(
230		autorest.AsDelete(),
231		autorest.WithBaseURL(client.BaseURI),
232		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/schemas/{schemaId}", pathParameters),
233		autorest.WithQueryParameters(queryParameters),
234		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
235	return preparer.Prepare((&http.Request{}).WithContext(ctx))
236}
237
238// DeleteSender sends the Delete request. The method will close the
239// http.Response Body if it receives an error.
240func (client APISchemaClient) DeleteSender(req *http.Request) (*http.Response, error) {
241	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
242	return autorest.SendWithSender(client, req, sd...)
243}
244
245// DeleteResponder handles the response to the Delete request. The method always
246// closes the http.Response Body.
247func (client APISchemaClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
248	err = autorest.Respond(
249		resp,
250		client.ByInspecting(),
251		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
252		autorest.ByClosing())
253	result.Response = resp
254	return
255}
256
257// Get get the schema configuration at the API level.
258// Parameters:
259// resourceGroupName - the name of the resource group.
260// serviceName - the name of the API Management service.
261// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
262// revision has ;rev=n as a suffix where n is the revision number.
263// schemaID - schema identifier within an API. Must be unique in the current API Management service instance.
264func (client APISchemaClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string) (result SchemaContract, err error) {
265	if tracing.IsEnabled() {
266		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.Get")
267		defer func() {
268			sc := -1
269			if result.Response.Response != nil {
270				sc = result.Response.Response.StatusCode
271			}
272			tracing.EndSpan(ctx, sc, err)
273		}()
274	}
275	if err := validation.Validate([]validation.Validation{
276		{TargetValue: serviceName,
277			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
278				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
279				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
280		{TargetValue: apiid,
281			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
282				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
283				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
284		{TargetValue: schemaID,
285			Constraints: []validation.Constraint{{Target: "schemaID", Name: validation.MaxLength, Rule: 80, Chain: nil},
286				{Target: "schemaID", Name: validation.MinLength, Rule: 1, Chain: nil},
287				{Target: "schemaID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
288		return result, validation.NewError("apimanagement.APISchemaClient", "Get", err.Error())
289	}
290
291	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, schemaID)
292	if err != nil {
293		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "Get", nil, "Failure preparing request")
294		return
295	}
296
297	resp, err := client.GetSender(req)
298	if err != nil {
299		result.Response = autorest.Response{Response: resp}
300		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "Get", resp, "Failure sending request")
301		return
302	}
303
304	result, err = client.GetResponder(resp)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "Get", resp, "Failure responding to request")
307	}
308
309	return
310}
311
312// GetPreparer prepares the Get request.
313func (client APISchemaClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string) (*http.Request, error) {
314	pathParameters := map[string]interface{}{
315		"apiId":             autorest.Encode("path", apiid),
316		"resourceGroupName": autorest.Encode("path", resourceGroupName),
317		"schemaId":          autorest.Encode("path", schemaID),
318		"serviceName":       autorest.Encode("path", serviceName),
319		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
320	}
321
322	const APIVersion = "2018-06-01-preview"
323	queryParameters := map[string]interface{}{
324		"api-version": APIVersion,
325	}
326
327	preparer := autorest.CreatePreparer(
328		autorest.AsGet(),
329		autorest.WithBaseURL(client.BaseURI),
330		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/schemas/{schemaId}", pathParameters),
331		autorest.WithQueryParameters(queryParameters))
332	return preparer.Prepare((&http.Request{}).WithContext(ctx))
333}
334
335// GetSender sends the Get request. The method will close the
336// http.Response Body if it receives an error.
337func (client APISchemaClient) GetSender(req *http.Request) (*http.Response, error) {
338	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
339	return autorest.SendWithSender(client, req, sd...)
340}
341
342// GetResponder handles the response to the Get request. The method always
343// closes the http.Response Body.
344func (client APISchemaClient) GetResponder(resp *http.Response) (result SchemaContract, err error) {
345	err = autorest.Respond(
346		resp,
347		client.ByInspecting(),
348		azure.WithErrorUnlessStatusCode(http.StatusOK),
349		autorest.ByUnmarshallingJSON(&result),
350		autorest.ByClosing())
351	result.Response = autorest.Response{Response: resp}
352	return
353}
354
355// GetEntityTag gets the entity state (Etag) version of the schema specified by its identifier.
356// Parameters:
357// resourceGroupName - the name of the resource group.
358// serviceName - the name of the API Management service.
359// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
360// revision has ;rev=n as a suffix where n is the revision number.
361// schemaID - schema identifier within an API. Must be unique in the current API Management service instance.
362func (client APISchemaClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string) (result autorest.Response, err error) {
363	if tracing.IsEnabled() {
364		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.GetEntityTag")
365		defer func() {
366			sc := -1
367			if result.Response != nil {
368				sc = result.Response.StatusCode
369			}
370			tracing.EndSpan(ctx, sc, err)
371		}()
372	}
373	if err := validation.Validate([]validation.Validation{
374		{TargetValue: serviceName,
375			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
376				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
377				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
378		{TargetValue: apiid,
379			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
380				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
381				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
382		{TargetValue: schemaID,
383			Constraints: []validation.Constraint{{Target: "schemaID", Name: validation.MaxLength, Rule: 80, Chain: nil},
384				{Target: "schemaID", Name: validation.MinLength, Rule: 1, Chain: nil},
385				{Target: "schemaID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
386		return result, validation.NewError("apimanagement.APISchemaClient", "GetEntityTag", err.Error())
387	}
388
389	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, schemaID)
390	if err != nil {
391		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "GetEntityTag", nil, "Failure preparing request")
392		return
393	}
394
395	resp, err := client.GetEntityTagSender(req)
396	if err != nil {
397		result.Response = resp
398		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "GetEntityTag", resp, "Failure sending request")
399		return
400	}
401
402	result, err = client.GetEntityTagResponder(resp)
403	if err != nil {
404		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "GetEntityTag", resp, "Failure responding to request")
405	}
406
407	return
408}
409
410// GetEntityTagPreparer prepares the GetEntityTag request.
411func (client APISchemaClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, schemaID string) (*http.Request, error) {
412	pathParameters := map[string]interface{}{
413		"apiId":             autorest.Encode("path", apiid),
414		"resourceGroupName": autorest.Encode("path", resourceGroupName),
415		"schemaId":          autorest.Encode("path", schemaID),
416		"serviceName":       autorest.Encode("path", serviceName),
417		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
418	}
419
420	const APIVersion = "2018-06-01-preview"
421	queryParameters := map[string]interface{}{
422		"api-version": APIVersion,
423	}
424
425	preparer := autorest.CreatePreparer(
426		autorest.AsHead(),
427		autorest.WithBaseURL(client.BaseURI),
428		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/schemas/{schemaId}", pathParameters),
429		autorest.WithQueryParameters(queryParameters))
430	return preparer.Prepare((&http.Request{}).WithContext(ctx))
431}
432
433// GetEntityTagSender sends the GetEntityTag request. The method will close the
434// http.Response Body if it receives an error.
435func (client APISchemaClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
436	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
437	return autorest.SendWithSender(client, req, sd...)
438}
439
440// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
441// closes the http.Response Body.
442func (client APISchemaClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
443	err = autorest.Respond(
444		resp,
445		client.ByInspecting(),
446		azure.WithErrorUnlessStatusCode(http.StatusOK),
447		autorest.ByClosing())
448	result.Response = resp
449	return
450}
451
452// ListByAPI get the schema configuration at the API level.
453// Parameters:
454// resourceGroupName - the name of the resource group.
455// serviceName - the name of the API Management service.
456// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
457// revision has ;rev=n as a suffix where n is the revision number.
458// filter - | Field       | Supported operators    | Supported functions               |
459// |-------------|------------------------|-----------------------------------|
460//
461// |contentType | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith|
462// top - number of records to return.
463// skip - number of records to skip.
464func (client APISchemaClient) ListByAPI(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result SchemaCollectionPage, err error) {
465	if tracing.IsEnabled() {
466		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.ListByAPI")
467		defer func() {
468			sc := -1
469			if result.sc.Response.Response != nil {
470				sc = result.sc.Response.Response.StatusCode
471			}
472			tracing.EndSpan(ctx, sc, err)
473		}()
474	}
475	if err := validation.Validate([]validation.Validation{
476		{TargetValue: serviceName,
477			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
478				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
479				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
480		{TargetValue: apiid,
481			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
482				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
483				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
484		{TargetValue: top,
485			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
486				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
487		{TargetValue: skip,
488			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
489				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
490		return result, validation.NewError("apimanagement.APISchemaClient", "ListByAPI", err.Error())
491	}
492
493	result.fn = client.listByAPINextResults
494	req, err := client.ListByAPIPreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
495	if err != nil {
496		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "ListByAPI", nil, "Failure preparing request")
497		return
498	}
499
500	resp, err := client.ListByAPISender(req)
501	if err != nil {
502		result.sc.Response = autorest.Response{Response: resp}
503		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "ListByAPI", resp, "Failure sending request")
504		return
505	}
506
507	result.sc, err = client.ListByAPIResponder(resp)
508	if err != nil {
509		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "ListByAPI", resp, "Failure responding to request")
510	}
511
512	return
513}
514
515// ListByAPIPreparer prepares the ListByAPI request.
516func (client APISchemaClient) ListByAPIPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) {
517	pathParameters := map[string]interface{}{
518		"apiId":             autorest.Encode("path", apiid),
519		"resourceGroupName": autorest.Encode("path", resourceGroupName),
520		"serviceName":       autorest.Encode("path", serviceName),
521		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
522	}
523
524	const APIVersion = "2018-06-01-preview"
525	queryParameters := map[string]interface{}{
526		"api-version": APIVersion,
527	}
528	if len(filter) > 0 {
529		queryParameters["$filter"] = autorest.Encode("query", filter)
530	}
531	if top != nil {
532		queryParameters["$top"] = autorest.Encode("query", *top)
533	}
534	if skip != nil {
535		queryParameters["$skip"] = autorest.Encode("query", *skip)
536	}
537
538	preparer := autorest.CreatePreparer(
539		autorest.AsGet(),
540		autorest.WithBaseURL(client.BaseURI),
541		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/schemas", pathParameters),
542		autorest.WithQueryParameters(queryParameters))
543	return preparer.Prepare((&http.Request{}).WithContext(ctx))
544}
545
546// ListByAPISender sends the ListByAPI request. The method will close the
547// http.Response Body if it receives an error.
548func (client APISchemaClient) ListByAPISender(req *http.Request) (*http.Response, error) {
549	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
550	return autorest.SendWithSender(client, req, sd...)
551}
552
553// ListByAPIResponder handles the response to the ListByAPI request. The method always
554// closes the http.Response Body.
555func (client APISchemaClient) ListByAPIResponder(resp *http.Response) (result SchemaCollection, 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// listByAPINextResults retrieves the next set of results, if any.
567func (client APISchemaClient) listByAPINextResults(ctx context.Context, lastResults SchemaCollection) (result SchemaCollection, err error) {
568	req, err := lastResults.schemaCollectionPreparer(ctx)
569	if err != nil {
570		return result, autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "listByAPINextResults", nil, "Failure preparing next results request")
571	}
572	if req == nil {
573		return
574	}
575	resp, err := client.ListByAPISender(req)
576	if err != nil {
577		result.Response = autorest.Response{Response: resp}
578		return result, autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "listByAPINextResults", resp, "Failure sending next results request")
579	}
580	result, err = client.ListByAPIResponder(resp)
581	if err != nil {
582		err = autorest.NewErrorWithError(err, "apimanagement.APISchemaClient", "listByAPINextResults", resp, "Failure responding to next results request")
583	}
584	return
585}
586
587// ListByAPIComplete enumerates all values, automatically crossing page boundaries as required.
588func (client APISchemaClient) ListByAPIComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result SchemaCollectionIterator, err error) {
589	if tracing.IsEnabled() {
590		ctx = tracing.StartSpan(ctx, fqdn+"/APISchemaClient.ListByAPI")
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.ListByAPI(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
600	return
601}
602