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