From 7158d69aa9573ab7fd6342b611e6cf962e15e7c0 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 20 Jul 2021 16:06:53 +0000 Subject: [PATCH] CodeGen from PR 14871 in Azure/azure-rest-api-specs [Maps] Add separate Swagger definitions for Maps client libraries (#14871) * Make maps data-plane swagger files compile when taken from api to sdk. * Update correctly the search api * Update common.js and add swagger codegen to maps dataplane. * Fix path issue * fix prettifier error. * Replace mistyped extension. * Fix common type version. * Fix errors for alias.json * run prettier * fix security def and parameters. * Revert "fix security def and parameters." This reverts commit 85370d9b6b3ad0ae615d1931aa7a5eec39957b30. * Revert "run prettier" This reverts commit be16d4423be319cc4b7a957abe977aced26e0fa5. * Revert "Fix errors for alias.json" This reverts commit 0458cbc9489ba8cc05a575517b35001fa4c4a7e8. * fix extension issue * comment out all other errors. * revert changes to package.json files * update files. remove common response as it isn't supported. * update readonly problem * Update error correctly to not be a breaking change * Remove unused definition. * Fix GeoJSONGeometryCollection * Fix naming scheme * fix coord abb * fix geometryCollection error by using a more generic type for inheritance. * update anon def * try without schema * fix naming issue. * add schema * try again * update common file * update route.json file * Revert "update route.json file" This reverts commit 2858248ea19ece1998617afbb83c1b6633487834. * Update geometry collection. * fix go modeler error * remove type * - fix ModelValidation * - enable Java and Python generation * try with new errorDetail. * correct paths * revert changes to odataerror. update python sdk. * fix typo * update error and readonly CoordinateAbbreviated to reuse more. * - try to build Python SDK * - try to forcefully build Python SDK * Add top level java. * update warnings from lint diff * try java generation with the inline file. * update Java compilation with right tags. * Fix compilation warnings * Update readme namespace names * Make enums be modelAsString: true * Add x-ms-error-response to error responses * Remove feedback.json and feedback reference from readme.md. * Fix "security" requirement object to have valid scope for OAuth2 security scheme type * Fix "security" requirement object to have valid scope for OAuth2 security scheme type - add missing file * Use common client parameters - part 1 * Use common client parameters - part 2 * Fix lint errors * update go namespace to the correct one. * Use common response objects to fix duplicate schemas * Fix semantic & model validation W/A for OAV as it is not able to parse Swagger file without "responses" object. * Fix autorest duplicate schema warnings Use common schema for Language, View, xTileIndex & yTileIndex between Render 1.0, Render 2.0, Search 1.0 and Traffic 1.0. * Fix C# generation of StyleRuleBaseType enum type * Fix license header for GO lang * Fix inheritance of the StyleRuleBase type in the FeatureState API * Revert resource-manager changes. * Remove current version. * Update java namespace. * Fix StyleRuleBase type inherited types generation * Fix prettier error * Use common GeoJson naming & fix inheritance * Update 200 response to be 200Async instead of error response. Also update the examples for the given routes. * Fix StyleRuleBase type inherited types generation * Fix 'avoid' parameter in Route service to be actually an array of things to avoid * Rename definitions to have at least two words (fix AZC0012 error) and add missing x-ms-enums. * Fix prettier * Fix GeoJSON type hierarchy and WFS examples * Fix long running operation definitions and examples * Add missing descriptions * Define batch responses in more detail & remove redundant definitions in Search API * Alias - remove unused definitions and empty 204 response * Data - remove unused definitions, empty 204 responses and file upload parameters * Dataset - remove unused definitions and empty 204 response * Fix description and linter validation * Elevation - remove unused definitions, merge some of them to get less models * Conversion, Feature State & Geolocation - remove unused definitions and empty 204 response * Use previous package-1.0-preview until new package-preview-2.0 is fixed. * Fix merge conflicts after rebase and security LintDiff * Fix Alias, Data, Dataset, Conversion, Feature State, Tileset & WFS 2.0 services * Fix linter warnings - Use common definition for ontology * Fix linter errors - LongRunningResponseStatusCode * Fix ApiDocPreview * Use different tag format to not relate with API version used * Use dummy trick to make ApiDocPreview and Avocado work * Another approach for ApiDocPreview * Seems like it is impossible to make ApiDocPreview work until someone takes a look at "REST API CI Script Reporter" in the "OpenAPIPortal-REST-Generator" pipeline and fix it to use referenced Swagger files. * update featureid to local parameter in wfs to see if it fixes error. * Remove dataset from wfs as it is not needed to fix doc preview. * Remove part that should be auto generated. * Fix error with java codegen. * Try to only export new versions of api. * Readd removed api's. Try with wfs v1 to see if api-preview passes. * remove wfs2 * Re-add wfs * update the readme.go to see if it generates install instructions. * add after scripts to bundle install * Remove defaults from route to test if it fixes go sdk problems. * Remove "x-publish" just for api doc preview test * fix JSON typo after removal * Experiment: do not use common responses for WFS 2.0 * Remove required false as it is the default value for query parameters. Remove default value for non required values. * run prettier. * Add onbe error-response individually to see if it fixes alias error. * Revert experimental WFS changes * Remove unused error. * Remove duplicated common file for 2.0 * Use ResponseFormat as a name for JsonFormat as one of the values is Json * Mobility & Render - fix response types, remove unnecessary definitions * Revert renaming TransitRouteType * revert data.json to consume the correct type * Only put at consumes application/json * Update consumes for data. * Render - rename operations to have common names with examples * update python codegen to use track2 correctly * Also change track2 from readme.md * Add track2 and track1 * Don't generate the sdk for arm. * Remove python track1 and add net track2. * Search - reduce number of responses for common cases * Elevation - fix input param for GetDataForPolyLine * Spatial - remove duplicated & unused definitions * Data - fix model validation * Tileset - remove 204 body Add x-ms-pageable to where it suits * Timezone & Traffic - fix "produces" fields and Traffic file responses * Add azure-sdk-for-net-track2 references to the -pr repo * Use azure-sdk-for-net without track2 since it's not enabled in the CI yet. * Weather - remove unused definitions * WFS 1.0 - remove unused definition and standardize naming * WFS 2.0 - remove unused definition and standardize naming * Put TextFormat & GeographicResourceLocation to a common file * Fix double to integer so that calls work. * Skip url encoding for elevation input parameters. * Put url ecoding to correct spot. * update geoemtries to be comma separated array. * Change search parameter order so that textFormat is always first. * Change parameter to udid from udId to be consistent * update wfs limit from float to int * update from string to datetime * Refix elevation. * Fix elevation prettier. * correctly update parameter to udid. * Add geography to all services. * update date-time * Add description to data * Add client flatten * Run prettier * Add geometry to examples. * Update missing routes. * Route - fix added endpoints for missing API * Use autorest v3 for TypeScript code gen * Add arm to python sdk in order to have aad auth. * Run prettier on route. * update get routes fixes. * put correct name for example. * update format * Add missing responses * Add same security for all. * fix copyright and countryCode warnings * remove arm. * fix extra comma * Add long running * Remove unused stuff from readme.md * Run prettifier * see if x-publish fixes linter error. * Replace description. * disable long running operation for put state update * Add schema of type string. * Replace description * Remove schema. * Remove after install to see if go package still fails. * Change credential type to bearer. and remove each sub key param. * - remove XML since our client libs are using JSON only and TS codegen cannot parse responses properly * - fix DWG conversion 200 response to not be an error but actual result with operationId in the body - use 6.0.0-alpha.20210514.1 TS codegen as latest beta has broken LRO support for JS core v1 (cannot use core v2 due to missing API key credential) * Fix Data & Dataset conversion 200 response to not be an error but actual result with operationId in the body * Fix OAuth description for Lint diff & fix prettier * Another try for the LintDiff CI * Yet another try for the LintDiff CI * Remove security from common * fix description message. * Remove preview 1 since preview 2 is added. * remove unused preview 1 files. * Change api version from common to each service. * Add default error. * Update version and route and search with batch. Remove subscription key from examples. * fixes. * Re-add 408. * fixes to errors. * update types. * Update description for batch. * remove unused errors from examples. * fix ci after changes. * fix again errors in examples. * remove package-preview-1.0 from go. * Remove go codegen as track1 isn't supported for data-plane. * Leave go readme. Remove js from ci for now. * remove 200 from dataset. * Put 200 response back to the Maps LROs. Although those paths do not return 200 directly (202 instead) the TS codegen takes 200 definition for the response type, so it is needed to deserialize. * Try to use .NET Track 2 * Workaround TS autogen limitation - loses inherited class properties due to invalid deserialization of base class properties only * Fix 200 to be 400 error(fix duplicate) * change versioning. * commit unsaved files. * fix wrong version. * fix breaking change. * Fix LintDiff errors and azure-sdk-for-net build * fix cSpell * Fix common descriptions for other Swaggers after e0624d2b17a8dcee07acfb08f39508a773a8dc21 * Use the new Azure AD description * Add back API key description * update consumes in data * fix typo. * update creator. * update references * update spatial version to 2. * fix data upload. * move spatial back to 1.0 for now and update batch to have 200 in case of success. * Remove mobility as its deprecated. * move spatial samples. * Update config md files & fix minor versioning issues * Remove unnecessary "produces" and "202Batch" * Use autorest's predefined AADToken & AzureKey * Generate public clients for C# * Prettier fix * change go namespaces * golang track2 config updates * Use latest TypeScript generator with core v2 * Fix Swagger ModelValidation Co-authored-by: Dragos Daian Co-authored-by: ambientlight --- .../src/Generated/GeolocationClient.cs | 231 +++++++++++++++++ .../src/Generated/GeolocationOperations.cs | 244 ++++++++++++++++++ .../GeolocationOperationsExtensions.cs | 53 ++++ .../src/Generated/IGeolocationClient.cs | 71 +++++ .../src/Generated/IGeolocationOperations.cs | 59 +++++ .../src/Generated/Models/CountryRegion.cs | 59 +++++ .../Generated/Models/ErrorAdditionalInfo.cs | 59 +++++ .../src/Generated/Models/ErrorDetail.cs | 85 ++++++ .../src/Generated/Models/ErrorResponse.cs | 56 ++++ .../Models/ErrorResponseException.cs | 62 +++++ .../Models/GeographicResourceLocation.cs | 28 ++ .../Models/IpAddressToLocationResult.cs | 58 +++++ .../Generated/SdkInfo_GeolocationClient.cs | 27 ++ 13 files changed, 1092 insertions(+) create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationClient.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperations.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperationsExtensions.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationClient.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationOperations.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/CountryRegion.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorAdditionalInfo.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorDetail.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponse.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponseException.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/GeographicResourceLocation.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/IpAddressToLocationResult.cs create mode 100644 sdk/maps/Azure.Maps.Geolocation/src/Generated/SdkInfo_GeolocationClient.cs diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationClient.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationClient.cs new file mode 100644 index 0000000000000..6d553c1cae600 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationClient.cs @@ -0,0 +1,231 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using Microsoft.Rest; + using Microsoft.Rest.Serialization; + using Models; + using Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + + /// + /// Azure Maps Geolocation REST APIs + /// + public partial class GeolocationClient : ServiceClient, IGeolocationClient + { + /// + /// The base URI of the service. + /// + internal string BaseUri {get; set;} + + /// + /// Gets or sets json serialization settings. + /// + public JsonSerializerSettings SerializationSettings { get; private set; } + + /// + /// Gets or sets json deserialization settings. + /// + public JsonSerializerSettings DeserializationSettings { get; private set; } + + /// + /// Version number of Azure Maps API. + /// + public string ApiVersion { get; set; } + + /// + /// Specifies which account is intended for usage in conjunction with the Azure + /// AD security model. It represents a unique ID for the Azure Maps account + /// and can be retrieved from the Azure Maps management plane Account API. To + /// use Azure AD security in Azure Maps see the following + /// [articles](https://aka.ms/amauthdetails) for guidance. + /// + public string XMsClientId { get; set; } + + /// + /// This parameter specifies where the Azure Maps Creator resource is located. + /// Valid values are us and eu. Possible values include: 'us', 'eu' + /// + public string Geography { get; set; } + + /// + /// Subscription credentials which uniquely identify client subscription. + /// + public ServiceClientCredentials Credentials { get; private set; } + + /// + /// Gets the IGeolocationOperations. + /// + public virtual IGeolocationOperations Geolocation { get; private set; } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// HttpClient to be used + /// + /// + /// True: will dispose the provided httpClient on calling GeolocationClient.Dispose(). False: will not dispose provided httpClient + protected GeolocationClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient) + { + Initialize(); + } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + protected GeolocationClient(params DelegatingHandler[] handlers) : base(handlers) + { + Initialize(); + } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// Optional. The http client handler used to handle http transport. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + protected GeolocationClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers) + { + Initialize(); + } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// Required. Subscription credentials which uniquely identify client subscription. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + /// + /// Thrown when a required parameter is null + /// + public GeolocationClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers) + { + if (credentials == null) + { + throw new System.ArgumentNullException("credentials"); + } + Credentials = credentials; + if (Credentials != null) + { + Credentials.InitializeServiceClient(this); + } + } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// Required. Subscription credentials which uniquely identify client subscription. + /// + /// + /// HttpClient to be used + /// + /// + /// True: will dispose the provided httpClient on calling GeolocationClient.Dispose(). False: will not dispose provided httpClient + /// + /// Thrown when a required parameter is null + /// + public GeolocationClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient) + { + if (credentials == null) + { + throw new System.ArgumentNullException("credentials"); + } + Credentials = credentials; + if (Credentials != null) + { + Credentials.InitializeServiceClient(this); + } + } + + /// + /// Initializes a new instance of the GeolocationClient class. + /// + /// + /// Required. Subscription credentials which uniquely identify client subscription. + /// + /// + /// Optional. The http client handler used to handle http transport. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + /// + /// Thrown when a required parameter is null + /// + public GeolocationClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) + { + if (credentials == null) + { + throw new System.ArgumentNullException("credentials"); + } + Credentials = credentials; + if (Credentials != null) + { + Credentials.InitializeServiceClient(this); + } + } + + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); + /// + /// Initializes client properties. + /// + private void Initialize() + { + Geolocation = new GeolocationOperations(this); + BaseUri = "https://{geography}.atlas.microsoft.com"; + ApiVersion = "1.0"; + Geography = "us"; + SerializationSettings = new JsonSerializerSettings + { + Formatting = Newtonsoft.Json.Formatting.Indented, + DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, + DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, + NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, + ContractResolver = new ReadOnlyJsonContractResolver(), + Converters = new List + { + new Iso8601TimeSpanConverter() + } + }; + DeserializationSettings = new JsonSerializerSettings + { + DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, + DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, + NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, + ContractResolver = new ReadOnlyJsonContractResolver(), + Converters = new List + { + new Iso8601TimeSpanConverter() + } + }; + CustomInitialize(); + } + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperations.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperations.cs new file mode 100644 index 0000000000000..a3e0d2180031d --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperations.cs @@ -0,0 +1,244 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using Microsoft.Rest; + using Models; + using Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + + /// + /// GeolocationOperations operations. + /// + public partial class GeolocationOperations : IServiceOperations, IGeolocationOperations + { + /// + /// Initializes a new instance of the GeolocationOperations class. + /// + /// + /// Reference to the service client. + /// + /// + /// Thrown when a required parameter is null + /// + public GeolocationOperations(GeolocationClient client) + { + if (client == null) + { + throw new System.ArgumentNullException("client"); + } + Client = client; + } + + /// + /// Gets a reference to the GeolocationClient + /// + public GeolocationClient Client { get; private set; } + + /// + /// + /// **Applies to**: S0 and S1 pricing tiers. + /// + /// + /// This service will return the ISO country code for the provided IP address. + /// Developers can use this information to block or alter certain content + /// based on geographical locations where the application is being viewed from. + /// + /// + /// __Note:__ This service returns results from IANA and does not necessarily + /// reflect the views of Microsoft Corporation. + /// + /// + /// The IP address. Both IPv4 and IPv6 are allowed. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task> GetIPToLocationPreviewWithHttpMessagesAsync(string ip, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (Client.Geography == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Geography"); + } + if (Client.ApiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); + } + if (ip == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "ip"); + } + string format = "json"; + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("format", format); + tracingParameters.Add("ip", ip); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "GetIPToLocationPreview", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "geolocation/ip/{format}"; + _url = _url.Replace("{geography}", System.Uri.EscapeDataString(Client.Geography)); + _url = _url.Replace("{format}", System.Uri.EscapeDataString(format)); + List _queryParameters = new List(); + if (Client.ApiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); + } + if (ip != null) + { + _queryParameters.Add(string.Format("ip={0}", System.Uri.EscapeDataString(ip))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("GET"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + if (Client.XMsClientId != null) + { + if (_httpRequest.Headers.Contains("x-ms-client-id")) + { + _httpRequest.Headers.Remove("x-ms-client-id"); + } + _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-id", Client.XMsClientId); + } + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Set Credentials + if (Client.Credentials != null) + { + cancellationToken.ThrowIfCancellationRequested(); + await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorResponse _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + // Deserialize Response + if ((int)_statusCode == 200) + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + try + { + _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); + } + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperationsExtensions.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperationsExtensions.cs new file mode 100644 index 0000000000000..72c2d77822203 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/GeolocationOperationsExtensions.cs @@ -0,0 +1,53 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using Models; + using System.Threading; + using System.Threading.Tasks; + + /// + /// Extension methods for GeolocationOperations. + /// + public static partial class GeolocationOperationsExtensions + { + /// + /// + /// **Applies to**: S0 and S1 pricing tiers. + /// + /// + /// This service will return the ISO country code for the provided IP address. + /// Developers can use this information to block or alter certain content + /// based on geographical locations where the application is being viewed from. + /// + /// + /// __Note:__ This service returns results from IANA and does not necessarily + /// reflect the views of Microsoft Corporation. + /// + /// + /// The operations group for this extension method. + /// + /// + /// The IP address. Both IPv4 and IPv6 are allowed. + /// + /// + /// The cancellation token. + /// + public static async Task GetIPToLocationPreviewAsync(this IGeolocationOperations operations, string ip, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.GetIPToLocationPreviewWithHttpMessagesAsync(ip, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Body; + } + } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationClient.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationClient.cs new file mode 100644 index 0000000000000..86d909ff91dac --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationClient.cs @@ -0,0 +1,71 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using Microsoft.Rest; + using Models; + using Newtonsoft.Json; + + /// + /// Azure Maps Geolocation REST APIs + /// + public partial interface IGeolocationClient : System.IDisposable + { + /// + /// The base URI of the service. + /// + + /// + /// Gets or sets json serialization settings. + /// + JsonSerializerSettings SerializationSettings { get; } + + /// + /// Gets or sets json deserialization settings. + /// + JsonSerializerSettings DeserializationSettings { get; } + + /// + /// Version number of Azure Maps API. + /// + string ApiVersion { get; set; } + + /// + /// Specifies which account is intended for usage in conjunction with + /// the Azure AD security model. It represents a unique ID for the + /// Azure Maps account and can be retrieved from the Azure Maps + /// management plane Account API. To use Azure AD security in Azure + /// Maps see the following [articles](https://aka.ms/amauthdetails) for + /// guidance. + /// + string XMsClientId { get; set; } + + /// + /// This parameter specifies where the Azure Maps Creator resource is + /// located. Valid values are us and eu. Possible values include: + /// 'us', 'eu' + /// + string Geography { get; set; } + + /// + /// Subscription credentials which uniquely identify client + /// subscription. + /// + ServiceClientCredentials Credentials { get; } + + + /// + /// Gets the IGeolocationOperations. + /// + IGeolocationOperations Geolocation { get; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationOperations.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationOperations.cs new file mode 100644 index 0000000000000..e6e131bd5aa07 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/IGeolocationOperations.cs @@ -0,0 +1,59 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using Microsoft.Rest; + using Models; + using System.Collections; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + /// + /// GeolocationOperations operations. + /// + public partial interface IGeolocationOperations + { + /// + /// + /// **Applies to**: S0 and S1 pricing tiers. + /// + /// + /// This service will return the ISO country code for the provided IP + /// address. Developers can use this information to block or alter + /// certain content based on geographical locations where the + /// application is being viewed from. + /// + /// + /// __Note:__ This service returns results from IANA and does not + /// necessarily reflect the views of Microsoft Corporation. + /// + /// + /// The IP address. Both IPv4 and IPv6 are allowed. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + Task> GetIPToLocationPreviewWithHttpMessagesAsync(string ip, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/CountryRegion.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/CountryRegion.cs new file mode 100644 index 0000000000000..847572f1b701f --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/CountryRegion.cs @@ -0,0 +1,59 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// The object containing the country/region information. + /// + public partial class CountryRegion + { + /// + /// Initializes a new instance of the CountryRegion class. + /// + public CountryRegion() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the CountryRegion class. + /// + /// The IP Address's 2-character code [(ISO + /// 3166-1)](https://www.iso.org/iso-3166-country-codes.html) of the + /// country or region as assigned by IANA and regional internet + /// authorities. Please note, IP address in ranges reserved for special + /// purpose will return Null for country/region. + public CountryRegion(string isoCode = default(string)) + { + IsoCode = isoCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets the IP Address's 2-character code [(ISO + /// 3166-1)](https://www.iso.org/iso-3166-country-codes.html) of the + /// country or region as assigned by IANA and regional internet + /// authorities. Please note, IP address in ranges reserved for special + /// purpose will return Null for country/region. + /// + [JsonProperty(PropertyName = "isoCode")] + public string IsoCode { get; private set; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorAdditionalInfo.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorAdditionalInfo.cs new file mode 100644 index 0000000000000..47f4ff674800f --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorAdditionalInfo.cs @@ -0,0 +1,59 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// The resource management error additional info. + /// + public partial class ErrorAdditionalInfo + { + /// + /// Initializes a new instance of the ErrorAdditionalInfo class. + /// + public ErrorAdditionalInfo() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ErrorAdditionalInfo class. + /// + /// The additional info type. + /// The additional info. + public ErrorAdditionalInfo(string type = default(string), object info = default(object)) + { + Type = type; + Info = info; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets the additional info type. + /// + [JsonProperty(PropertyName = "type")] + public string Type { get; private set; } + + /// + /// Gets the additional info. + /// + [JsonProperty(PropertyName = "info")] + public object Info { get; private set; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorDetail.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorDetail.cs new file mode 100644 index 0000000000000..98d4b84a5cdfc --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorDetail.cs @@ -0,0 +1,85 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + + /// + /// The error detail. + /// + public partial class ErrorDetail + { + /// + /// Initializes a new instance of the ErrorDetail class. + /// + public ErrorDetail() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ErrorDetail class. + /// + /// The error code. + /// The error message. + /// The error target. + /// The error details. + /// The error additional info. + public ErrorDetail(string code = default(string), string message = default(string), string target = default(string), IList details = default(IList), IList additionalInfo = default(IList)) + { + Code = code; + Message = message; + Target = target; + Details = details; + AdditionalInfo = additionalInfo; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets the error code. + /// + [JsonProperty(PropertyName = "code")] + public string Code { get; private set; } + + /// + /// Gets the error message. + /// + [JsonProperty(PropertyName = "message")] + public string Message { get; private set; } + + /// + /// Gets the error target. + /// + [JsonProperty(PropertyName = "target")] + public string Target { get; private set; } + + /// + /// Gets the error details. + /// + [JsonProperty(PropertyName = "details")] + public IList Details { get; private set; } + + /// + /// Gets the error additional info. + /// + [JsonProperty(PropertyName = "additionalInfo")] + public IList AdditionalInfo { get; private set; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponse.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponse.cs new file mode 100644 index 0000000000000..75ac1dd9c4dab --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponse.cs @@ -0,0 +1,56 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Error response + /// + /// + /// Common error response for all Azure Resource Manager APIs to return + /// error details for failed operations. (This also follows the OData error + /// response format.). + /// + public partial class ErrorResponse + { + /// + /// Initializes a new instance of the ErrorResponse class. + /// + public ErrorResponse() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ErrorResponse class. + /// + /// The error object. + public ErrorResponse(ErrorDetail error = default(ErrorDetail)) + { + Error = error; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets or sets the error object. + /// + [JsonProperty(PropertyName = "error")] + public ErrorDetail Error { get; set; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponseException.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponseException.cs new file mode 100644 index 0000000000000..17c95bfb5c337 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/ErrorResponseException.cs @@ -0,0 +1,62 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Microsoft.Rest; + + /// + /// Exception thrown for an invalid response with ErrorResponse + /// information. + /// + public partial class ErrorResponseException : RestException + { + /// + /// Gets information about the associated HTTP request. + /// + public HttpRequestMessageWrapper Request { get; set; } + + /// + /// Gets information about the associated HTTP response. + /// + public HttpResponseMessageWrapper Response { get; set; } + + /// + /// Gets or sets the body object. + /// + public ErrorResponse Body { get; set; } + + /// + /// Initializes a new instance of the ErrorResponseException class. + /// + public ErrorResponseException() + { + } + + /// + /// Initializes a new instance of the ErrorResponseException class. + /// + /// The exception message. + public ErrorResponseException(string message) + : this(message, null) + { + } + + /// + /// Initializes a new instance of the ErrorResponseException class. + /// + /// The exception message. + /// Inner exception. + public ErrorResponseException(string message, System.Exception innerException) + : base(message, innerException) + { + } + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/GeographicResourceLocation.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/GeographicResourceLocation.cs new file mode 100644 index 0000000000000..ced9f789ad48d --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/GeographicResourceLocation.cs @@ -0,0 +1,28 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + + /// + /// Defines values for GeographicResourceLocation. + /// + public static class GeographicResourceLocation + { + /// + /// Used to access an Azure Maps Creator resource in the United States + /// + public const string Us = "us"; + /// + /// Used to access an Azure Maps Creator resource in Europe + /// + public const string Eu = "eu"; + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/IpAddressToLocationResult.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/IpAddressToLocationResult.cs new file mode 100644 index 0000000000000..467339cf5e573 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/Models/IpAddressToLocationResult.cs @@ -0,0 +1,58 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation.Models +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// This object is returned from a successful call to IP Address to + /// country/region API + /// + public partial class IpAddressToLocationResult + { + /// + /// Initializes a new instance of the IpAddressToLocationResult class. + /// + public IpAddressToLocationResult() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the IpAddressToLocationResult class. + /// + /// The IP Address of the request. + public IpAddressToLocationResult(CountryRegion countryRegion = default(CountryRegion), string ipAddress = default(string)) + { + CountryRegion = countryRegion; + IpAddress = ipAddress; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "countryRegion")] + public CountryRegion CountryRegion { get; set; } + + /// + /// Gets the IP Address of the request. + /// + [JsonProperty(PropertyName = "ipAddress")] + public string IpAddress { get; private set; } + + } +} diff --git a/sdk/maps/Azure.Maps.Geolocation/src/Generated/SdkInfo_GeolocationClient.cs b/sdk/maps/Azure.Maps.Geolocation/src/Generated/SdkInfo_GeolocationClient.cs new file mode 100644 index 0000000000000..245bc078cf267 --- /dev/null +++ b/sdk/maps/Azure.Maps.Geolocation/src/Generated/SdkInfo_GeolocationClient.cs @@ -0,0 +1,27 @@ + +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Maps.Geolocation +{ + using System; + using System.Collections.Generic; + using System.Linq; + + internal static partial class SdkInfo + { + public static IEnumerable> ApiInfo_GeolocationClient + { + get + { + return new Tuple[] + { + new Tuple("GeolocationClient", "Geolocation", "1.0"), + }.AsEnumerable(); + } + } + } +}