diff --git a/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs b/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
index c58c81e4e6b0c..8cadb3f6414f4 100644
--- a/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
+++ b/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
@@ -86,8 +86,11 @@ public void OutputToSingleFile()
};
string path = Path.Combine(settings.OutputDirectory, "test.file.cs");
+ string existingContents = "this is dummy";
+ _fileSystem.VirtualStore[path] = new StringBuilder(existingContents);
var codeGenerator = new SampleCodeGenerator(settings);
codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
+ Assert.DoesNotContain(existingContents, _fileSystem.VirtualStore[path].ToString());
Assert.Equal(4, _fileSystem.VirtualStore.Count);
Assert.True(_fileSystem.VirtualStore.ContainsKey(path));
Assert.True(_fileSystem.VirtualStore.ContainsKey("AutoRest.json"));
diff --git a/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs b/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
index 200dcfe018dfc..94dd5ffd7b726 100644
--- a/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
+++ b/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
@@ -25,6 +25,7 @@ public enum KnownPrimaryType
Boolean,
Credentials,
Uuid,
- Base64Url
+ Base64Url,
+ UnixTime
}
}
diff --git a/AutoRest/AutoRest.Core/CodeGenerator.cs b/AutoRest/AutoRest.Core/CodeGenerator.cs
index 8efb1c0311361..57dbecb697346 100644
--- a/AutoRest/AutoRest.Core/CodeGenerator.cs
+++ b/AutoRest/AutoRest.Core/CodeGenerator.cs
@@ -16,6 +16,7 @@ namespace Microsoft.Rest.Generator
public abstract class CodeGenerator
{
public const string EnumObject = "x-ms-enum";
+ private bool firstTimeWriteSingleFile = true;
protected CodeGenerator(Settings settings)
{
@@ -99,7 +100,7 @@ public async Task Write(ITemplate template, string fileName)
///
public async Task Write(string template, string fileName)
{
- string relativeFilePath = null;
+ string filePath = null;
if (Settings.OutputFileName != null)
{
@@ -110,17 +111,19 @@ public async Task Write(string template, string fileName)
ErrorManager.ThrowErrors();
}
- relativeFilePath = Settings.OutputFileName;
+ filePath = Path.Combine(Settings.OutputDirectory, Settings.OutputFileName);
+
+ if (firstTimeWriteSingleFile)
+ {
+ // for SingleFileGeneration clean the file before writing only if its the first time
+ Settings.FileSystem.DeleteFile(filePath);
+ firstTimeWriteSingleFile = false;
+ }
}
else
{
- relativeFilePath = fileName;
- }
- string filePath = Path.Combine(Settings.OutputDirectory, relativeFilePath);
-
- // cleans file before writing unless single file
- if (!(Settings.OutputFileName != null && IsSingleFileGenerationSupported))
- {
+ filePath = Path.Combine(Settings.OutputDirectory, fileName);
+ // cleans file before writing
Settings.FileSystem.DeleteFile(filePath);
}
// Make sure the directory exist
diff --git a/AutoRest/AutoRest.Core/Utilities/Extensions.cs b/AutoRest/AutoRest.Core/Utilities/Extensions.cs
index 23bea5173d9db..9a18e21f1f5b4 100644
--- a/AutoRest/AutoRest.Core/Utilities/Extensions.cs
+++ b/AutoRest/AutoRest.Core/Utilities/Extensions.cs
@@ -244,7 +244,7 @@ public static string EscapeXmlComment(this string comment)
}
///
- /// Returns true is the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
+ /// Returns true if the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
///
///
///
@@ -263,5 +263,54 @@ public static bool IsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
}
return false;
}
+
+ ///
+ /// Returns true if the is a PrimaryType with KnownPrimaryType matching
+ /// or a DictionaryType with ValueType matching or a SequenceType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsOrContainsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ if (type == null)
+ {
+ return false;
+ }
+
+ if (type.IsPrimaryType(typeToMatch) ||
+ type.IsDictionaryContainingType(typeToMatch) ||
+ type.IsSequenceContainingType(typeToMatch))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// Returns true if the is a DictionaryType with ValueType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsDictionaryContainingType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ DictionaryType dictionaryType = type as DictionaryType;
+ PrimaryType dictionaryPrimaryType = dictionaryType?.ValueType as PrimaryType;
+ return dictionaryPrimaryType != null && dictionaryPrimaryType.IsPrimaryType(typeToMatch);
+ }
+
+ ///
+ /// Returns true if the is a SequenceType matching
+ ///
+ ///
+ ///
+ ///
+ public static bool IsSequenceContainingType(this IType type, KnownPrimaryType typeToMatch)
+ {
+ SequenceType sequenceType = type as SequenceType;
+ PrimaryType sequencePrimaryType = sequenceType?.ElementType as PrimaryType;
+ return sequencePrimaryType != null && sequencePrimaryType.IsPrimaryType(typeToMatch);
+ }
}
}
\ No newline at end of file
diff --git a/AutoRest/AutoRest.Core/Utilities/FileSystem.cs b/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
index 91b4f6c18bdd0..13fab28c4cd4c 100644
--- a/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
+++ b/AutoRest/AutoRest.Core/Utilities/FileSystem.cs
@@ -3,6 +3,7 @@
using System.IO;
using System.Net;
+using System.Text;
namespace Microsoft.Rest.Generator.Utilities
{
@@ -10,13 +11,15 @@ public class FileSystem : IFileSystem
{
public void WriteFile(string path, string contents)
{
- File.WriteAllText(path, contents);
+ File.WriteAllText(path, contents, Encoding.UTF8);
}
public string ReadFileAsText(string path)
{
using (var client = new WebClient())
{
+ client.Headers.Add("User-Agent: AutoRest");
+ client.Encoding = Encoding.UTF8;
return client.DownloadString(path);
}
}
diff --git a/AutoRest/AutoRest/AutoRest.csproj b/AutoRest/AutoRest/AutoRest.csproj
index 8bd5ec84e97dd..7c578e0980acb 100644
--- a/AutoRest/AutoRest/AutoRest.csproj
+++ b/AutoRest/AutoRest/AutoRest.csproj
@@ -31,6 +31,7 @@
Properties\AssemblyVersionInfo.cs
+
@@ -70,4 +71,4 @@
-
+
\ No newline at end of file
diff --git a/AutoRest/AutoRest/ExitCode.cs b/AutoRest/AutoRest/ExitCode.cs
new file mode 100644
index 0000000000000..fe09a82b44c21
--- /dev/null
+++ b/AutoRest/AutoRest/ExitCode.cs
@@ -0,0 +1,14 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for license information.
+
+namespace Microsoft.Rest.Generator.Cli
+{
+ ///
+ /// Available exit codes.
+ ///
+ public enum ExitCode : int
+ {
+ Success = 0,
+ Error = 1
+ }
+}
diff --git a/AutoRest/AutoRest/Program.cs b/AutoRest/AutoRest/Program.cs
index b0c4aa7abea2b..f7bdf406b1066 100644
--- a/AutoRest/AutoRest/Program.cs
+++ b/AutoRest/AutoRest/Program.cs
@@ -12,8 +12,10 @@ namespace Microsoft.Rest.Generator.Cli
{
internal class Program
{
- private static void Main(string[] args)
+ private static int Main(string[] args)
{
+ int exitCode = (int)ExitCode.Error;
+
try
{
Settings settings = null;
@@ -69,6 +71,7 @@ private static void Main(string[] args)
{
Console.WriteLine(Resources.GenerationComplete,
settings.CodeGenerator, settings.Input);
+ exitCode = (int)ExitCode.Success;
}
}
@@ -91,6 +94,7 @@ private static void Main(string[] args)
Console.Error.WriteLine(Resources.ConsoleErrorMessage, exception.Message);
Console.Error.WriteLine(Resources.ConsoleErrorStackTrace, exception.StackTrace);
}
+ return exitCode;
}
///
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj
index 079278b9d781b..01522ea89f2b4 100644
--- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj
@@ -62,7 +62,9 @@
-
+
+ PreserveNewest
+
diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config
index 64fb5d7b3b792..4e690e09d9def 100644
--- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config
+++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/packages.config
@@ -1,10 +1,10 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
index d04c712fd1c96..6c254399697c3 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs
@@ -274,6 +274,10 @@ public void LroSadPathTests()
Assert.Equal("Error from the server", exception.Body.Message);
Assert.NotNull(exception.Request);
Assert.NotNull(exception.Response);
+ exception =
+ Assert.Throws(() => client.LROSADs.PutNonRetry201Creating400InvalidJson(new Product { Location = "West US" }));
+ Assert.Null(exception.Body);
+ Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message);
exception =
Assert.Throws(
() => client.LROSADs.PutAsyncRelativeRetry400(new Product {Location = "West US"}));
@@ -527,8 +531,7 @@ public void AzureODataTests()
Top = 10,
OrderBy = "id"
};
- var filterString = Uri.EscapeDataString("id gt 5 and name eq 'foo'");
- Assert.Equal(string.Format("$filter={0}&$orderby=id&$top=10", filterString), filter.ToString());
+ Assert.Equal("$filter=id gt 5 and name eq 'foo'&$orderby=id&$top=10", filter.ToString());
client.Odata.GetWithFilter(filter);
}
}
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
index 60ac71a045d3e..5717f7f8f64e8 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/ILROSADsOperations.cs
@@ -79,6 +79,34 @@ public partial interface ILROSADsOperations
///
Task> BeginPutNonRetry201Creating400WithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
/// Azure-AsyncOperation header for operation status
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
index 7b0662de0c29e..cbd54f78112ae 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperations.cs
@@ -453,6 +453,209 @@ internal LROSADsOperations(AutoRestLongRunningOperationTestService client)
return _result;
}
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public async Task> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Send Request
+ AzureOperationResponse _response = await BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(
+ product, customHeaders, cancellationToken);
+ return await this.Client.GetPutOrPatchOperationResultAsync(_response,
+ customHeaders,
+ cancellationToken);
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("product", product);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "BeginPutNonRetry201Creating400InvalidJson", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "lro/nonretryerror/put/201/creating/400/invalidjson").ToString();
+ List _queryParameters = new List();
+ if (_queryParameters.Count > 0)
+ {
+ _url += "?" + string.Join("&", _queryParameters);
+ }
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ if (this.Client.GenerateClientRequestId != null && this.Client.GenerateClientRequestId.Value)
+ {
+ _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Guid.NewGuid().ToString());
+ }
+ if (this.Client.AcceptLanguage != null)
+ {
+ if (_httpRequest.Headers.Contains("accept-language"))
+ {
+ _httpRequest.Headers.Remove("accept-language");
+ }
+ _httpRequest.Headers.TryAddWithoutValidation("accept-language", this.Client.AcceptLanguage);
+ }
+ 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;
+ if(product != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(product, this.Client.SerializationSettings);
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Set Credentials
+ if (this.Client.Credentials != null)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 && (int)_statusCode != 201)
+ {
+ var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ CloudError _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ if (_errorBody != null)
+ {
+ ex = new CloudException(_errorBody.Message);
+ ex.Body = _errorBody;
+ }
+ }
+ catch (JsonException)
+ {
+ // Ignore the exception
+ }
+ ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
+ ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
+ if (_httpResponse.Headers.Contains("x-ms-request-id"))
+ {
+ ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
+ }
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Error(_invocationId, ex);
+ }
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw ex;
+ }
+ // Create Result
+ var _result = new AzureOperationResponse();
+ _result.Request = _httpRequest;
+ _result.Response = _httpResponse;
+ if (_httpResponse.Headers.Contains("x-ms-request-id"))
+ {
+ _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
+ }
+ // Deserialize Response
+ if ((int)_statusCode == 200)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings);
+ }
+ catch (JsonException ex)
+ {
+ _httpRequest.Dispose();
+ if (_httpResponse != null)
+ {
+ _httpResponse.Dispose();
+ }
+ throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
+ }
+ }
+ // Deserialize Response
+ if ((int)_statusCode == 201)
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ try
+ {
+ _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.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;
+ }
+
///
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
index 86b6c1b083fc9..dc7d177cbe402 100644
--- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
+++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/Lro/LROSADsOperationsExtensions.cs
@@ -162,6 +162,78 @@ public static partial class LROSADsOperationsExtensions
}
}
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ public static Product PutNonRetry201Creating400InvalidJson(this ILROSADsOperations operations, Product product = default(Product))
+ {
+ return Task.Factory.StartNew(s => ((ILROSADsOperations)s).PutNonRetry201Creating400InvalidJsonAsync(product), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutNonRetry201Creating400InvalidJsonAsync(this ILROSADsOperations operations, Product product = default(Product), CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(product, null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ public static Product BeginPutNonRetry201Creating400InvalidJson(this ILROSADsOperations operations, Product product = default(Product))
+ {
+ return Task.Factory.StartNew(s => ((ILROSADsOperations)s).BeginPutNonRetry201Creating400InvalidJsonAsync(product), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Long running put request, service returns a Product with
+ /// 'ProvisioningState' = 'Creating' and 201 response code
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Product to put
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task BeginPutNonRetry201Creating400InvalidJsonAsync(this ILROSADsOperations operations, Product product = default(Product), CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(product, null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
///
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
index 0c6e31b1c1467..804db915e6111 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs
@@ -50,6 +50,7 @@
using Fixtures.PetstoreV2;
using Fixtures.AcceptanceTestsCompositeBoolIntClient;
using Fixtures.AcceptanceTestsCustomBaseUri;
+using Fixtures.AcceptanceTestsCustomBaseUriMoreOptions;
using System.Net.Http;
using Fixtures.AcceptanceTestsModelFlattening;
using Fixtures.AcceptanceTestsModelFlattening.Models;
@@ -197,12 +198,16 @@ public void IntegerTests()
client.IntModel.PutMin32(Int32.MinValue);
client.IntModel.PutMax64(Int64.MaxValue);
client.IntModel.PutMin64(Int64.MinValue);
+ client.IntModel.PutUnixTimeDate(new DateTime(2016, 4, 13, 0, 0, 0));
client.IntModel.GetNull();
Assert.Throws(() => client.IntModel.GetInvalid());
Assert.Throws(() => client.IntModel.GetOverflowInt32());
Assert.Throws(() => client.IntModel.GetOverflowInt64());
Assert.Throws(() => client.IntModel.GetUnderflowInt32());
Assert.Throws(() => client.IntModel.GetUnderflowInt64());
+ Assert.Throws(() => client.IntModel.GetInvalidUnixTime());
+ Assert.Null(client.IntModel.GetNullUnixTime());
+ Assert.Equal(new DateTime(2016, 4, 13, 0, 0, 0), client.IntModel.GetUnixTime());
}
[Fact]
@@ -1350,6 +1355,7 @@ public void UrlPathTests()
client.Paths.Base64Url(Encoding.UTF8.GetBytes("lorem"));
var testArray = new List { "ArrayPath1", @"begin!*'();:@ &=+$,/?#[]end", null, "" };
client.Paths.ArrayCsvInPath(testArray);
+ client.Paths.UnixTimeUrl(new DateTime(2016, 4, 13, 0, 0, 0));
}
}
@@ -1951,6 +1957,21 @@ public void CustomBaseUriTests()
}
}
+ [Fact]
+ public void CustomBaseUriMoreOptionsTests()
+ {
+ SwaggerSpecRunner.RunTests(
+ SwaggerPath("custom-baseUrl-more-options.json"), ExpectedPath("CustomBaseUriMoreOptions"));
+ using (var client = new AutoRestParameterizedCustomHostTestClient())
+ {
+ client.SubscriptionId = "test12";
+ // small modification to the "host" portion to include the port and the '.'
+ client.DnsSuffix = string.Format(CultureInfo.InvariantCulture, "{0}.:{1}", "host", Fixture.Port);
+ Assert.Equal(HttpStatusCode.OK,
+ client.Paths.GetEmptyWithHttpMessagesAsync("http://lo", "cal", "key1").Result.Response.StatusCode);
+ }
+ }
+
[Fact]
public void CustomBaseUriNegativeTests()
{
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
index 4b90323fef26b..7131504bb1855 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IIntModel.cs
@@ -129,5 +129,47 @@ public partial interface IIntModel
/// The cancellation token.
///
Task PutMin64WithHttpMessagesAsync(long intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
index feb0d3013f373..9c9b57ebbb2a4 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModel.cs
@@ -1202,5 +1202,472 @@ public IntModel(AutoRestIntegerTestService client)
return _result;
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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;
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("intBody", intBody);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "PutUnixTimeDate", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, new UnixTimeJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetInvalidUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/invalidunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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;
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetNullUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/nullunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
index 0c57e20b0aade..c0bc0812ebde8 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/BodyInteger/IntModelExtensions.cs
@@ -305,5 +305,118 @@ public static void PutMin64(this IIntModel operations, long intBody)
await operations.PutMin64WithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ public static void PutUnixTimeDate(this IIntModel operations, DateTime intBody)
+ {
+ Task.Factory.StartNew(s => ((IIntModel)s).PutUnixTimeDateAsync(intBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutUnixTimeDateAsync(this IIntModel operations, DateTime intBody, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.PutUnixTimeDateWithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetInvalidUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetInvalidUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetInvalidUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetInvalidUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetNullUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetNullUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetNullUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetNullUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
index 4917e355224d7..d0b518478669c 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IIntModel.cs
@@ -129,5 +129,47 @@ public partial interface IIntModel
/// The cancellation token.
///
Task PutMin64WithHttpMessagesAsync(long intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
index 1ed42f86ca54e..2047fd860871e 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModel.cs
@@ -1202,5 +1202,472 @@ public IntModel(CompositeBoolInt client)
return _result;
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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;
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task PutUnixTimeDateWithHttpMessagesAsync(DateTime intBody, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("intBody", intBody);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "PutUnixTimeDate", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/unixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("PUT");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ if(intBody != null)
+ {
+ _requestContent = SafeJsonConvert.SerializeObject(intBody, new UnixTimeJsonConverter());
+ _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
+ _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
+ }
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetInvalidUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetInvalidUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/invalidunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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;
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task> GetNullUnixTimeWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetNullUnixTime", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "int/nullunixtime").ToString();
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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 = SafeJsonConvert.DeserializeObject(_responseContent, new UnixTimeJsonConverter());
+ }
+ 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/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
index a203d3cee39e7..009277ea5077b 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/IntModelExtensions.cs
@@ -305,5 +305,118 @@ public static void PutMin64(this IIntModel operations, long intBody)
await operations.PutMin64WithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get datetime encoded as Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ public static void PutUnixTimeDate(this IIntModel operations, DateTime intBody)
+ {
+ Task.Factory.StartNew(s => ((IIntModel)s).PutUnixTimeDateAsync(intBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Put datetime encoded as Unix time
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task PutUnixTimeDateAsync(this IIntModel operations, DateTime intBody, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.PutUnixTimeDateWithHttpMessagesAsync(intBody, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetInvalidUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetInvalidUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get invalid Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetInvalidUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetInvalidUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ public static DateTime? GetNullUnixTime(this IIntModel operations)
+ {
+ return Task.Factory.StartNew(s => ((IIntModel)s).GetNullUnixTimeAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get null Unix time value
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetNullUnixTimeAsync(this IIntModel operations, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ using (var _result = await operations.GetNullUnixTimeWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
+ {
+ return _result.Body;
+ }
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs
new file mode 100644
index 0000000000000..e680cbe6a8731
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/AutoRestParameterizedCustomHostTestClient.cs
@@ -0,0 +1,128 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
+ using System.Text;
+ using System.Text.RegularExpressions;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+ using Newtonsoft.Json;
+ using Models;
+
+ ///
+ /// Test Infrastructure for AutoRest
+ ///
+ public partial class AutoRestParameterizedCustomHostTestClient : ServiceClient, IAutoRestParameterizedCustomHostTestClient
+ {
+ ///
+ /// 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; }
+
+ ///
+ /// The subscription id with value 'test12'.
+ ///
+ public string SubscriptionId { get; set; }
+
+ ///
+ /// A string value that is used as a global part of the parameterized host.
+ /// Default value 'host'.
+ ///
+ public string DnsSuffix { get; set; }
+
+ ///
+ /// Gets the IPaths.
+ ///
+ public virtual IPaths Paths { get; private set; }
+
+ ///
+ /// Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ ///
+ ///
+ /// Optional. The delegating handlers to add to the http client pipeline.
+ ///
+ public AutoRestParameterizedCustomHostTestClient(params DelegatingHandler[] handlers) : base(handlers)
+ {
+ this.Initialize();
+ }
+
+ ///
+ /// Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ ///
+ ///
+ /// Optional. The http client handler used to handle http transport.
+ ///
+ ///
+ /// Optional. The delegating handlers to add to the http client pipeline.
+ ///
+ public AutoRestParameterizedCustomHostTestClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers)
+ {
+ this.Initialize();
+ }
+
+ ///
+ /// An optional partial-method to perform custom initialization.
+ ///
+ partial void CustomInitialize();
+ ///
+ /// Initializes client properties.
+ ///
+ private void Initialize()
+ {
+ this.Paths = new Paths(this);
+ this.BaseUri = "{vault}{secret}{dnsSuffix}";
+ this.DnsSuffix = "host";
+ SerializationSettings = new JsonSerializerSettings
+ {
+ Formatting = Formatting.Indented,
+ DateFormatHandling = DateFormatHandling.IsoDateFormat,
+ DateTimeZoneHandling = DateTimeZoneHandling.Utc,
+ NullValueHandling = NullValueHandling.Ignore,
+ ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
+ ContractResolver = new ReadOnlyJsonContractResolver(),
+ Converters = new List
+ {
+ new Iso8601TimeSpanConverter()
+ }
+ };
+ DeserializationSettings = new JsonSerializerSettings
+ {
+ DateFormatHandling = DateFormatHandling.IsoDateFormat,
+ DateTimeZoneHandling = DateTimeZoneHandling.Utc,
+ NullValueHandling = NullValueHandling.Ignore,
+ ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
+ ContractResolver = new ReadOnlyJsonContractResolver(),
+ Converters = new List
+ {
+ new Iso8601TimeSpanConverter()
+ }
+ };
+ CustomInitialize();
+ }
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs
new file mode 100644
index 0000000000000..87db999d81c42
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IAutoRestParameterizedCustomHostTestClient.cs
@@ -0,0 +1,57 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Newtonsoft.Json;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Test Infrastructure for AutoRest
+ ///
+ public partial interface IAutoRestParameterizedCustomHostTestClient : 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; }
+
+ ///
+ /// The subscription id with value 'test12'.
+ ///
+ string SubscriptionId { get; set; }
+
+ ///
+ /// A string value that is used as a global part of the parameterized
+ /// host. Default value 'host'.
+ ///
+ string DnsSuffix { get; set; }
+
+
+ ///
+ /// Gets the IPaths.
+ ///
+ IPaths Paths { get; }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs
new file mode 100644
index 0000000000000..a117b914e7526
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/IPaths.cs
@@ -0,0 +1,47 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Paths operations.
+ ///
+ public partial interface IPaths
+ {
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task GetEmptyWithHttpMessagesAsync(string vault, string secret, string keyName, string keyVersion = "v1", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs
new file mode 100644
index 0000000000000..82a4873e61389
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/Error.cs
@@ -0,0 +1,45 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions.Models
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using Newtonsoft.Json;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+
+ public partial class Error
+ {
+ ///
+ /// Initializes a new instance of the Error class.
+ ///
+ public Error() { }
+
+ ///
+ /// Initializes a new instance of the Error class.
+ ///
+ public Error(int? status = default(int?), string message = default(string))
+ {
+ Status = status;
+ Message = message;
+ }
+
+ ///
+ ///
+ [JsonProperty(PropertyName = "status")]
+ public int? Status { get; set; }
+
+ ///
+ ///
+ [JsonProperty(PropertyName = "message")]
+ public string Message { get; set; }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs
new file mode 100644
index 0000000000000..e3ab1c0a08abc
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Models/ErrorException.cs
@@ -0,0 +1,99 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions.Models
+{
+ using Microsoft.Rest;
+ using System;
+ using System.Net.Http;
+ using System.Runtime.Serialization;
+#if !PORTABLE && !DNXCORE50
+ using System.Security.Permissions;
+#endif
+
+ ///
+ /// Exception thrown for an invalid response with Error information.
+ ///
+#if !PORTABLE && !DNXCORE50
+ [Serializable]
+#endif
+ public class ErrorException : 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 Error Body { get; set; }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ public ErrorException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// The exception message.
+ public ErrorException(string message)
+ : this(message, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// The exception message.
+ /// Inner exception.
+ public ErrorException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+#if !PORTABLE && !DNXCORE50
+ ///
+ /// Initializes a new instance of the ErrorException class.
+ ///
+ /// Serialization info.
+ /// Streaming context.
+ protected ErrorException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ ///
+ /// Serializes content of the exception.
+ ///
+ /// Serialization info.
+ /// Streaming context.
+ [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ if (info == null)
+ {
+ throw new ArgumentNullException("info");
+ }
+
+ info.AddValue("Request", Request);
+ info.AddValue("Response", Response);
+ info.AddValue("Body", Body);
+ }
+#endif
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs
new file mode 100644
index 0000000000000..a8599cf083382
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/Paths.cs
@@ -0,0 +1,203 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
+ using System.Text;
+ using System.Text.RegularExpressions;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Microsoft.Rest.Serialization;
+ using Newtonsoft.Json;
+ using Models;
+
+ ///
+ /// Paths operations.
+ ///
+ public partial class Paths : IServiceOperations, IPaths
+ {
+ ///
+ /// Initializes a new instance of the Paths class.
+ ///
+ ///
+ /// Reference to the service client.
+ ///
+ public Paths(AutoRestParameterizedCustomHostTestClient client)
+ {
+ if (client == null)
+ {
+ throw new ArgumentNullException("client");
+ }
+ this.Client = client;
+ }
+
+ ///
+ /// Gets a reference to the AutoRestParameterizedCustomHostTestClient
+ ///
+ public AutoRestParameterizedCustomHostTestClient Client { get; private set; }
+
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task GetEmptyWithHttpMessagesAsync(string vault, string secret, string keyName, string keyVersion = "v1", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ if (vault == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "vault");
+ }
+ if (secret == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "secret");
+ }
+ if (this.Client.DnsSuffix == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.DnsSuffix");
+ }
+ if (keyName == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "keyName");
+ }
+ if (this.Client.SubscriptionId == null)
+ {
+ throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
+ }
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("vault", vault);
+ tracingParameters.Add("secret", secret);
+ tracingParameters.Add("keyName", keyName);
+ tracingParameters.Add("keyVersion", keyVersion);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "GetEmpty", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri;
+ var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "customuri/{subscriptionId}/{keyName}";
+ _url = _url.Replace("{vault}", vault);
+ _url = _url.Replace("{secret}", secret);
+ _url = _url.Replace("{dnsSuffix}", this.Client.DnsSuffix);
+ _url = _url.Replace("{keyName}", Uri.EscapeDataString(keyName));
+ _url = _url.Replace("{subscriptionId}", Uri.EscapeDataString(this.Client.SubscriptionId));
+ List _queryParameters = new List();
+ if (keyVersion != null)
+ {
+ _queryParameters.Add(string.Format("keyVersion={0}", Uri.EscapeDataString(keyVersion)));
+ }
+ if (_queryParameters.Count > 0)
+ {
+ _url += "?" + string.Join("&", _queryParameters);
+ }
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs
new file mode 100644
index 0000000000000..c553414304ed0
--- /dev/null
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/PathsExtensions.cs
@@ -0,0 +1,74 @@
+// 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 Fixtures.AcceptanceTestsCustomBaseUriMoreOptions
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.Rest;
+ using Models;
+
+ ///
+ /// Extension methods for Paths.
+ ///
+ public static partial class PathsExtensions
+ {
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ public static void GetEmpty(this IPaths operations, string vault, string secret, string keyName, string keyVersion = "v1")
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).GetEmptyAsync(vault, secret, keyName, keyVersion), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get a 200 to test a valid base uri
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// The vault name, e.g. https://myvault
+ ///
+ ///
+ /// Secret value.
+ ///
+ ///
+ /// The key name with value 'key1'.
+ ///
+ ///
+ /// The key version. Default value 'v1'.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task GetEmptyAsync(this IPaths operations, string vault, string secret, string keyName, string keyVersion = "v1", CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.GetEmptyWithHttpMessagesAsync(vault, secret, keyName, keyVersion, null, cancellationToken).ConfigureAwait(false);
+ }
+
+ }
+}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
index ce60b9a5c2f28..d8f9e2c761579 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs
@@ -305,5 +305,18 @@ public partial interface IPaths
/// The cancellation token.
///
Task ArrayCsvInPathWithHttpMessagesAsync(IList arrayPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// The headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
index d880804521f0c..3892f728ba11b 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs
@@ -2692,5 +2692,111 @@ public Paths(AutoRestUrlTestService client)
return _result;
}
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// Headers that will be added to request.
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ /// A response object containing the response body and response headers.
+ ///
+ public async Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ // Tracing
+ bool _shouldTrace = ServiceClientTracing.IsEnabled;
+ string _invocationId = null;
+ if (_shouldTrace)
+ {
+ _invocationId = ServiceClientTracing.NextInvocationId.ToString();
+ Dictionary tracingParameters = new Dictionary();
+ tracingParameters.Add("unixTimeUrlPath", unixTimeUrlPath);
+ tracingParameters.Add("cancellationToken", cancellationToken);
+ ServiceClientTracing.Enter(_invocationId, this, "UnixTimeUrl", tracingParameters);
+ }
+ // Construct URL
+ var _baseUrl = this.Client.BaseUri.AbsoluteUri;
+ var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "paths/int/1460505600/{unixTimeUrlPath}").ToString();
+ _url = _url.Replace("{unixTimeUrlPath}", Uri.EscapeDataString(SafeJsonConvert.SerializeObject(unixTimeUrlPath, new UnixTimeJsonConverter()).Trim('"')));
+ // Create HTTP transport objects
+ HttpRequestMessage _httpRequest = new HttpRequestMessage();
+ HttpResponseMessage _httpResponse = null;
+ _httpRequest.Method = new HttpMethod("GET");
+ _httpRequest.RequestUri = new Uri(_url);
+ // Set Headers
+ 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;
+ // Send Request
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
+ }
+ cancellationToken.ThrowIfCancellationRequested();
+ _httpResponse = await this.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 ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
+ try
+ {
+ _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.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;
+ if (_shouldTrace)
+ {
+ ServiceClientTracing.Exit(_invocationId, _result);
+ }
+ return _result;
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
index 65ea07ea61b8b..b4e8d2ce268e6 100644
--- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs
@@ -712,5 +712,36 @@ public static void ArrayCsvInPath(this IPaths operations, IList arrayPat
await operations.ArrayCsvInPathWithHttpMessagesAsync(arrayPath, null, cancellationToken).ConfigureAwait(false);
}
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ public static void UnixTimeUrl(this IPaths operations, DateTime unixTimeUrlPath)
+ {
+ Task.Factory.StartNew(s => ((IPaths)s).UnixTimeUrlAsync(unixTimeUrlPath), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
+ ///
+ ///
+ /// The operations group for this extension method.
+ ///
+ ///
+ /// Unix time encoded value
+ ///
+ ///
+ /// The cancellation token.
+ ///
+ public static async Task UnixTimeUrlAsync(this IPaths operations, DateTime unixTimeUrlPath, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ await operations.UnixTimeUrlWithHttpMessagesAsync(unixTimeUrlPath, null, cancellationToken).ConfigureAwait(false);
+ }
+
}
}
diff --git a/AutoRest/Generators/CSharp/CSharp/CSharpCodeNamer.cs b/AutoRest/Generators/CSharp/CSharp/CSharpCodeNamer.cs
index d9562cf4ca63c..3504b01cb57d2 100644
--- a/AutoRest/Generators/CSharp/CSharp/CSharpCodeNamer.cs
+++ b/AutoRest/Generators/CSharp/CSharp/CSharpCodeNamer.cs
@@ -297,6 +297,10 @@ protected virtual IType NormalizePrimaryType(PrimaryType primaryType)
{
primaryType.Name = "ServiceClientCredentials";
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ primaryType.Name = "DateTime";
+ }
else if (primaryType.Type == KnownPrimaryType.Uuid)
{
primaryType.Name = "Guid";
@@ -401,7 +405,8 @@ public override string EscapeDefaultValue(string defaultValue, IType type)
primaryType.Type == KnownPrimaryType.DateTimeRfc1123 ||
primaryType.Type == KnownPrimaryType.TimeSpan ||
primaryType.Type == KnownPrimaryType.ByteArray ||
- primaryType.Type == KnownPrimaryType.Base64Url)
+ primaryType.Type == KnownPrimaryType.Base64Url ||
+ primaryType.Type == KnownPrimaryType.UnixTime)
{
return "SafeJsonConvert.DeserializeObject<" + primaryType.Name.TrimEnd('?') +
diff --git a/AutoRest/Generators/CSharp/CSharp/ClientModelExtensions.cs b/AutoRest/Generators/CSharp/CSharp/ClientModelExtensions.cs
index ded2055e683be..ae4d9f11159de 100644
--- a/AutoRest/Generators/CSharp/CSharp/ClientModelExtensions.cs
+++ b/AutoRest/Generators/CSharp/CSharp/ClientModelExtensions.cs
@@ -225,6 +225,10 @@ public static string ToString(this IType type, string clientReference, string re
{
serializationSettings = "new Base64UrlJsonConverter()";
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ serializationSettings = "new UnixTimeJsonConverter()";
+ }
}
return string.Format(CultureInfo.InvariantCulture,
@@ -268,6 +272,7 @@ public static bool IsValueType(this IType type)
|| primaryType.Type == KnownPrimaryType.Long
|| primaryType.Type == KnownPrimaryType.TimeSpan
|| primaryType.Type == KnownPrimaryType.DateTimeRfc1123
+ || primaryType.Type == KnownPrimaryType.UnixTime
|| primaryType.Type == KnownPrimaryType.Uuid));
}
diff --git a/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs b/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs
index cc44708181ecf..22d1ca54614d0 100644
--- a/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs
+++ b/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs
@@ -325,32 +325,22 @@ public string ClientReference
///
public string GetSerializationSettingsReference(IType serializationType)
{
- SequenceType sequenceType = serializationType as SequenceType;
- DictionaryType dictionaryType = serializationType as DictionaryType;
- if (serializationType.IsPrimaryType(KnownPrimaryType.Date) ||
- (sequenceType != null && sequenceType.ElementType is PrimaryType
- && ((PrimaryType)sequenceType.ElementType).Type == KnownPrimaryType.Date) ||
- (dictionaryType != null && dictionaryType.ValueType is PrimaryType
- && ((PrimaryType)dictionaryType.ValueType).Type == KnownPrimaryType.Date))
+ if (serializationType.IsOrContainsPrimaryType(KnownPrimaryType.Date))
{
return "new DateJsonConverter()";
}
- else if (serializationType.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123) ||
- (sequenceType != null && sequenceType.ElementType is PrimaryType
- && ((PrimaryType)sequenceType.ElementType).Type == KnownPrimaryType.DateTimeRfc1123) ||
- (dictionaryType != null && dictionaryType.ValueType is PrimaryType
- && ((PrimaryType)dictionaryType.ValueType).Type == KnownPrimaryType.DateTimeRfc1123))
+ else if (serializationType.IsOrContainsPrimaryType(KnownPrimaryType.DateTimeRfc1123))
{
return "new DateTimeRfc1123JsonConverter()";
}
- else if (serializationType.IsPrimaryType(KnownPrimaryType.Base64Url) ||
- (sequenceType != null && sequenceType.ElementType is PrimaryType
- && ((PrimaryType)sequenceType.ElementType).Type == KnownPrimaryType.Base64Url) ||
- (dictionaryType != null && dictionaryType.ValueType is PrimaryType
- && ((PrimaryType)dictionaryType.ValueType).Type == KnownPrimaryType.Base64Url))
+ else if (serializationType.IsOrContainsPrimaryType(KnownPrimaryType.Base64Url))
{
return "new Base64UrlJsonConverter()";
}
+ else if (serializationType.IsOrContainsPrimaryType(KnownPrimaryType.UnixTime))
+ {
+ return "new UnixTimeJsonConverter()";
+ }
return ClientReference + ".SerializationSettings";
}
@@ -361,25 +351,18 @@ public string GetSerializationSettingsReference(IType serializationType)
///
public string GetDeserializationSettingsReference(IType deserializationType)
{
- SequenceType sequenceType = deserializationType as SequenceType;
- DictionaryType dictionaryType = deserializationType as DictionaryType;
- if (deserializationType.IsPrimaryType(KnownPrimaryType.Date) ||
- (sequenceType != null && sequenceType.ElementType is PrimaryType
- && ((PrimaryType)sequenceType.ElementType).Type == KnownPrimaryType.Date) ||
- (dictionaryType != null && dictionaryType.ValueType is PrimaryType
- && ((PrimaryType)dictionaryType.ValueType).Type == KnownPrimaryType.Date))
+ if (deserializationType.IsOrContainsPrimaryType(KnownPrimaryType.Date))
{
return "new DateJsonConverter()";
}
- if (deserializationType.IsPrimaryType(KnownPrimaryType.Base64Url) ||
- (sequenceType != null && sequenceType.ElementType is PrimaryType
- && ((PrimaryType)sequenceType.ElementType).Type == KnownPrimaryType.Base64Url) ||
- (dictionaryType != null && dictionaryType.ValueType is PrimaryType
- && ((PrimaryType)dictionaryType.ValueType).Type == KnownPrimaryType.Base64Url))
+ else if (deserializationType.IsOrContainsPrimaryType(KnownPrimaryType.Base64Url))
{
return "new Base64UrlJsonConverter()";
}
-
+ else if (deserializationType.IsOrContainsPrimaryType(KnownPrimaryType.UnixTime))
+ {
+ return "new UnixTimeJsonConverter()";
+ }
return ClientReference + ".DeserializationSettings";
}
diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml
index 2bcf9676f0951..942e67ef809e3 100644
--- a/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml
+++ b/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml
@@ -123,6 +123,10 @@ namespace @(Settings.Namespace).Models
{
@:[JsonConverter(typeof(Base64UrlJsonConverter))]
}
+ if (property.Type.IsPrimaryType(KnownPrimaryType.UnixTime))
+ {
+ @:[JsonConverter(typeof(UnixTimeJsonConverter))]
+ }
@:[JsonProperty(PropertyName = "@property.SerializedName")]
@:public @property.Type.Name @property.Name { get; @(property.IsReadOnly ? "private " : "")set; }
@EmptyLine
@@ -145,6 +149,10 @@ namespace @(Settings.Namespace).Models
{
@:[JsonConverter(typeof(Base64UrlJsonConverter))]
}
+ if (property.Type.IsPrimaryType(KnownPrimaryType.UnixTime))
+ {
+ @:[JsonConverter(typeof(UnixTimeJsonConverter))]
+ }
@:[JsonProperty(PropertyName = "@property.SerializedName")]
@:public static @property.Type.Name @property.Name { get; private set; }
@EmptyLine
diff --git a/AutoRest/Generators/Extensions/Extensions/Extensions.cs b/AutoRest/Generators/Extensions/Extensions/Extensions.cs
index e974d9563af25..620a2d594c83e 100644
--- a/AutoRest/Generators/Extensions/Extensions/Extensions.cs
+++ b/AutoRest/Generators/Extensions/Extensions/Extensions.cs
@@ -12,6 +12,8 @@
using Microsoft.Rest.Modeler.Swagger.Model;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
+using System.Text.RegularExpressions;
+using Microsoft.Rest.Generator.Properties;
namespace Microsoft.Rest.Generator
{
@@ -27,6 +29,8 @@ public abstract class Extensions
public const string FlattenOriginalTypeName = "x-ms-client-flatten-original-type-name";
public const string ParameterGroupExtension = "x-ms-parameter-grouping";
public const string ParameterizedHostExtension = "x-ms-parameterized-host";
+ public const string UseSchemePrefix = "useSchemePrefix";
+ public const string PositionInOperation = "positionInOperation";
private static bool hostChecked = false;
@@ -67,6 +71,28 @@ public static void ProcessParameterizedHost(ServiceClient serviceClient, Setting
{
var hostTemplate = (string)hostExtension["hostTemplate"];
var parametersJson = hostExtension["parameters"].ToString();
+ var useSchemePrefix = true;
+ if (hostExtension[UseSchemePrefix] != null)
+ {
+ useSchemePrefix = bool.Parse(hostExtension[UseSchemePrefix].ToString());
+ }
+
+ var position = "first";
+
+ if (hostExtension[PositionInOperation] != null)
+ {
+ var pat = "^(fir|la)st$";
+ Regex r = new Regex(pat, RegexOptions.IgnoreCase);
+ var text = hostExtension[PositionInOperation].ToString();
+ Match m = r.Match(text);
+ if (!m.Success)
+ {
+ throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
+ Resources.InvalidExtensionProperty, text, PositionInOperation, ParameterizedHostExtension, "first, last"));
+ }
+ position = text;
+ }
+
if (!string.IsNullOrEmpty(parametersJson))
{
var jsonSettings = new JsonSerializerSettings
@@ -76,7 +102,7 @@ public static void ProcessParameterizedHost(ServiceClient serviceClient, Setting
};
var swaggerParams = JsonConvert.DeserializeObject>(parametersJson, jsonSettings);
-
+ List hostParamList = new List();
foreach (var swaggerParameter in swaggerParams)
{
// Build parameter
@@ -89,16 +115,33 @@ public static void ProcessParameterizedHost(ServiceClient serviceClient, Setting
parameter.ClientProperty = serviceClient.Properties.Single(p => p.SerializedName.Equals(parameter.SerializedName));
}
parameter.Extensions["hostParameter"] = true;
+ hostParamList.Add(parameter);
+ }
- foreach (var method in serviceClient.Methods)
+ foreach (var method in serviceClient.Methods)
+ {
+ if (position.Equals("first", StringComparison.OrdinalIgnoreCase))
{
- method.Parameters.Add(parameter);
+ method.Parameters.InsertRange(0, hostParamList);
}
+ else
+ {
+ method.Parameters.AddRange(hostParamList);
+ }
+
}
-
- serviceClient.BaseUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}{2}",
- modeler.ServiceDefinition.Schemes[0].ToString().ToLowerInvariant(),
- hostTemplate, modeler.ServiceDefinition.BasePath);
+ if (useSchemePrefix)
+ {
+ serviceClient.BaseUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}{2}",
+ modeler.ServiceDefinition.Schemes[0].ToString().ToLowerInvariant(),
+ hostTemplate, modeler.ServiceDefinition.BasePath);
+ }
+ else
+ {
+ serviceClient.BaseUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}",
+ hostTemplate, modeler.ServiceDefinition.BasePath);
+ }
+
}
}
}
diff --git a/AutoRest/Generators/Extensions/Extensions/Properties/Resources.Designer.cs b/AutoRest/Generators/Extensions/Extensions/Properties/Resources.Designer.cs
index 689a601b826f3..f98e2ea0b022c 100644
--- a/AutoRest/Generators/Extensions/Extensions/Properties/Resources.Designer.cs
+++ b/AutoRest/Generators/Extensions/Extensions/Properties/Resources.Designer.cs
@@ -69,6 +69,15 @@ internal static string HeadMethodInvalidResponses {
}
}
+ ///
+ /// Looks up a localized string similar to The value '{0}' provided for property '{1}' of extension '{2} is invalid. Valid values are: '{3}'..
+ ///
+ internal static string InvalidExtensionProperty {
+ get {
+ return ResourceManager.GetString("InvalidExtensionProperty", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Azure resource {0} is missing required 'properties' property..
///
diff --git a/AutoRest/Generators/Extensions/Extensions/Properties/Resources.resx b/AutoRest/Generators/Extensions/Extensions/Properties/Resources.resx
index d06a580a716fe..7df584f0a47aa 100644
--- a/AutoRest/Generators/Extensions/Extensions/Properties/Resources.resx
+++ b/AutoRest/Generators/Extensions/Extensions/Properties/Resources.resx
@@ -120,6 +120,9 @@
Head method '{0}' should contain only 200 level responses, or 404.
+
+ The value '{0}' provided for property '{1}' of extension '{2} is invalid. Valid values are: '{3}'.
+
Azure resource {0} is missing required 'properties' property.
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClient.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClient.java
new file mode 100644
index 0000000000000..7c5bb29be05d4
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClient.java
@@ -0,0 +1,86 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions;
+
+import java.util.List;
+import okhttp3.Interceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+import com.microsoft.rest.AutoRestBaseUrl;
+import com.microsoft.rest.serializer.JacksonMapperAdapter;
+
+/**
+ * The interface for AutoRestParameterizedCustomHostTestClient class.
+ */
+public interface AutoRestParameterizedCustomHostTestClient {
+ /**
+ * Gets the URL used as the base for all cloud service requests.
+ *
+ * @return the BaseUrl object.
+ */
+ AutoRestBaseUrl getBaseUrl();
+
+ /**
+ * Gets the list of interceptors the OkHttp client will execute.
+ *
+ * @return the list of interceptors.
+ */
+ List getClientInterceptors();
+
+ /**
+ * Sets the logging level for OkHttp client.
+ *
+ * @param logLevel the logging level enum.
+ */
+ void setLogLevel(Level logLevel);
+
+ /**
+ * Gets the adapter for {@link com.fasterxml.jackson.databind.ObjectMapper} for serialization
+ * and deserialization operations..
+ *
+ * @return the adapter.
+ */
+ JacksonMapperAdapter getMapperAdapter();
+
+ /**
+ * Gets The subscription id with value 'test12'..
+ *
+ * @return the subscriptionId value.
+ */
+ String getSubscriptionId();
+
+ /**
+ * Sets The subscription id with value 'test12'..
+ *
+ * @param subscriptionId the subscriptionId value.
+ */
+ void setSubscriptionId(String subscriptionId);
+
+ /**
+ * Gets A string value that is used as a global part of the parameterized host. Default value 'host'..
+ *
+ * @return the dnsSuffix value.
+ */
+ String getDnsSuffix();
+
+ /**
+ * Sets A string value that is used as a global part of the parameterized host. Default value 'host'..
+ *
+ * @param dnsSuffix the dnsSuffix value.
+ */
+ void setDnsSuffix(String dnsSuffix);
+
+ /**
+ * Gets the PathsOperations object to access its operations.
+ * @return the PathsOperations object.
+ */
+ PathsOperations getPathsOperations();
+
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClientImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClientImpl.java
new file mode 100644
index 0000000000000..ad9fe946dc423
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/AutoRestParameterizedCustomHostTestClientImpl.java
@@ -0,0 +1,121 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions;
+
+import com.microsoft.rest.ServiceClient;
+import com.microsoft.rest.AutoRestBaseUrl;
+import okhttp3.OkHttpClient;
+import retrofit2.Retrofit;
+
+/**
+ * Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ */
+public final class AutoRestParameterizedCustomHostTestClientImpl extends ServiceClient implements AutoRestParameterizedCustomHostTestClient {
+ /**
+ * The URL used as the base for all cloud service requests.
+ */
+ private final AutoRestBaseUrl baseUrl;
+
+ /**
+ * Gets the URL used as the base for all cloud service requests.
+ *
+ * @return The BaseUrl value.
+ */
+ public AutoRestBaseUrl getBaseUrl() {
+ return this.baseUrl;
+ }
+
+ /** The subscription id with value 'test12'. */
+ private String subscriptionId;
+
+ /**
+ * Gets The subscription id with value 'test12'.
+ *
+ * @return the subscriptionId value.
+ */
+ public String getSubscriptionId() {
+ return this.subscriptionId;
+ }
+
+ /**
+ * Sets The subscription id with value 'test12'.
+ *
+ * @param subscriptionId the subscriptionId value.
+ */
+ public void setSubscriptionId(String subscriptionId) {
+ this.subscriptionId = subscriptionId;
+ }
+
+ /** A string value that is used as a global part of the parameterized host. Default value 'host'. */
+ private String dnsSuffix;
+
+ /**
+ * Gets A string value that is used as a global part of the parameterized host. Default value 'host'.
+ *
+ * @return the dnsSuffix value.
+ */
+ public String getDnsSuffix() {
+ return this.dnsSuffix;
+ }
+
+ /**
+ * Sets A string value that is used as a global part of the parameterized host. Default value 'host'.
+ *
+ * @param dnsSuffix the dnsSuffix value.
+ */
+ public void setDnsSuffix(String dnsSuffix) {
+ this.dnsSuffix = dnsSuffix;
+ }
+
+ /**
+ * Gets the PathsOperations object to access its operations.
+ * @return the PathsOperations object.
+ */
+ public PathsOperations getPathsOperations() {
+ return new PathsOperationsImpl(this.retrofitBuilder.client(clientBuilder.build()).build(), this);
+ }
+
+ /**
+ * Initializes an instance of AutoRestParameterizedCustomHostTestClient client.
+ */
+ public AutoRestParameterizedCustomHostTestClientImpl() {
+ this("{vault}{secret}{dnsSuffix}");
+ }
+
+ /**
+ * Initializes an instance of AutoRestParameterizedCustomHostTestClient client.
+ *
+ * @param baseUrl the base URL of the host
+ */
+ private AutoRestParameterizedCustomHostTestClientImpl(String baseUrl) {
+ super();
+ this.baseUrl = new AutoRestBaseUrl(baseUrl);
+ initialize();
+ }
+
+ /**
+ * Initializes an instance of AutoRestParameterizedCustomHostTestClient client.
+ *
+ * @param clientBuilder the builder for building up an {@link OkHttpClient}
+ * @param retrofitBuilder the builder for building up a {@link Retrofit}
+ */
+ public AutoRestParameterizedCustomHostTestClientImpl(OkHttpClient.Builder clientBuilder, Retrofit.Builder retrofitBuilder) {
+ super(clientBuilder, retrofitBuilder);
+ this.baseUrl = new AutoRestBaseUrl("{vault}{secret}{dnsSuffix}");
+ initialize();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.retrofitBuilder.baseUrl(baseUrl);
+ }
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperations.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperations.java
new file mode 100644
index 0000000000000..6273f3426d73c
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperations.java
@@ -0,0 +1,75 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions;
+
+import com.microsoft.rest.ServiceCall;
+import com.microsoft.rest.ServiceCallback;
+import com.microsoft.rest.ServiceResponse;
+import fixtures.custombaseurimoreoptions.models.ErrorException;
+import java.io.IOException;
+
+/**
+ * An instance of this class provides access to all the operations defined
+ * in PathsOperations.
+ */
+public interface PathsOperations {
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @throws ErrorException exception thrown from REST call
+ * @throws IOException exception thrown from serialization/deserialization
+ * @throws IllegalArgumentException exception thrown from invalid parameters
+ * @return the {@link ServiceResponse} object if successful.
+ */
+ ServiceResponse getEmpty(String vault, String secret, String keyName) throws ErrorException, IOException, IllegalArgumentException;
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if callback is null
+ * @return the {@link ServiceCall} object
+ */
+ ServiceCall getEmptyAsync(String vault, String secret, String keyName, final ServiceCallback serviceCallback) throws IllegalArgumentException;
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param keyVersion The key version. Default value 'v1'.
+ * @throws ErrorException exception thrown from REST call
+ * @throws IOException exception thrown from serialization/deserialization
+ * @throws IllegalArgumentException exception thrown from invalid parameters
+ * @return the {@link ServiceResponse} object if successful.
+ */
+ ServiceResponse getEmpty(String vault, String secret, String keyName, String keyVersion) throws ErrorException, IOException, IllegalArgumentException;
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param keyVersion The key version. Default value 'v1'.
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if callback is null
+ * @return the {@link ServiceCall} object
+ */
+ ServiceCall getEmptyAsync(String vault, String secret, String keyName, String keyVersion, final ServiceCallback serviceCallback) throws IllegalArgumentException;
+
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperationsImpl.java
new file mode 100644
index 0000000000000..13994720257bd
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/PathsOperationsImpl.java
@@ -0,0 +1,245 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions;
+
+import com.google.common.reflect.TypeToken;
+import com.microsoft.rest.ServiceCall;
+import com.microsoft.rest.ServiceCallback;
+import com.microsoft.rest.ServiceResponse;
+import com.microsoft.rest.ServiceResponseBuilder;
+import com.microsoft.rest.ServiceResponseCallback;
+import fixtures.custombaseurimoreoptions.models.ErrorException;
+import java.io.IOException;
+import okhttp3.ResponseBody;
+import retrofit2.Call;
+import retrofit2.http.GET;
+import retrofit2.http.Headers;
+import retrofit2.http.Path;
+import retrofit2.http.Query;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+/**
+ * An instance of this class provides access to all the operations defined
+ * in PathsOperations.
+ */
+public final class PathsOperationsImpl implements PathsOperations {
+ /** The Retrofit service to perform REST calls. */
+ private PathsService service;
+ /** The service client containing this operation class. */
+ private AutoRestParameterizedCustomHostTestClient client;
+
+ /**
+ * Initializes an instance of PathsOperations.
+ *
+ * @param retrofit the Retrofit instance built from a Retrofit Builder.
+ * @param client the instance of the service client containing this operation class.
+ */
+ public PathsOperationsImpl(Retrofit retrofit, AutoRestParameterizedCustomHostTestClient client) {
+ this.service = retrofit.create(PathsService.class);
+ this.client = client;
+ }
+
+ /**
+ * The interface defining all the services for PathsOperations to be
+ * used by Retrofit to perform actually REST calls.
+ */
+ interface PathsService {
+ @Headers("Content-Type: application/json; charset=utf-8")
+ @GET("customuri/{subscriptionId}/{keyName}")
+ Call getEmpty(@Path("keyName") String keyName, @Path("subscriptionId") String subscriptionId, @Query("keyVersion") String keyVersion);
+
+ }
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @throws ErrorException exception thrown from REST call
+ * @throws IOException exception thrown from serialization/deserialization
+ * @throws IllegalArgumentException exception thrown from invalid parameters
+ * @return the {@link ServiceResponse} object if successful.
+ */
+ public ServiceResponse getEmpty(String vault, String secret, String keyName) throws ErrorException, IOException, IllegalArgumentException {
+ if (vault == null) {
+ throw new IllegalArgumentException("Parameter vault is required and cannot be null.");
+ }
+ if (secret == null) {
+ throw new IllegalArgumentException("Parameter secret is required and cannot be null.");
+ }
+ if (this.client.getDnsSuffix() == null) {
+ throw new IllegalArgumentException("Parameter this.client.getDnsSuffix() is required and cannot be null.");
+ }
+ if (keyName == null) {
+ throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
+ }
+ if (this.client.getSubscriptionId() == null) {
+ throw new IllegalArgumentException("Parameter this.client.getSubscriptionId() is required and cannot be null.");
+ }
+ final String keyVersion = null;
+ this.client.getBaseUrl().set("{vault}", vault);
+ this.client.getBaseUrl().set("{secret}", secret);
+ this.client.getBaseUrl().set("{dnsSuffix}", this.client.getDnsSuffix());
+ Call call = service.getEmpty(keyName, this.client.getSubscriptionId(), keyVersion);
+ return getEmptyDelegate(call.execute());
+ }
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if callback is null
+ * @return the {@link Call} object
+ */
+ public ServiceCall getEmptyAsync(String vault, String secret, String keyName, final ServiceCallback serviceCallback) throws IllegalArgumentException {
+ if (serviceCallback == null) {
+ throw new IllegalArgumentException("ServiceCallback is required for async calls.");
+ }
+ if (vault == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter vault is required and cannot be null."));
+ return null;
+ }
+ if (secret == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter secret is required and cannot be null."));
+ return null;
+ }
+ if (this.client.getDnsSuffix() == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter this.client.getDnsSuffix() is required and cannot be null."));
+ return null;
+ }
+ if (keyName == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter keyName is required and cannot be null."));
+ return null;
+ }
+ if (this.client.getSubscriptionId() == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter this.client.getSubscriptionId() is required and cannot be null."));
+ return null;
+ }
+ final String keyVersion = null;
+ this.client.getBaseUrl().set("{vault}", vault);
+ this.client.getBaseUrl().set("{secret}", secret);
+ this.client.getBaseUrl().set("{dnsSuffix}", this.client.getDnsSuffix());
+ Call call = service.getEmpty(keyName, this.client.getSubscriptionId(), keyVersion);
+ final ServiceCall serviceCall = new ServiceCall(call);
+ call.enqueue(new ServiceResponseCallback(serviceCallback) {
+ @Override
+ public void onResponse(Call call, Response response) {
+ try {
+ serviceCallback.success(getEmptyDelegate(response));
+ } catch (ErrorException | IOException exception) {
+ serviceCallback.failure(exception);
+ }
+ }
+ });
+ return serviceCall;
+ }
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param keyVersion The key version. Default value 'v1'.
+ * @throws ErrorException exception thrown from REST call
+ * @throws IOException exception thrown from serialization/deserialization
+ * @throws IllegalArgumentException exception thrown from invalid parameters
+ * @return the {@link ServiceResponse} object if successful.
+ */
+ public ServiceResponse getEmpty(String vault, String secret, String keyName, String keyVersion) throws ErrorException, IOException, IllegalArgumentException {
+ if (vault == null) {
+ throw new IllegalArgumentException("Parameter vault is required and cannot be null.");
+ }
+ if (secret == null) {
+ throw new IllegalArgumentException("Parameter secret is required and cannot be null.");
+ }
+ if (this.client.getDnsSuffix() == null) {
+ throw new IllegalArgumentException("Parameter this.client.getDnsSuffix() is required and cannot be null.");
+ }
+ if (keyName == null) {
+ throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
+ }
+ if (this.client.getSubscriptionId() == null) {
+ throw new IllegalArgumentException("Parameter this.client.getSubscriptionId() is required and cannot be null.");
+ }
+ this.client.getBaseUrl().set("{vault}", vault);
+ this.client.getBaseUrl().set("{secret}", secret);
+ this.client.getBaseUrl().set("{dnsSuffix}", this.client.getDnsSuffix());
+ Call call = service.getEmpty(keyName, this.client.getSubscriptionId(), keyVersion);
+ return getEmptyDelegate(call.execute());
+ }
+
+ /**
+ * Get a 200 to test a valid base uri.
+ *
+ * @param vault The vault name, e.g. https://myvault
+ * @param secret Secret value.
+ * @param keyName The key name with value 'key1'.
+ * @param keyVersion The key version. Default value 'v1'.
+ * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
+ * @throws IllegalArgumentException thrown if callback is null
+ * @return the {@link Call} object
+ */
+ public ServiceCall getEmptyAsync(String vault, String secret, String keyName, String keyVersion, final ServiceCallback serviceCallback) throws IllegalArgumentException {
+ if (serviceCallback == null) {
+ throw new IllegalArgumentException("ServiceCallback is required for async calls.");
+ }
+ if (vault == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter vault is required and cannot be null."));
+ return null;
+ }
+ if (secret == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter secret is required and cannot be null."));
+ return null;
+ }
+ if (this.client.getDnsSuffix() == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter this.client.getDnsSuffix() is required and cannot be null."));
+ return null;
+ }
+ if (keyName == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter keyName is required and cannot be null."));
+ return null;
+ }
+ if (this.client.getSubscriptionId() == null) {
+ serviceCallback.failure(new IllegalArgumentException("Parameter this.client.getSubscriptionId() is required and cannot be null."));
+ return null;
+ }
+ this.client.getBaseUrl().set("{vault}", vault);
+ this.client.getBaseUrl().set("{secret}", secret);
+ this.client.getBaseUrl().set("{dnsSuffix}", this.client.getDnsSuffix());
+ Call call = service.getEmpty(keyName, this.client.getSubscriptionId(), keyVersion);
+ final ServiceCall serviceCall = new ServiceCall(call);
+ call.enqueue(new ServiceResponseCallback(serviceCallback) {
+ @Override
+ public void onResponse(Call call, Response response) {
+ try {
+ serviceCallback.success(getEmptyDelegate(response));
+ } catch (ErrorException | IOException exception) {
+ serviceCallback.failure(exception);
+ }
+ }
+ });
+ return serviceCall;
+ }
+
+ private ServiceResponse getEmptyDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
+ return new ServiceResponseBuilder(this.client.getMapperAdapter())
+ .register(200, new TypeToken() { }.getType())
+ .registerError(ErrorException.class)
+ .build(response);
+ }
+
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/Error.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/Error.java
new file mode 100644
index 0000000000000..73232cf4ed434
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/Error.java
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions.models;
+
+
+/**
+ * The Error model.
+ */
+public class Error {
+ /**
+ * The status property.
+ */
+ private Integer status;
+
+ /**
+ * The message property.
+ */
+ private String message;
+
+ /**
+ * Get the status value.
+ *
+ * @return the status value
+ */
+ public Integer getStatus() {
+ return this.status;
+ }
+
+ /**
+ * Set the status value.
+ *
+ * @param status the status value to set
+ */
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ /**
+ * Get the message value.
+ *
+ * @return the message value
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ /**
+ * Set the message value.
+ *
+ * @param message the message value to set
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/ErrorException.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/ErrorException.java
new file mode 100644
index 0000000000000..0c4458e200dac
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/ErrorException.java
@@ -0,0 +1,89 @@
+/**
+ * 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.
+ */
+
+package fixtures.custombaseurimoreoptions.models;
+
+import com.microsoft.rest.AutoRestException;
+import retrofit2.Response;
+
+/**
+ * Exception thrown for an invalid response with Error information.
+ */
+public class ErrorException extends AutoRestException {
+ /**
+ * Information about the associated HTTP response.
+ */
+ private Response response;
+ /**
+ * The actual response body.
+ */
+ private Error body;
+ /**
+ * Initializes a new instance of the ErrorException class.
+ */
+ public ErrorException() { }
+ /**
+ * Initializes a new instance of the ErrorException class.
+ *
+ * @param message The exception message.
+ */
+ public ErrorException(final String message) {
+ super(message);
+ }
+ /**
+ * Initializes a new instance of the ErrorException class.
+ *
+ * @param message the exception message
+ * @param cause exception that caused this exception to occur
+ */
+ public ErrorException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Initializes a new instance of the ErrorException class.
+ *
+ * @param cause exception that caused this exception to occur
+ */
+ public ErrorException(final Throwable cause) {
+ super(cause);
+ }
+ /**
+ * Gets information about the associated HTTP response.
+ *
+ * @return the HTTP response
+ */
+ public Response getResponse() {
+ return response;
+ }
+ /**
+ * Gets the HTTP response body.
+ *
+ * @return the response body
+ */
+ public Error getBody() {
+ return body;
+ }
+ /**
+ * Sets the HTTP response.
+ *
+ * @param response the HTTP response
+ */
+ public void setResponse(Response response) {
+ this.response = response;
+ }
+ /**
+ * Sets the HTTP response body.
+ *
+ * @param body the response body
+ */
+ public void setBody(Error body) {
+ this.body = body;
+ }
+}
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/package-info.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/package-info.java
new file mode 100644
index 0000000000000..b5c9a91ec97d8
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/models/package-info.java
@@ -0,0 +1,13 @@
+// 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.
+
+/**
+ * This package contains the model classes for AutoRestParameterizedCustomHostTestClient.
+ * Test Infrastructure for AutoRest.
+ */
+package fixtures.custombaseurimoreoptions.models;
diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/package-info.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/package-info.java
new file mode 100644
index 0000000000000..a6434083eb1c5
--- /dev/null
+++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/custombaseurimoreoptions/package-info.java
@@ -0,0 +1,13 @@
+// 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.
+
+/**
+ * This package contains the classes for AutoRestParameterizedCustomHostTestClient.
+ * Test Infrastructure for AutoRest.
+ */
+package fixtures.custombaseurimoreoptions;
diff --git a/AutoRest/Generators/Java/Java/TypeModels/PrimaryTypeModel.cs b/AutoRest/Generators/Java/Java/TypeModels/PrimaryTypeModel.cs
index 2d5a2fad78626..d6990c79ff680 100644
--- a/AutoRest/Generators/Java/Java/TypeModels/PrimaryTypeModel.cs
+++ b/AutoRest/Generators/Java/Java/TypeModels/PrimaryTypeModel.cs
@@ -202,6 +202,10 @@ private void Initialize(PrimaryType primaryType)
Name = "Period";
_imports.Add("org.joda.time.Period");
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ Name = "long";
+ }
else if (primaryType.Type == KnownPrimaryType.Uuid)
{
Name = "UUID";
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts
index c7404da84e360..0a81b3420068b 100644
--- a/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts
@@ -32,7 +32,7 @@ import dictionaryModels = require('../Expected/AcceptanceTests/BodyDictionary/mo
import httpClient = require('../Expected/AcceptanceTests/Http/autoRestHttpInfrastructureTestService');
import formDataClient = require('../Expected/AcceptanceTests/BodyFormData/autoRestSwaggerBATFormDataService');
import customBaseUriClient = require('../Expected/AcceptanceTests/CustomBaseUri/autoRestParameterizedHostTestClient');
-
+import customBaseUriClientMoreOptions = require('../Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient');
var dummyToken = 'dummy12321343423';
var credentials = new msRest.TokenCredentials(dummyToken);
@@ -94,6 +94,19 @@ describe('nodejs', function () {
});
});
});
+ describe('Custom BaseUri Client with more options', function () {
+ var customOptions = {
+ dnsSuffix: 'host:3000'
+ };
+ var testClient = new customBaseUriClientMoreOptions('test12', customOptions);
+ it('should return 200', function (done) {
+ testClient.paths.getEmpty('http://lo','cal', 'key1', function (error, result, request, response) {
+ should.not.exist(error);
+ response.statusCode.should.equal(200);
+ done();
+ });
+ });
+ });
describe('Bool Client', function () {
var testClient = new boolClient(baseUri, clientOptions);
it('should get valid boolean values', function (done) {
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.d.ts
new file mode 100644
index 0000000000000..98c22ab85f4de
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.d.ts
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+import { ServiceClientOptions, RequestOptions, ServiceCallback } from 'ms-rest';
+import * as operations from "./operations";
+
+declare class AutoRestParameterizedCustomHostTestClient {
+ /**
+ * @class
+ * Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ * @constructor
+ *
+ * @param {string} subscriptionId - The subscription id with value 'test12'.
+ *
+ * @param {object} [options] - The parameter options
+ *
+ * @param {Array} [options.filters] - Filters to be added to the request pipeline
+ *
+ * @param {object} [options.requestOptions] - Options for the underlying request object
+ * {@link https://github.com/request/request#requestoptions-callback Options doc}
+ *
+ * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy
+ *
+ * @param {string} [options.dnsSuffix] - A string value that is used as a global part of the parameterized host. Default value 'host'.
+ *
+ */
+ constructor(subscriptionId: string, options: ServiceClientOptions);
+
+ subscriptionId: string;
+
+ dnsSuffix: string;
+
+ // Operation groups
+ paths: operations.Paths;
+ }
+
+export = AutoRestParameterizedCustomHostTestClient;
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.js
new file mode 100644
index 0000000000000..391f7b50deb38
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient.js
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+/* jshint latedef:false */
+/* jshint forin:false */
+/* jshint noempty:false */
+
+'use strict';
+
+var util = require('util');
+var msRest = require('ms-rest');
+var ServiceClient = msRest.ServiceClient;
+
+var models = require('./models');
+var operations = require('./operations');
+
+/**
+ * @class
+ * Initializes a new instance of the AutoRestParameterizedCustomHostTestClient class.
+ * @constructor
+ *
+ * @param {string} subscriptionId - The subscription id with value 'test12'.
+ *
+ * @param {object} [options] - The parameter options
+ *
+ * @param {Array} [options.filters] - Filters to be added to the request pipeline
+ *
+ * @param {object} [options.requestOptions] - Options for the underlying request object
+ * {@link https://github.com/request/request#requestoptions-callback Options doc}
+ *
+ * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy
+ *
+ * @param {string} [options.dnsSuffix] - A string value that is used as a global part of the parameterized host. Default value 'host'.
+ *
+ */
+function AutoRestParameterizedCustomHostTestClient(subscriptionId, options) {
+ this.dnsSuffix = 'host';
+ if (subscriptionId === null || subscriptionId === undefined) {
+ throw new Error('\'subscriptionId\' cannot be null.');
+ }
+
+ if (!options) options = {};
+
+ AutoRestParameterizedCustomHostTestClient['super_'].call(this, null, options);
+ this.baseUri = '{vault}{secret}{dnsSuffix}';
+ this.subscriptionId = subscriptionId;
+
+ if(options.dnsSuffix !== null && options.dnsSuffix !== undefined) {
+ this.dnsSuffix = options.dnsSuffix;
+ }
+ this.paths = new operations.Paths(this);
+ this.models = models;
+ msRest.addSerializationMixin(this);
+}
+
+util.inherits(AutoRestParameterizedCustomHostTestClient, ServiceClient);
+
+module.exports = AutoRestParameterizedCustomHostTestClient;
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/errorModel.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/errorModel.js
new file mode 100644
index 0000000000000..663be0f4aaa8c
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/errorModel.js
@@ -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.
+ */
+
+'use strict';
+
+/**
+ * @class
+ * Initializes a new instance of the ErrorModel class.
+ * @constructor
+ * @member {number} [status]
+ *
+ * @member {string} [message]
+ *
+ */
+function ErrorModel() {
+}
+
+/**
+ * Defines the metadata of ErrorModel
+ *
+ * @returns {object} metadata of ErrorModel
+ *
+ */
+ErrorModel.prototype.mapper = function () {
+ return {
+ required: false,
+ serializedName: 'Error',
+ type: {
+ name: 'Composite',
+ className: 'ErrorModel',
+ modelProperties: {
+ status: {
+ required: false,
+ serializedName: 'status',
+ type: {
+ name: 'Number'
+ }
+ },
+ message: {
+ required: false,
+ serializedName: 'message',
+ type: {
+ name: 'String'
+ }
+ }
+ }
+ }
+ };
+};
+
+module.exports = ErrorModel;
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.d.ts
new file mode 100644
index 0000000000000..5405a199a0755
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.d.ts
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+
+/**
+ * @class
+ * Initializes a new instance of the ErrorModel class.
+ * @constructor
+ * @member {number} [status]
+ *
+ * @member {string} [message]
+ *
+ */
+export interface ErrorModel {
+ status?: number;
+ message?: string;
+}
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.js
new file mode 100644
index 0000000000000..3430295d8bd86
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/models/index.js
@@ -0,0 +1,17 @@
+/*
+ * 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.
+ */
+
+/* jshint latedef:false */
+/* jshint forin:false */
+/* jshint noempty:false */
+
+'use strict';
+
+exports.ErrorModel = require('./errorModel');
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.d.ts
new file mode 100644
index 0000000000000..3fa4ea5d9bf14
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.d.ts
@@ -0,0 +1,44 @@
+/*
+ * 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.
+*/
+
+import { ServiceClientOptions, RequestOptions, ServiceCallback } from 'ms-rest';
+import * as models from '../models';
+
+
+/**
+ * @class
+ * Paths
+ * __NOTE__: An instance of this class is automatically created for an
+ * instance of the AutoRestParameterizedCustomHostTestClient.
+ */
+export interface Paths {
+
+ /**
+ * Get a 200 to test a valid base uri
+ *
+ * @param {string} vault The vault name, e.g. https://myvault
+ *
+ * @param {string} secret Secret value.
+ *
+ * @param {string} keyName The key name with value 'key1'.
+ *
+ * @param {object} [options] Optional Parameters.
+ *
+ * @param {string} [options.keyVersion] The key version. Default value 'v1'.
+ *
+ * @param {object} [options.customHeaders] Headers that will be added to the
+ * request
+ *
+ * @param {ServiceCallback} [callback] callback function; see ServiceCallback
+ * doc in ms-rest index.d.ts for details
+ */
+ getEmpty(vault: string, secret: string, keyName: string, options: { keyVersion? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void;
+ getEmpty(vault: string, secret: string, keyName: string, callback: ServiceCallback): void;
+}
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.js
new file mode 100644
index 0000000000000..412d88e67668a
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/index.js
@@ -0,0 +1,17 @@
+/*
+ * 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.
+ */
+
+/* jshint latedef:false */
+/* jshint forin:false */
+/* jshint noempty:false */
+
+'use strict';
+
+exports.Paths = require('./paths');
diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/paths.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/paths.js
new file mode 100644
index 0000000000000..dc2c66f05c60e
--- /dev/null
+++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/operations/paths.js
@@ -0,0 +1,167 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var util = require('util');
+var msRest = require('ms-rest');
+var WebResource = msRest.WebResource;
+
+/**
+ * @class
+ * Paths
+ * __NOTE__: An instance of this class is automatically created for an
+ * instance of the AutoRestParameterizedCustomHostTestClient.
+ * Initializes a new instance of the Paths class.
+ * @constructor
+ *
+ * @param {AutoRestParameterizedCustomHostTestClient} client Reference to the service client.
+ */
+function Paths(client) {
+ this.client = client;
+}
+
+/**
+ * Get a 200 to test a valid base uri
+ *
+ * @param {string} vault The vault name, e.g. https://myvault
+ *
+ * @param {string} secret Secret value.
+ *
+ * @param {string} keyName The key name with value 'key1'.
+ *
+ * @param {object} [options] Optional Parameters.
+ *
+ * @param {string} [options.keyVersion] The key version. Default value 'v1'.
+ *
+ * @param {object} [options.customHeaders] Headers that will be added to the
+ * request
+ *
+ * @param {function} callback
+ *
+ * @returns {function} callback(err, result, request, response)
+ *
+ * {Error} err - The Error object if an error occurred, null otherwise.
+ *
+ * {null} [result] - The deserialized result object.
+ *
+ * {object} [request] - The HTTP Request object if an error did not occur.
+ *
+ * {stream} [response] - The HTTP Response stream if an error did not occur.
+ */
+Paths.prototype.getEmpty = function (vault, secret, keyName, options, callback) {
+ var client = this.client;
+ if(!callback && typeof options === 'function') {
+ callback = options;
+ options = null;
+ }
+ if (!callback) {
+ throw new Error('callback cannot be null.');
+ }
+ var keyVersion = (options && options.keyVersion !== undefined) ? options.keyVersion : 'v1';
+ // Validate
+ try {
+ if (vault === null || vault === undefined || typeof vault.valueOf() !== 'string') {
+ throw new Error('vault cannot be null or undefined and it must be of type string.');
+ }
+ if (secret === null || secret === undefined || typeof secret.valueOf() !== 'string') {
+ throw new Error('secret cannot be null or undefined and it must be of type string.');
+ }
+ if (this.client.dnsSuffix === null || this.client.dnsSuffix === undefined || typeof this.client.dnsSuffix.valueOf() !== 'string') {
+ throw new Error('this.client.dnsSuffix cannot be null or undefined and it must be of type string.');
+ }
+ if (keyName === null || keyName === undefined || typeof keyName.valueOf() !== 'string') {
+ throw new Error('keyName cannot be null or undefined and it must be of type string.');
+ }
+ if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
+ throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
+ }
+ if (keyVersion !== null && keyVersion !== undefined && typeof keyVersion.valueOf() !== 'string') {
+ throw new Error('keyVersion must be of type string.');
+ }
+ } catch (error) {
+ return callback(error);
+ }
+
+ // Construct URL
+ var requestUrl = this.client.baseUri +
+ '//customuri/{subscriptionId}/{keyName}';
+ requestUrl = requestUrl.replace('{vault}', vault);
+ requestUrl = requestUrl.replace('{secret}', secret);
+ requestUrl = requestUrl.replace('{dnsSuffix}', this.client.dnsSuffix);
+ requestUrl = requestUrl.replace('{keyName}', encodeURIComponent(keyName));
+ requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
+ var queryParameters = [];
+ if (keyVersion !== null && keyVersion !== undefined) {
+ queryParameters.push('keyVersion=' + encodeURIComponent(keyVersion));
+ }
+ if (queryParameters.length > 0) {
+ requestUrl += '?' + queryParameters.join('&');
+ }
+ // trim all duplicate forward slashes in the url
+ var regex = /([^:]\/)\/+/gi;
+ requestUrl = requestUrl.replace(regex, '$1');
+
+ // Create HTTP transport objects
+ var httpRequest = new WebResource();
+ httpRequest.method = 'GET';
+ httpRequest.headers = {};
+ httpRequest.url = requestUrl;
+ // Set Headers
+ if(options) {
+ for(var headerName in options['customHeaders']) {
+ if (options['customHeaders'].hasOwnProperty(headerName)) {
+ httpRequest.headers[headerName] = options['customHeaders'][headerName];
+ }
+ }
+ }
+ httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
+ httpRequest.body = null;
+ // Send Request
+ return client.pipeline(httpRequest, function (err, response, responseBody) {
+ if (err) {
+ return callback(err);
+ }
+ var statusCode = response.statusCode;
+ if (statusCode !== 200) {
+ var error = new Error(responseBody);
+ error.statusCode = response.statusCode;
+ error.request = msRest.stripRequest(httpRequest);
+ error.response = msRest.stripResponse(response);
+ if (responseBody === '') responseBody = null;
+ var parsedErrorResponse;
+ try {
+ parsedErrorResponse = JSON.parse(responseBody);
+ if (parsedErrorResponse) {
+ if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
+ if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
+ if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
+ }
+ if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
+ var resultMapper = new client.models['ErrorModel']().mapper();
+ error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
+ }
+ } catch (defaultError) {
+ error.message = util.format('Error "%s" occurred in deserializing the responseBody ' +
+ '- "%s" for the default response.', defaultError.message, responseBody);
+ return callback(error);
+ }
+ return callback(error);
+ }
+ // Create Result
+ var result = null;
+ if (responseBody === '') responseBody = null;
+
+ return callback(null, result, httpRequest, response);
+ });
+};
+
+
+module.exports = Paths;
diff --git a/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs b/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs
index 53ac858681ef1..d2f43a402f589 100644
--- a/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs
+++ b/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs
@@ -393,6 +393,10 @@ private static IType NormalizePrimaryType(PrimaryType primaryType)
{
primaryType.Name = "moment.duration";
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ primaryType.Name = "Number";
+ }
else if (primaryType.Type == KnownPrimaryType.Uuid)
{
primaryType.Name = "Uuid";
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureBodyDuration/autorestdurationtestservice/auto_rest_duration_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureBodyDuration/autorestdurationtestservice/auto_rest_duration_test_service.py
index bceee986fdda8..668b135381e1f 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureBodyDuration/autorestdurationtestservice/auto_rest_duration_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureBodyDuration/autorestdurationtestservice/auto_rest_duration_test_service.py
@@ -43,7 +43,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'https://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureParameterGrouping/autorestparametergroupingtestservice/auto_rest_parameter_grouping_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureParameterGrouping/autorestparametergroupingtestservice/auto_rest_parameter_grouping_test_service.py
index b8bae0b1b5228..13e63f9569c81 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureParameterGrouping/autorestparametergroupingtestservice/auto_rest_parameter_grouping_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureParameterGrouping/autorestparametergroupingtestservice/auto_rest_parameter_grouping_test_service.py
@@ -43,7 +43,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'https://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureReport/autorestreportserviceforazure/auto_rest_report_service_for_azure.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureReport/autorestreportserviceforazure/auto_rest_report_service_for_azure.py
index b37530e7d7985..c02088e43b1a4 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureReport/autorestreportserviceforazure/auto_rest_report_service_for_azure.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureReport/autorestreportserviceforazure/auto_rest_report_service_for_azure.py
@@ -44,7 +44,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/auto_rest_resource_flattening_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/auto_rest_resource_flattening_test_service.py
index 3a806d13f53fc..74f09db9d3400 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/auto_rest_resource_flattening_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/auto_rest_resource_flattening_test_service.py
@@ -44,7 +44,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/flattened_product.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/flattened_product.py
index 5b5b7ea2e4c04..37bf31568e6ae 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/flattened_product.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/flattened_product.py
@@ -15,16 +15,19 @@
class FlattenedProduct(Resource):
"""FlattenedProduct
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
:param pname:
:type pname: str
:param lsize:
@@ -33,6 +36,12 @@ class FlattenedProduct(Resource):
:type provisioning_state: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -44,8 +53,8 @@ class FlattenedProduct(Resource):
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None, pname=None, lsize=None, provisioning_state=None):
- super(FlattenedProduct, self).__init__(id=id, type=type, tags=tags, location=location, name=name)
+ def __init__(self, tags=None, location=None, pname=None, lsize=None, provisioning_state=None):
+ super(FlattenedProduct, self).__init__(tags=tags, location=location)
self.pname = pname
self.lsize = lsize
self.provisioning_state = provisioning_state
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py
index ccc46d79f60ce..349e6b7fbd717 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py
@@ -15,18 +15,27 @@
class Resource(Model):
"""Resource
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -35,9 +44,9 @@ class Resource(Model):
'name': {'key': 'name', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None):
- self.id = id
- self.type = type
+ def __init__(self, tags=None, location=None):
+ self.id = None
+ self.type = None
self.tags = tags
self.location = location
- self.name = name
+ self.name = None
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureSpecials/autorestazurespecialparameterstestclient/auto_rest_azure_special_parameters_test_client.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureSpecials/autorestazurespecialparameterstestclient/auto_rest_azure_special_parameters_test_client.py
index cc2d96c0ce719..95f2d47d0fb58 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureSpecials/autorestazurespecialparameterstestclient/auto_rest_azure_special_parameters_test_client.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureSpecials/autorestazurespecialparameterstestclient/auto_rest_azure_special_parameters_test_client.py
@@ -56,9 +56,15 @@ def __init__(
self, credentials, subscription_id, api_version='2015-07-01-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
- raise ValueError('subscription_id must not be None.')
+ raise ValueError("Parameter 'subscription_id' must not be None.")
+ if not isinstance(subscription_id, str):
+ raise TypeError("Parameter 'subscription_id' must be str.")
+ if api_version is not None and not isinstance(api_version, str):
+ raise TypeError("Optional parameter 'api_version' must be str.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
index ce9c7112afaf5..79e862f82db73 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
@@ -45,9 +45,13 @@ def __init__(
self, credentials, host, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
if host is None:
- raise ValueError('host must not be None.')
+ raise ValueError("Parameter 'host' must not be None.")
+ if not isinstance(host, str):
+ raise TypeError("Parameter 'host' must be str.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
base_url = 'http://{accountName}{host}'
super(AutoRestParameterizedHostTestClientConfiguration, self).__init__(base_url, filepath)
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Head/autorestheadtestservice/auto_rest_head_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Head/autorestheadtestservice/auto_rest_head_test_service.py
index 85044ec1cbcc4..fc86a3308cb2e 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Head/autorestheadtestservice/auto_rest_head_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Head/autorestheadtestservice/auto_rest_head_test_service.py
@@ -42,7 +42,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/HeadExceptions/autorestheadexceptiontestservice/auto_rest_head_exception_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/HeadExceptions/autorestheadexceptiontestservice/auto_rest_head_exception_test_service.py
index e7531777378d2..d9745572729ef 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/HeadExceptions/autorestheadexceptiontestservice/auto_rest_head_exception_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/HeadExceptions/autorestheadexceptiontestservice/auto_rest_head_exception_test_service.py
@@ -42,7 +42,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/auto_rest_long_running_operation_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/auto_rest_long_running_operation_test_service.py
index 718b1114d10af..be1ddc0cc63c0 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/auto_rest_long_running_operation_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/auto_rest_long_running_operation_test_service.py
@@ -46,7 +46,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/product.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/product.py
index 6f322f37b09fc..1671df6f6c655 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/product.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/product.py
@@ -15,24 +15,34 @@
class Product(Resource):
"""Product
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
:param provisioning_state:
:type provisioning_state: str
- :param provisioning_state_values: Possible values include: 'Succeeded',
+ :ivar provisioning_state_values: Possible values include: 'Succeeded',
'Failed', 'canceled', 'Accepted', 'Creating', 'Created', 'Updating',
'Updated', 'Deleting', 'Deleted', 'OK'
- :type provisioning_state_values: str
+ :vartype provisioning_state_values: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ 'provisioning_state_values': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -43,7 +53,7 @@ class Product(Resource):
'provisioning_state_values': {'key': 'properties.provisioningStateValues', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None, provisioning_state=None, provisioning_state_values=None):
- super(Product, self).__init__(id=id, type=type, tags=tags, location=location, name=name)
+ def __init__(self, tags=None, location=None, provisioning_state=None):
+ super(Product, self).__init__(tags=tags, location=location)
self.provisioning_state = provisioning_state
- self.provisioning_state_values = provisioning_state_values
+ self.provisioning_state_values = None
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/resource.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/resource.py
index ccc46d79f60ce..349e6b7fbd717 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/resource.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/resource.py
@@ -15,18 +15,27 @@
class Resource(Model):
"""Resource
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -35,9 +44,9 @@ class Resource(Model):
'name': {'key': 'name', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None):
- self.id = id
- self.type = type
+ def __init__(self, tags=None, location=None):
+ self.id = None
+ self.type = None
self.tags = tags
self.location = location
- self.name = name
+ self.name = None
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_product.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_product.py
index 099f79ecdc9de..c813566223b8d 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_product.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_product.py
@@ -15,23 +15,31 @@
class SubProduct(SubResource):
"""SubProduct
- :param id: Sub Resource Id
- :type id: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Sub Resource Id
+ :vartype id: str
:param provisioning_state:
:type provisioning_state: str
- :param provisioning_state_values: Possible values include: 'Succeeded',
+ :ivar provisioning_state_values: Possible values include: 'Succeeded',
'Failed', 'canceled', 'Accepted', 'Creating', 'Created', 'Updating',
'Updated', 'Deleting', 'Deleted', 'OK'
- :type provisioning_state_values: str
+ :vartype provisioning_state_values: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'provisioning_state_values': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'provisioning_state_values': {'key': 'properties.provisioningStateValues', 'type': 'str'},
}
- def __init__(self, id=None, provisioning_state=None, provisioning_state_values=None):
- super(SubProduct, self).__init__(id=id)
+ def __init__(self, provisioning_state=None):
+ super(SubProduct, self).__init__()
self.provisioning_state = provisioning_state
- self.provisioning_state_values = provisioning_state_values
+ self.provisioning_state_values = None
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_resource.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_resource.py
index 46ce23db785ac..77ec6cf29f437 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_resource.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/sub_resource.py
@@ -15,13 +15,20 @@
class SubResource(Model):
"""SubResource
- :param id: Sub Resource Id
- :type id: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Sub Resource Id
+ :vartype id: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
}
- def __init__(self, id=None):
- self.id = id
+ def __init__(self):
+ self.id = None
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Paging/autorestpagingtestservice/auto_rest_paging_test_service.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Paging/autorestpagingtestservice/auto_rest_paging_test_service.py
index 532adc38d5acc..e3cf9310642ed 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Paging/autorestpagingtestservice/auto_rest_paging_test_service.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/Paging/autorestpagingtestservice/auto_rest_paging_test_service.py
@@ -43,7 +43,9 @@ def __init__(
self, credentials, accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/resource.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/resource.py
index 9025ae9819072..8d25c5c02f7ac 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/resource.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/resource.py
@@ -15,12 +15,15 @@
class Resource(Model):
"""Resource
- :param id: Resource Id
- :type id: str
- :param name: Resource name
- :type name: str
- :param type: Resource type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar name: Resource name
+ :vartype name: str
+ :ivar type: Resource type
+ :vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
@@ -28,6 +31,9 @@ class Resource(Model):
"""
_validation = {
+ 'id': {'readonly': True},
+ 'name': {'readonly': True},
+ 'type': {'readonly': True},
'location': {'required': True},
}
@@ -39,9 +45,9 @@ class Resource(Model):
'tags': {'key': 'tags', 'type': '{str}'},
}
- def __init__(self, location, id=None, name=None, type=None, tags=None):
- self.id = id
- self.name = name
- self.type = type
+ def __init__(self, location, tags=None):
+ self.id = None
+ self.name = None
+ self.type = None
self.location = location
self.tags = tags
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account.py
index 3268320474a92..bff1707d78076 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account.py
@@ -16,12 +16,15 @@ class StorageAccount(Resource):
"""
The storage account.
- :param id: Resource Id
- :type id: str
- :param name: Resource name
- :type name: str
- :param type: Resource type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar name: Resource name
+ :vartype name: str
+ :ivar type: Resource type
+ :vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
@@ -77,6 +80,9 @@ class StorageAccount(Resource):
"""
_validation = {
+ 'id': {'readonly': True},
+ 'name': {'readonly': True},
+ 'type': {'readonly': True},
'location': {'required': True},
}
@@ -99,8 +105,8 @@ class StorageAccount(Resource):
'secondary_endpoints': {'key': 'properties.secondaryEndpoints', 'type': 'Endpoints'},
}
- def __init__(self, location, id=None, name=None, type=None, tags=None, provisioning_state=None, account_type=None, primary_endpoints=None, primary_location=None, status_of_primary=None, last_geo_failover_time=None, secondary_location=None, status_of_secondary=None, creation_time=None, custom_domain=None, secondary_endpoints=None):
- super(StorageAccount, self).__init__(id=id, name=name, type=type, location=location, tags=tags)
+ def __init__(self, location, tags=None, provisioning_state=None, account_type=None, primary_endpoints=None, primary_location=None, status_of_primary=None, last_geo_failover_time=None, secondary_location=None, status_of_secondary=None, creation_time=None, custom_domain=None, secondary_endpoints=None):
+ super(StorageAccount, self).__init__(location=location, tags=tags)
self.provisioning_state = provisioning_state
self.account_type = account_type
self.primary_endpoints = primary_endpoints
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_create_parameters.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_create_parameters.py
index 449f6c502135a..31535a2dc8c20 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_create_parameters.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_create_parameters.py
@@ -16,12 +16,15 @@ class StorageAccountCreateParameters(Resource):
"""
The parameters to provide for the account.
- :param id: Resource Id
- :type id: str
- :param name: Resource name
- :type name: str
- :param type: Resource type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar name: Resource name
+ :vartype name: str
+ :ivar type: Resource type
+ :vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
@@ -33,6 +36,9 @@ class StorageAccountCreateParameters(Resource):
"""
_validation = {
+ 'id': {'readonly': True},
+ 'name': {'readonly': True},
+ 'type': {'readonly': True},
'location': {'required': True},
}
@@ -45,6 +51,6 @@ class StorageAccountCreateParameters(Resource):
'account_type': {'key': 'properties.accountType', 'type': 'AccountType'},
}
- def __init__(self, location, id=None, name=None, type=None, tags=None, account_type=None):
- super(StorageAccountCreateParameters, self).__init__(id=id, name=name, type=type, location=location, tags=tags)
+ def __init__(self, location, tags=None, account_type=None):
+ super(StorageAccountCreateParameters, self).__init__(location=location, tags=tags)
self.account_type = account_type
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_update_parameters.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_update_parameters.py
index 5975e56879436..e60b187d613bd 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_update_parameters.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/models/storage_account_update_parameters.py
@@ -16,12 +16,15 @@ class StorageAccountUpdateParameters(Resource):
"""
The parameters to update on the account.
- :param id: Resource Id
- :type id: str
- :param name: Resource name
- :type name: str
- :param type: Resource type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar name: Resource name
+ :vartype name: str
+ :ivar type: Resource type
+ :vartype type: str
:param location: Resource location
:type location: str
:param tags: Resource tags
@@ -41,6 +44,9 @@ class StorageAccountUpdateParameters(Resource):
"""
_validation = {
+ 'id': {'readonly': True},
+ 'name': {'readonly': True},
+ 'type': {'readonly': True},
'location': {'required': True},
}
@@ -54,7 +60,7 @@ class StorageAccountUpdateParameters(Resource):
'custom_domain': {'key': 'properties.customDomain', 'type': 'CustomDomain'},
}
- def __init__(self, location, id=None, name=None, type=None, tags=None, account_type=None, custom_domain=None):
- super(StorageAccountUpdateParameters, self).__init__(id=id, name=name, type=type, location=location, tags=tags)
+ def __init__(self, location, tags=None, account_type=None, custom_domain=None):
+ super(StorageAccountUpdateParameters, self).__init__(location=location, tags=tags)
self.account_type = account_type
self.custom_domain = custom_domain
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/storage_management_client.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/storage_management_client.py
index cd2c457915195..1334ec94142ec 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/storage_management_client.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/storage_management_client.py
@@ -50,9 +50,15 @@ def __init__(
self, credentials, subscription_id, api_version='2015-05-01-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
- raise ValueError('subscription_id must not be None.')
+ raise ValueError("Parameter 'subscription_id' must not be None.")
+ if not isinstance(subscription_id, str):
+ raise TypeError("Parameter 'subscription_id' must be str.")
+ if api_version is not None and not isinstance(api_version, str):
+ raise TypeError("Optional parameter 'api_version' must be str.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'https://management.azure.com'
diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/SubscriptionIdApiVersion/microsoftazuretesturl/microsoft_azure_test_url.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/SubscriptionIdApiVersion/microsoftazuretesturl/microsoft_azure_test_url.py
index 99e3bc1f4ce98..d16f3f25706a6 100644
--- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/SubscriptionIdApiVersion/microsoftazuretesturl/microsoft_azure_test_url.py
+++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/SubscriptionIdApiVersion/microsoftazuretesturl/microsoft_azure_test_url.py
@@ -47,9 +47,15 @@ def __init__(
self, credentials, subscription_id, api_version='2014-04-01-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
- raise ValueError('credentials must not be None.')
+ raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
- raise ValueError('subscription_id must not be None.')
+ raise ValueError("Parameter 'subscription_id' must not be None.")
+ if not isinstance(subscription_id, str):
+ raise TypeError("Parameter 'subscription_id' must be str.")
+ if api_version is not None and not isinstance(api_version, str):
+ raise TypeError("Optional parameter 'api_version' must be str.")
+ if accept_language is not None and not isinstance(accept_language, str):
+ raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'https://management.azure.com/'
diff --git a/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs b/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs
index 3c0cfcbf8160c..f56bc3935547a 100644
--- a/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs
+++ b/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs
@@ -74,7 +74,7 @@ public override string RequiredConstructorParameters
else
{
string defaultValue = PythonConstants.None;
- if (property.DefaultValue != null && property.Type is PrimaryType)
+ if (!string.IsNullOrWhiteSpace(property.DefaultValue) && property.Type is PrimaryType)
{
defaultValue = property.DefaultValue;
}
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/complex_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/complex_tests.py
index fcbf2f38617cf..fa4902659e391 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/complex_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/complex_tests.py
@@ -201,6 +201,19 @@ def test_complex(self):
# PUT primitive/byte
client.primitive.put_byte(valid_bytes)
+ """
+ COMPLEX TYPE WITH READ ONLY PROPERTIES
+ """
+ # GET readonly/valid
+ valid_obj = ReadonlyObj(size=2)
+ valid_obj.id = '1234'
+ readonly_result = client.readonlyproperty.get_valid()
+ self.assertEqual(readonly_result, valid_obj)
+
+ # PUT readonly/valid
+ readonly_result = client.readonlyproperty.put_valid(valid_obj)
+ self.assertIsNone(readonly_result)
+
"""
COMPLEX TYPE WITH ARRAY PROPERTIES
"""
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py
index cc7fb8d0f5eb7..900265a4ed1fe 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py
@@ -53,24 +53,21 @@ class FileTests(unittest.TestCase):
def test_files(self):
config = AutoRestSwaggerBATFileServiceConfiguration(base_url="http://localhost:3000")
- config.log_level = log_level
config.connection.data_block_size = 1000
client = AutoRestSwaggerBATFileService(config)
- def test_callback(data, response, progress = [0], is_response_streamed=None):
+ def test_callback(data, response, progress=[0]):
self.assertTrue(len(data) > 0)
- if not is_response_streamed:
- self.assertFalse(response._content_consumed)
+ self.assertIsNotNone(response)
+ self.assertFalse(response._content_consumed)
+ total = float(response.headers['Content-Length'])
+ if total < 4096:
progress[0] += len(data)
- total = float(response.headers['Content-Length'])
print("Downloading... {}%".format(int(progress[0]*100/total)))
- self.assertIsNotNone(response)
file_length = 0
with io.BytesIO() as file_handle:
-
- stream = client.files.get_file(callback=lambda x, response, progress=[0] :
- test_callback(x, response, progress, False))
+ stream = client.files.get_file(callback=test_callback)
for data in stream:
file_length += len(data)
@@ -86,11 +83,10 @@ def test_callback(data, response, progress = [0], is_response_streamed=None):
sample_data = hash(data.read())
self.assertEqual(sample_data, hash(file_handle.getvalue()))
+ config.connection.data_block_size = 4096
file_length = 0
with io.BytesIO() as file_handle:
-
- stream = client.files.get_empty_file(callback=lambda x, response, progress=[0] :
- test_callback(x, response, progress, False))
+ stream = client.files.get_empty_file(callback=test_callback)
for data in stream:
file_length += len(data)
@@ -98,9 +94,12 @@ def test_callback(data, response, progress = [0], is_response_streamed=None):
self.assertEqual(file_length, 0)
- #file_length = 0
- #stream = client.files.get_file_large(callback=lambda x, response, progress=[0] :
- # test_callback(x, response, progress, True))
+ def add_headers(adapter, request, response, *args, **kwargs):
+ response.headers['Content-Length'] = str(3000 * 1024 * 1024)
+
+ file_length = 0
+ client._client.add_hook('response', add_headers)
+ stream = client.files.get_file_large(callback=test_callback)
#for data in stream:
# file_length += len(data)
@@ -108,24 +107,21 @@ def test_callback(data, response, progress = [0], is_response_streamed=None):
def test_files_raw(self):
- def test_callback(data, response, progress = [0], is_response_streamed=None):
+ def test_callback(data, response, progress=[0]):
self.assertTrue(len(data) > 0)
- if not is_response_streamed:
- self.assertFalse(response._content_consumed)
+ self.assertIsNotNone(response)
+ self.assertFalse(response._content_consumed)
+ total = float(response.headers.get('Content-Length', 0))
+ if total:
progress[0] += len(data)
- total = float(response.headers['Content-Length'])
print("Downloading... {}%".format(int(progress[0]*100/total)))
- self.assertIsNotNone(response)
config = AutoRestSwaggerBATFileServiceConfiguration(base_url="http://localhost:3000")
- config.log_level = log_level
client = AutoRestSwaggerBATFileService(config)
file_length = 0
with io.BytesIO() as file_handle:
-
- response = client.files.get_file(raw=True, callback=lambda x, response, progress=[0] :
- test_callback(x, response, progress, False))
+ response = client.files.get_file(raw=True, callback=test_callback)
stream = response.output
for data in stream:
@@ -144,9 +140,7 @@ def test_callback(data, response, progress = [0], is_response_streamed=None):
file_length = 0
with io.BytesIO() as file_handle:
-
- response = client.files.get_empty_file(raw=True, callback=lambda x, response, progress=[0] :
- test_callback(x, response, progress, False))
+ response = client.files.get_empty_file(raw=True, callback=test_callback)
stream = response.output
for data in stream:
@@ -155,16 +149,5 @@ def test_callback(data, response, progress = [0], is_response_streamed=None):
self.assertEqual(file_length, 0)
- #file_length = 0
- #response = client.files.get_file_large(raw=True, callback=lambda x, response, progress=[0] :
- # test_callback(x, response, progress, True))
-
- #stream = response.output
-
- #for data in stream:
- # file_length += len(data)
-
- #self.assertEqual(file_length, 3000 * 1024 * 1024)
-
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/form_data_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/form_data_tests.py
index f18bfdb92aa05..ea1ed1a726f9e 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/form_data_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/form_data_tests.py
@@ -174,7 +174,6 @@ def test_callback(data, response, progress = [0]):
with open(self.dummy_file, 'rb') as upload_data:
resp = client.formdata.upload_file_via_body(upload_data, callback=test_callback)
for r in resp:
- print(r)
result.write(r)
self.assertEqual(result.getvalue().decode(), "Test file")
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/url_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/url_tests.py
index 05f7b4dcdba4f..3204669e8568c 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/url_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/url_tests.py
@@ -90,8 +90,9 @@ def test_url_path(self):
self.client.paths.get_negative_ten_billion(-10000000000)
self.client.paths.get_ten_billion(10000000000)
self.client.paths.string_empty("")
- #test_array = ["ArrayPath1", r"begin!*'();:@ &=+$,/?#[]end", None, ""]
- #self.client.paths.array_csv_in_path(test_array)
+
+ test_array = ["ArrayPath1", r"begin!*'();:@ &=+$,/?#[]end", None, ""]
+ self.client.paths.array_csv_in_path(test_array)
with self.assertRaises(ValidationError):
self.client.paths.string_null(None)
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/validation_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/validation_tests.py
index 5af07d6773dbd..7e1ba54e0556e 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/validation_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/validation_tests.py
@@ -67,10 +67,7 @@ def test_constant_values(self):
client.get_with_constant_in_path()
- # TODO: Const body should be built implicitly
body = Product(child=ChildProduct())
- body.const_child = ConstantProduct()
-
product = client.post_with_constant_in_body(body=body)
self.assertIsNotNone(product)
@@ -121,7 +118,6 @@ def test_validation(self):
try:
tempproduct=Product(child=ChildProduct(), capacity=0)
- tempproduct.const_child=ConstantProduct()
client.validation_of_body("123", 150, tempproduct)
except ValidationError as err:
self.assertEqual(err.rule, "minimum_ex")
@@ -129,7 +125,6 @@ def test_validation(self):
try:
tempproduct=Product(child=ChildProduct(), capacity=100)
- tempproduct.const_child=ConstantProduct()
client.validation_of_body("123", 150, tempproduct)
except ValidationError as err:
self.assertEqual(err.rule, "maximum_ex")
@@ -138,7 +133,6 @@ def test_validation(self):
try:
tempproduct=Product(child=ChildProduct(),
display_names=["item1","item2","item3","item4","item5","item6","item7"])
- tempproduct.const_child=ConstantProduct()
client.validation_of_body("123", 150, tempproduct)
except ValidationError as err:
self.assertEqual(err.rule, "max_items")
@@ -155,4 +149,8 @@ def test_validation(self):
client2.validation_of_method_parameters("123", 150)
except ValidationError as err:
self.assertEqual(err.rule, "pattern")
- self.assertEqual(err.target, "self.config.api_version")
\ No newline at end of file
+ self.assertEqual(err.target, "self.config.api_version")
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/zzz_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/zzz_tests.py
index b54157497620c..2afd6aa9c3c70 100644
--- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/zzz_tests.py
+++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/zzz_tests.py
@@ -54,33 +54,37 @@ def test_ensure_coverage(self):
client = AutoRestReportService(config)
report = client.get_report()
- # These will not be supported in Python
- report['getIntegerOverflow']=1
- report['getIntegerUnderflow']=1
- report['getLongOverflow']=1
- report['getLongUnderflow']=1
- report['getDateInvalid']=1
- report['getDictionaryNullkey']=1
- report['HttpRedirect300Get']=1
-
- # TODO: Support large file streams
- report['FileStreamVeryLarge']=1
-
- # TODO: Support ignore readonly property in http put
- report['putComplexReadOnlyPropertyValid']=1
-
- skipped = [k for k, v in report.items() if v == 0]
- manually_marked_successful = [k for k, v in report.items() if v == 2]
- for s in manually_marked_successful:
- print("SKIPPED {0}".format(s))
-
- for s in skipped:
+ # Add tests that wont be supported due to the nature of Python here
+ not_supported = {
+ 'getIntegerOverflow': 1,
+ 'getIntegerUnderflow': 1,
+ 'getLongOverflow': 1,
+ 'getLongUnderflow': 1,
+ 'getDateInvalid': 1,
+ 'getDictionaryNullkey': 1,
+ 'HttpRedirect300Get': 1,
+ }
+
+ # Please add missing features or failing tests here
+ missing_features_or_bugs = {'FileStreamVeryLarge' : 1}
+
+ report.update(not_supported)
+ report.update(missing_features_or_bugs)
+ failed = [k for k, v in report.items() if v == 0]
+
+ for s in not_supported.keys():
+ print("IGNORING {0}".format(s))
+
+ for s in missing_features_or_bugs.keys():
+ print("PENDING {0}".format(s))
+
+ for s in failed:
print("FAILED TO EXECUTE {0}".format(s))
totalTests = len(report)
- print ("The test coverage is {0}/{1}.".format(totalTests - len(skipped), totalTests))
+ print ("The test coverage is {0}/{1}.".format(totalTests - len(failed), totalTests))
- self.assertEqual(0, len(skipped))
+ self.assertEqual(0, len(failed))
if __name__ == '__main__':
unittest.main()
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/auto_rest_complex_test_service.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/auto_rest_complex_test_service.py
index 8ff86db017bbd..3887687ac962c 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/auto_rest_complex_test_service.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/auto_rest_complex_test_service.py
@@ -38,7 +38,9 @@ def __init__(
self, api_version, base_url=None, filepath=None):
if api_version is None:
- raise ValueError('api_version must not be None.')
+ raise ValueError("Parameter 'api_version' must not be None.")
+ if not isinstance(api_version, str):
+ raise TypeError("Parameter 'api_version' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/models/readonly_obj.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/models/readonly_obj.py
index f0db42cc1b3f9..109d15efbe7e4 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/models/readonly_obj.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/BodyComplex/autorestcomplextestservice/models/readonly_obj.py
@@ -15,17 +15,24 @@
class ReadonlyObj(Model):
"""ReadonlyObj
- :param id:
- :type id: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id:
+ :vartype id: str
:param size:
:type size: int
"""
+ _validation = {
+ 'id': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'size': {'key': 'size', 'type': 'int'},
}
- def __init__(self, id=None, size=None):
- self.id = id
+ def __init__(self, size=None):
+ self.id = None
self.size = size
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
index 570afdaa95129..5839338b5a2d2 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUri/autorestparameterizedhosttestclient/auto_rest_parameterized_host_test_client.py
@@ -31,7 +31,9 @@ def __init__(
self, host, filepath=None):
if host is None:
- raise ValueError('host must not be None.')
+ raise ValueError("Parameter 'host' must not be None.")
+ if not isinstance(host, str):
+ raise TypeError("Parameter 'host' must be str.")
base_url = 'http://{accountName}{host}'
super(AutoRestParameterizedHostTestClientConfiguration, self).__init__(base_url, filepath)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/__init__.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/__init__.py
new file mode 100644
index 0000000000000..6711cf5b14df9
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/__init__.py
@@ -0,0 +1,21 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from .auto_rest_parameterized_custom_host_test_client import AutoRestParameterizedCustomHostTestClient, AutoRestParameterizedCustomHostTestClientConfiguration
+from .version import VERSION
+
+__all__ = [
+ 'AutoRestParameterizedCustomHostTestClient',
+ 'AutoRestParameterizedCustomHostTestClientConfiguration'
+]
+
+__version__ = VERSION
+
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/auto_rest_parameterized_custom_host_test_client.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/auto_rest_parameterized_custom_host_test_client.py
new file mode 100644
index 0000000000000..6a61d697f46ef
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/auto_rest_parameterized_custom_host_test_client.py
@@ -0,0 +1,73 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from msrest.service_client import ServiceClient
+from msrest import Configuration, Serializer, Deserializer
+from .version import VERSION
+from .operations.paths import Paths
+from . import models
+
+
+class AutoRestParameterizedCustomHostTestClientConfiguration(Configuration):
+ """Configuration for AutoRestParameterizedCustomHostTestClient
+ Note that all parameters used to create this instance are saved as instance
+ attributes.
+
+ :param subscription_id: The subscription id with value 'test12'.
+ :type subscription_id: str
+ :param dns_suffix: A string value that is used as a global part of the
+ parameterized host. Default value 'host'.
+ :type dns_suffix: str
+ :param str filepath: Existing config
+ """
+
+ def __init__(
+ self, subscription_id, dns_suffix, filepath=None):
+
+ if subscription_id is None:
+ raise ValueError("Parameter 'subscription_id' must not be None.")
+ if not isinstance(subscription_id, str):
+ raise TypeError("Parameter 'subscription_id' must be str.")
+ if dns_suffix is None:
+ raise ValueError("Parameter 'dns_suffix' must not be None.")
+ if not isinstance(dns_suffix, str):
+ raise TypeError("Parameter 'dns_suffix' must be str.")
+ base_url = '{vault}{secret}{dnsSuffix}'
+
+ super(AutoRestParameterizedCustomHostTestClientConfiguration, self).__init__(base_url, filepath)
+
+ self.add_user_agent('autorestparameterizedcustomhosttestclient/{}'.format(VERSION))
+
+ self.subscription_id = subscription_id
+ self.dns_suffix = dns_suffix
+
+
+class AutoRestParameterizedCustomHostTestClient(object):
+ """Test Infrastructure for AutoRest
+
+ :param config: Configuration for client.
+ :type config: AutoRestParameterizedCustomHostTestClientConfiguration
+
+ :ivar paths: Paths operations
+ :vartype paths: .operations.Paths
+ """
+
+ def __init__(self, config):
+
+ self._client = ServiceClient(None, config)
+
+ client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
+ self._serialize = Serializer()
+ self._deserialize = Deserializer(client_models)
+
+ self.config = config
+ self.paths = Paths(
+ self._client, self.config, self._serialize, self._deserialize)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/credentials.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/credentials.py
new file mode 100644
index 0000000000000..0d097b4f2a6cf
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/credentials.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from msrest.authentication import (
+ BasicAuthentication,
+ BasicTokenAuthentication,
+ OAuthTokenAuthentication)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/exceptions.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/exceptions.py
new file mode 100644
index 0000000000000..c3cc00226060c
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/exceptions.py
@@ -0,0 +1,21 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from msrest.exceptions import (
+ ClientException,
+ SerializationError,
+ DeserializationError,
+ TokenExpiredError,
+ ClientRequestError,
+ AuthenticationError,
+ HttpOperationError,
+ ValidationError,
+)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/__init__.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/__init__.py
new file mode 100644
index 0000000000000..fd6d517a47113
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/__init__.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from .error import Error, ErrorException
+
+__all__ = [
+ 'Error', 'ErrorException',
+]
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/error.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/error.py
new file mode 100644
index 0000000000000..c2d19e377e004
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/models/error.py
@@ -0,0 +1,44 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from msrest.serialization import Model
+from msrest.exceptions import HttpOperationError
+
+
+class Error(Model):
+ """Error
+
+ :param status:
+ :type status: int
+ :param message:
+ :type message: str
+ """
+
+ _attribute_map = {
+ 'status': {'key': 'status', 'type': 'int'},
+ 'message': {'key': 'message', 'type': 'str'},
+ }
+
+ def __init__(self, status=None, message=None):
+ self.status = status
+ self.message = message
+
+
+class ErrorException(HttpOperationError):
+ """Server responsed with exception of type: 'Error'.
+
+ :param deserialize: A deserializer
+ :param response: Server response to be deserialized.
+ """
+
+ def __init__(self, deserialize, response, *args):
+
+ super(ErrorException, self).__init__(deserialize, response, 'Error', *args)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/__init__.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/__init__.py
new file mode 100644
index 0000000000000..fa4a82a28df55
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/__init__.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from .paths import Paths
+
+__all__ = [
+ 'Paths',
+]
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/paths.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/paths.py
new file mode 100644
index 0000000000000..2c43f455f742d
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/operations/paths.py
@@ -0,0 +1,87 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+from msrest.pipeline import ClientRawResponse
+
+from .. import models
+
+
+class Paths(object):
+ """Paths operations.
+
+ :param client: Client for service requests.
+ :param config: Configuration of service client.
+ :param serializer: An object model serializer.
+ :param deserializer: An objec model deserializer.
+ """
+
+ def __init__(self, client, config, serializer, deserializer):
+
+ self._client = client
+ self._serialize = serializer
+ self._deserialize = deserializer
+
+ self.config = config
+
+ def get_empty(
+ self, vault, secret, key_name, key_version="v1", custom_headers={}, raw=False, **operation_config):
+ """
+ Get a 200 to test a valid base uri
+
+ :param vault: The vault name, e.g. https://myvault
+ :type vault: str
+ :param secret: Secret value.
+ :type secret: str
+ :param key_name: The key name with value 'key1'.
+ :type key_name: str
+ :param key_version: The key version. Default value 'v1'.
+ :type key_version: str
+ :param dict custom_headers: headers that will be added to the request
+ :param bool raw: returns the direct response alongside the
+ deserialized response
+ :param operation_config: :ref:`Operation configuration
+ overrides`.
+ :rtype: None
+ :rtype: :class:`ClientRawResponse`
+ if raw=true
+ """
+ # Construct URL
+ url = '/customuri/{subscriptionId}/{keyName}'
+ path_format_arguments = {
+ 'vault': self._serialize.url("vault", vault, 'str', skip_quote=True),
+ 'secret': self._serialize.url("secret", secret, 'str', skip_quote=True),
+ 'dnsSuffix': self._serialize.url("self.config.dns_suffix", self.config.dns_suffix, 'str', skip_quote=True),
+ 'keyName': self._serialize.url("key_name", key_name, 'str'),
+ 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
+ }
+ url = self._client.format_url(url, **path_format_arguments)
+
+ # Construct parameters
+ query_parameters = {}
+ if key_version is not None:
+ query_parameters['keyVersion'] = self._serialize.query("key_version", key_version, 'str')
+
+ # Construct headers
+ header_parameters = {}
+ header_parameters['Content-Type'] = 'application/json; charset=utf-8'
+ if custom_headers:
+ header_parameters.update(custom_headers)
+
+ # Construct and send request
+ request = self._client.get(url, query_parameters)
+ response = self._client.send(request, header_parameters, **operation_config)
+
+ if response.status_code not in [200]:
+ raise models.ErrorException(self._deserialize, response)
+
+ if raw:
+ client_raw_response = ClientRawResponse(None, response)
+ return client_raw_response
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/version.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/version.py
new file mode 100644
index 0000000000000..a39916c162cec
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/autorestparameterizedcustomhosttestclient/version.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+
+VERSION = "1.0.0"
+
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py
new file mode 100644
index 0000000000000..3521fb6abef92
--- /dev/null
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py
@@ -0,0 +1,40 @@
+# coding=utf-8
+# --------------------------------------------------------------------------
+# 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.
+# --------------------------------------------------------------------------
+# coding: utf-8
+
+from setuptools import setup, find_packages
+
+NAME = "autorestparameterizedcustomhosttestclient"
+VERSION = "1.0.0"
+
+# To install the library, run the following
+#
+# python setup.py install
+#
+# prerequisite: setuptools
+# http://pypi.python.org/pypi/setuptools
+
+REQUIRES = ["msrest>=0.2.0"]
+
+setup(
+ name=NAME,
+ version=VERSION,
+ description="AutoRestParameterizedCustomHostTestClient",
+ author_email="",
+ url="",
+ keywords=["Swagger", "AutoRestParameterizedCustomHostTestClient"],
+ install_requires=REQUIRES,
+ packages=find_packages(),
+ include_package_data=True,
+ long_description="""\
+ Test Infrastructure for AutoRest
+ """
+)
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py
index 99e49b9aa384f..55df7eedae364 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py
@@ -15,28 +15,38 @@
class FlattenedProduct(Resource):
"""FlattenedProduct
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
:param pname:
:type pname: str
:param flattened_product_type:
:type flattened_product_type: str
- :param provisioning_state_values: Possible values include: 'Succeeded',
+ :ivar provisioning_state_values: Possible values include: 'Succeeded',
'Failed', 'canceled', 'Accepted', 'Creating', 'Created', 'Updating',
'Updated', 'Deleting', 'Deleted', 'OK'
- :type provisioning_state_values: str
+ :vartype provisioning_state_values: str
:param provisioning_state:
:type provisioning_state: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ 'provisioning_state_values': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -49,9 +59,9 @@ class FlattenedProduct(Resource):
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None, pname=None, flattened_product_type=None, provisioning_state_values=None, provisioning_state=None):
- super(FlattenedProduct, self).__init__(id=id, type=type, tags=tags, location=location, name=name)
+ def __init__(self, tags=None, location=None, pname=None, flattened_product_type=None, provisioning_state=None):
+ super(FlattenedProduct, self).__init__(tags=tags, location=location)
self.pname = pname
self.flattened_product_type = flattened_product_type
- self.provisioning_state_values = provisioning_state_values
+ self.provisioning_state_values = None
self.provisioning_state = provisioning_state
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/resource.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/resource.py
index ccc46d79f60ce..349e6b7fbd717 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/resource.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/resource.py
@@ -15,18 +15,27 @@
class Resource(Model):
"""Resource
- :param id: Resource Id
- :type id: str
- :param type: Resource Type
- :type type: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar id: Resource Id
+ :vartype id: str
+ :ivar type: Resource Type
+ :vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
- :param name: Resource Name
- :type name: str
+ :ivar name: Resource Name
+ :vartype name: str
"""
+ _validation = {
+ 'id': {'readonly': True},
+ 'type': {'readonly': True},
+ 'name': {'readonly': True},
+ }
+
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
@@ -35,9 +44,9 @@ class Resource(Model):
'name': {'key': 'name', 'type': 'str'},
}
- def __init__(self, id=None, type=None, tags=None, location=None, name=None):
- self.id = id
- self.type = type
+ def __init__(self, tags=None, location=None):
+ self.id = None
+ self.type = None
self.tags = tags
self.location = location
- self.name = name
+ self.name = None
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/simple_product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/simple_product.py
index 1be642054ecac..02537d1797c79 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/simple_product.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/simple_product.py
@@ -16,6 +16,9 @@ class SimpleProduct(BaseProduct):
"""
The product documentation.
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
:param product_id: Unique identifier representing a specific product for
a given latitude & longitude. For example, uberX in San Francisco will
have a different product_id than uberX in Los Angeles.
@@ -24,9 +27,9 @@ class SimpleProduct(BaseProduct):
:type description: str
:param max_product_display_name: Display name of product.
:type max_product_display_name: str
- :param capacity: Capacity of product. For example, 4 people. Default
+ :ivar capacity: Capacity of product. For example, 4 people. Default
value: "Large" .
- :type capacity: str
+ :vartype capacity: str
:param generic_value: Generic URL value.
:type generic_value: str
:param odatavalue: URL value.
@@ -48,9 +51,10 @@ class SimpleProduct(BaseProduct):
'odatavalue': {'key': 'details.max_product_image.@odata\\.value', 'type': 'str'},
}
+ capacity = "Large"
+
def __init__(self, product_id, max_product_display_name, description=None, generic_value=None, odatavalue=None):
super(SimpleProduct, self).__init__(product_id=product_id, description=description)
self.max_product_display_name = max_product_display_name
- self.capacity = "Large"
self.generic_value = generic_value
self.odatavalue = odatavalue
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/RequiredOptional/autorestrequiredoptionaltestservice/auto_rest_required_optional_test_service.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/RequiredOptional/autorestrequiredoptionaltestservice/auto_rest_required_optional_test_service.py
index d9a36a8ffd5b0..7dcce131d92ad 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/RequiredOptional/autorestrequiredoptionaltestservice/auto_rest_required_optional_test_service.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/RequiredOptional/autorestrequiredoptionaltestservice/auto_rest_required_optional_test_service.py
@@ -36,9 +36,13 @@ def __init__(
self, required_global_path, required_global_query, optional_global_query=None, base_url=None, filepath=None):
if required_global_path is None:
- raise ValueError('required_global_path must not be None.')
+ raise ValueError("Parameter 'required_global_path' must not be None.")
+ if not isinstance(required_global_path, str):
+ raise TypeError("Parameter 'required_global_path' must be str.")
if required_global_query is None:
- raise ValueError('required_global_query must not be None.')
+ raise ValueError("Parameter 'required_global_query' must not be None.")
+ if not isinstance(required_global_query, str):
+ raise TypeError("Parameter 'required_global_query' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/auto_rest_url_test_service.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/auto_rest_url_test_service.py
index 31c1880929875..34efde192fd6b 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/auto_rest_url_test_service.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/auto_rest_url_test_service.py
@@ -36,7 +36,11 @@ def __init__(
self, global_string_path, global_string_query=None, base_url=None, filepath=None):
if global_string_path is None:
- raise ValueError('global_string_path must not be None.')
+ raise ValueError("Parameter 'global_string_path' must not be None.")
+ if not isinstance(global_string_path, str):
+ raise TypeError("Parameter 'global_string_path' must be str.")
+ if global_string_query is not None and not isinstance(global_string_query, str):
+ raise TypeError("Optional parameter 'global_string_query' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/operations/paths.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/operations/paths.py
index 46bface0d9375..97cd8878c0e6a 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/operations/paths.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Url/autoresturltestservice/operations/paths.py
@@ -1089,7 +1089,7 @@ def array_csv_in_path(
if raw=true
"""
# Construct URL
- url = '/paths/array/ArrayPath1%2cbegin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend%2c%2c/{arrayPath:commaSeparated}'
+ url = '/paths/array/ArrayPath1%2cbegin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend%2c%2c/{arrayPath}'
path_format_arguments = {
'arrayPath': self._serialize.url("array_path", array_path, '[str]', div=',')
}
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/auto_rest_validation_test.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/auto_rest_validation_test.py
index 7fd4093d00b6e..f9a6b88ede469 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/auto_rest_validation_test.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/auto_rest_validation_test.py
@@ -34,9 +34,13 @@ def __init__(
self, subscription_id, api_version, base_url=None, filepath=None):
if subscription_id is None:
- raise ValueError('subscription_id must not be None.')
+ raise ValueError("Parameter 'subscription_id' must not be None.")
+ if not isinstance(subscription_id, str):
+ raise TypeError("Parameter 'subscription_id' must be str.")
if api_version is None:
- raise ValueError('api_version must not be None.')
+ raise ValueError("Parameter 'api_version' must not be None.")
+ if not isinstance(api_version, str):
+ raise TypeError("Parameter 'api_version' must be str.")
if not base_url:
base_url = 'http://localhost'
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/child_product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/child_product.py
index e7270ddf47641..0ef944dd8e9ca 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/child_product.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/child_product.py
@@ -16,8 +16,11 @@ class ChildProduct(Model):
"""
The product documentation.
- :param const_property: Constant string. Default value: "constant" .
- :type const_property: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar const_property: Constant string. Default value: "constant" .
+ :vartype const_property: str
:param count: Count
:type count: int
"""
@@ -31,6 +34,7 @@ class ChildProduct(Model):
'count': {'key': 'count', 'type': 'int'},
}
+ const_property = "constant"
+
def __init__(self, count=None):
- self.const_property = "constant"
self.count = count
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/constant_product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/constant_product.py
index 14f416cef6f00..cb4531c4ec1aa 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/constant_product.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/constant_product.py
@@ -16,10 +16,13 @@ class ConstantProduct(Model):
"""
The product documentation.
- :param const_property: Constant string. Default value: "constant" .
- :type const_property: str
- :param const_property2: Constant string2. Default value: "constant2" .
- :type const_property2: str
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
+ :ivar const_property: Constant string. Default value: "constant" .
+ :vartype const_property: str
+ :ivar const_property2: Constant string2. Default value: "constant2" .
+ :vartype const_property2: str
"""
_validation = {
@@ -32,6 +35,6 @@ class ConstantProduct(Model):
'const_property2': {'key': 'constProperty2', 'type': 'str'},
}
- def __init__(self):
- self.const_property = "constant"
- self.const_property2 = "constant2"
+ const_property = "constant"
+
+ const_property2 = "constant2"
diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/product.py
index c9577fa07f23d..65d49c5d12e17 100644
--- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/product.py
+++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/Validation/autorestvalidationtest/models/product.py
@@ -9,6 +9,7 @@
# regenerated.
# --------------------------------------------------------------------------
+from .constant_product import ConstantProduct
from msrest.serialization import Model
@@ -16,6 +17,9 @@ class Product(Model):
"""
The product documentation.
+ Variables are only populated by the server, and will be ignored when
+ sending a request.
+
:param display_names: Non required array of unique items from 0 to 6
elements.
:type display_names: list of str
@@ -26,13 +30,13 @@ class Product(Model):
:param child:
:type child: :class:`ChildProduct
`
- :param const_child:
- :type const_child: :class:`ConstantProduct
+ :ivar const_child:
+ :vartype const_child: :class:`ConstantProduct
`
- :param const_int: Constant int. Default value: 0 .
- :type const_int: int
- :param const_string: Constant string. Default value: "constant" .
- :type const_string: str
+ :ivar const_int: Constant int. Default value: 0 .
+ :vartype const_int: int
+ :ivar const_string: Constant string. Default value: "constant" .
+ :vartype const_string: str
:param const_string_as_enum: Constant string as Enum. Possible values
include: 'constant_string_as_enum'
:type const_string_as_enum: str
@@ -59,12 +63,15 @@ class Product(Model):
'const_string_as_enum': {'key': 'constStringAsEnum', 'type': 'EnumConst'},
}
+ const_child = ConstantProduct()
+
+ const_int = 0
+
+ const_string = "constant"
+
def __init__(self, child, display_names=None, capacity=None, image=None, const_string_as_enum=None):
self.display_names = display_names
self.capacity = capacity
self.image = image
self.child = child
- self.const_child = None
- self.const_int = 0
- self.const_string = "constant"
self.const_string_as_enum = const_string_as_enum
diff --git a/AutoRest/Generators/Python/Python.Tests/Python.Tests.pyproj b/AutoRest/Generators/Python/Python.Tests/Python.Tests.pyproj
index 551692fe3e198..b6cfb6ea96c3e 100644
--- a/AutoRest/Generators/Python/Python.Tests/Python.Tests.pyproj
+++ b/AutoRest/Generators/Python/Python.Tests/Python.Tests.pyproj
@@ -125,6 +125,10 @@
+
+
+
+
diff --git a/AutoRest/Generators/Python/Python/PythonCodeNamer.cs b/AutoRest/Generators/Python/Python/PythonCodeNamer.cs
index 4aebfb6378a11..11ae0801acce4 100644
--- a/AutoRest/Generators/Python/Python/PythonCodeNamer.cs
+++ b/AutoRest/Generators/Python/Python/PythonCodeNamer.cs
@@ -376,6 +376,10 @@ private static IType NormalizePrimaryType(PrimaryType primaryType)
{
primaryType.Name = "Decimal";
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ primaryType.Name = "long";
+ }
else if (primaryType.Type == KnownPrimaryType.Object) // Revisit here
{
primaryType.Name = "object";
diff --git a/AutoRest/Generators/Python/Python/TemplateModels/MethodTemplateModel.cs b/AutoRest/Generators/Python/Python/TemplateModels/MethodTemplateModel.cs
index 5c47e7be1f83c..ee71dc5b08b4d 100644
--- a/AutoRest/Generators/Python/Python/TemplateModels/MethodTemplateModel.cs
+++ b/AutoRest/Generators/Python/Python/TemplateModels/MethodTemplateModel.cs
@@ -6,6 +6,7 @@
using System.Globalization;
using System.Linq;
using System.Net;
+using System.Text.RegularExpressions;
using Microsoft.Rest.Generator.ClientModel;
using Microsoft.Rest.Generator.Python.TemplateModels;
using Microsoft.Rest.Generator.Utilities;
@@ -31,6 +32,19 @@ public MethodTemplateModel(Method source, ServiceClient serviceClient)
OperationName = serviceClient.Name;
}
AddCustomHeader = true;
+ string formatter;
+ foreach (var parameter in LocalParameters)
+ {
+ if (string.IsNullOrWhiteSpace(parameter.DefaultValue))
+ {
+ parameter.DefaultValue = PythonConstants.None;
+ }
+ }
+ foreach (Match m in Regex.Matches(Url, @"\{[\w]+:[\w]+\}"))
+ {
+ formatter = m.Value.Split(':').First() + '}';
+ Url = Url.Replace(m.Value, formatter);
+ }
}
public bool AddCustomHeader { get; private set; }
@@ -151,7 +165,7 @@ public virtual string MethodParameterDeclaration(bool addCustomHeaderParameters)
foreach (var parameter in LocalParameters)
{
- if (parameter.IsRequired && parameter.DefaultValue.Equals(PythonConstants.None))
+ if (parameter.IsRequired && parameter.DefaultValue == PythonConstants.None)
{
requiredDeclarations.Add(parameter.Name);
}
diff --git a/AutoRest/Generators/Python/Python/TemplateModels/ModelTemplateModel.cs b/AutoRest/Generators/Python/Python/TemplateModels/ModelTemplateModel.cs
index dbd8fd040ff5f..2c43e7c092ca7 100644
--- a/AutoRest/Generators/Python/Python/TemplateModels/ModelTemplateModel.cs
+++ b/AutoRest/Generators/Python/Python/TemplateModels/ModelTemplateModel.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using System.Text;
using Microsoft.Rest.Generator.ClientModel;
using Microsoft.Rest.Generator.Python.TemplateModels;
using Microsoft.Rest.Generator.Utilities;
@@ -48,6 +49,14 @@ public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
_parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
}
+ foreach (var property in ComposedProperties)
+ {
+ if (string.IsNullOrWhiteSpace(property.DefaultValue))
+ {
+ property.DefaultValue = PythonConstants.None;
+ }
+ }
+
if (this.IsPolymorphic)
{
foreach (var modelType in ServiceClient.ModelTypes)
@@ -104,6 +113,10 @@ public IList Validators
{
validation.Add("'constant': True");
}
+ if (parameter.IsReadOnly)
+ {
+ validation.Add("'readonly': True");
+ }
if (parameter.Constraints.Any())
{
validation.AddRange(BuildValidationParameters(parameter.Constraints));
@@ -190,6 +203,22 @@ public bool HasParent
get { return this._parent != null; }
}
+ public bool NeedsConstructor
+ {
+ get
+ {
+ var nonConstant = Properties.Where(p => !p.IsConstant);
+ if (nonConstant.Any())
+ {
+ return true;
+ }
+ else
+ {
+ return (HasParent || NeedsPolymorphicConverter);
+ }
+ }
+ }
+
///
/// Provides the modelProperty documentation string along with default value if any.
///
@@ -202,11 +231,14 @@ public static string GetPropertyDocumentationString(Property property)
{
throw new ArgumentNullException("property");
}
-
string docString = string.Format(CultureInfo.InvariantCulture, ":param {0}:", property.Name);
-
+ if (property.IsConstant || property.IsReadOnly)
+ {
+ docString = string.Format(CultureInfo.InvariantCulture, ":ivar {0}:", property.Name);
+ }
+
string documentation = property.Documentation;
- if (!string.IsNullOrWhiteSpace(property.DefaultValue) && property.DefaultValue != PythonConstants.None)
+ if (property.DefaultValue != PythonConstants.None)
{
if (documentation != null && !documentation.EndsWith(".", StringComparison.OrdinalIgnoreCase))
{
@@ -243,16 +275,43 @@ public IList RequiredFieldsList
}
}
+ public IEnumerable ReadOnlyAttributes
+ {
+ get
+ {
+ return ComposedProperties.Where(p => p.IsConstant || p.IsReadOnly);
+ }
+ }
+
+ public IDictionary ComplexConstants
+ {
+ get
+ {
+ Dictionary complexConstant = new Dictionary ();
+ foreach (var property in Properties)
+ {
+ if (property.IsConstant)
+ {
+ CompositeType compType = property.Type as CompositeType;
+ if (compType != null)
+ {
+ complexConstant[property.Name] = compType;
+ }
+ }
+ }
+ return complexConstant;
+ }
+ }
+
public virtual string SuperParameterDeclaration()
{
List combinedDeclarations = new List();
- foreach (var property in ComposedProperties.Except(Properties))
+ foreach (var property in ComposedProperties.Except(Properties).Except(ReadOnlyAttributes))
{
if (this.IsPolymorphic)
if (property.Name == this.BasePolymorphicDiscriminator)
continue;
-
combinedDeclarations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={0}", property.Name));
}
return string.Join(", ", combinedDeclarations);
@@ -264,17 +323,13 @@ public virtual string MethodParameterDeclaration()
List requiredDeclarations = new List();
List combinedDeclarations = new List();
- foreach (var property in ComposedProperties)
+ foreach (var property in ComposedProperties.Except(ReadOnlyAttributes))
{
if (this.IsPolymorphic)
if (property.Name == this.BasePolymorphicDiscriminator)
continue;
- if (property.IsConstant)
- {
- continue;
- }
- if (property.IsRequired && property.DefaultValue.Equals(PythonConstants.None))
+ if (property.IsRequired && property.DefaultValue == PythonConstants.None)
{
requiredDeclarations.Add(property.Name);
}
@@ -363,9 +418,20 @@ public string InitializeProperty(string objectName, Property property)
{
throw new ArgumentNullException("property");
}
+ if (property.IsReadOnly)
+ {
+ return string.Format(CultureInfo.InvariantCulture, "{0}.{1} = None", objectName, property.Name);
+ }
if (property.IsConstant)
{
- return string.Format(CultureInfo.InvariantCulture, "{0}.{1} = {2}", objectName, property.Name, property.DefaultValue);
+ if (ComplexConstants.ContainsKey(property.Name))
+ {
+ return string.Format(CultureInfo.InvariantCulture, "{0} = {1}()", property.Name, property.Type.Name);
+ }
+ else
+ {
+ return string.Format(CultureInfo.InvariantCulture, "{0} = {1}", property.Name, property.DefaultValue);
+ }
}
if (IsPolymorphic)
{
diff --git a/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs b/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs
index 4eb487cdfdee5..60629ea26ca28 100644
--- a/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs
+++ b/AutoRest/Generators/Python/Python/TemplateModels/ServiceClientTemplateModel.cs
@@ -105,7 +105,10 @@ public virtual string RequiredConstructorParameters
}
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ValueError"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ValueError"),
+ System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "TypeError"),
+ System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "str"),
+ System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)")]
public virtual string ValidateRequiredParameters
{
get
@@ -118,9 +121,31 @@ public virtual string ValidateRequiredParameters
builder.
AppendFormat("if {0} is None:", property.Name.ToPythonCase()).AppendLine().
Indent().
- AppendLine(string.Format(CultureInfo.InvariantCulture, "raise ValueError('{0} must not be None.')", property.Name.ToPythonCase())).
+ AppendLine(string.Format(CultureInfo.InvariantCulture, "raise ValueError(\"Parameter '{0}' must not be None.\")", property.Name.ToPythonCase())).
Outdent();
+ if (property.Type.IsPrimaryType(KnownPrimaryType.String))
+ {
+ builder.
+ AppendFormat("if not isinstance({0}, str):", property.Name.ToPythonCase()).AppendLine().
+ Indent().
+ AppendLine(string.Format(CultureInfo.InvariantCulture, "raise TypeError(\"Parameter '{0}' must be str.\")", property.Name.ToPythonCase())).
+ Outdent();
+ }
}
+ else
+ {
+ if (property.Type.IsPrimaryType(KnownPrimaryType.String))
+ {
+ builder.
+ AppendFormat("if {0} is not None and not isinstance({0}, str):", property.Name.ToPythonCase()).AppendLine().
+ Indent().
+ AppendLine(string.Format(CultureInfo.InvariantCulture, "raise TypeError(\"Optional parameter '{0}' must be str.\")", property.Name.ToPythonCase())).
+ Outdent();
+ }
+
+ }
+
+
}
return builder.ToString();
}
diff --git a/AutoRest/Generators/Python/Python/Templates/ModelTemplate.cshtml b/AutoRest/Generators/Python/Python/Templates/ModelTemplate.cshtml
index 40ee94f75cb4b..17e86079f9cfd 100644
--- a/AutoRest/Generators/Python/Python/Templates/ModelTemplate.cshtml
+++ b/AutoRest/Generators/Python/Python/Templates/ModelTemplate.cshtml
@@ -11,6 +11,13 @@
@Header("# ").TrimMultilineHeader()
# --------------------------------------------------------------------------
@EmptyLine
+@if(Model.ComplexConstants.Any())
+{
+ foreach(var property in Model.ComplexConstants.Values)
+ {
+@:from .@property.Name.ToPythonCase() import @property.Name
+ }
+}
@if (Model.BaseModelType != null)
{
@:from .@Model.BaseModelType.Name.ToPythonCase() import @Model.BaseModelType.Name
@@ -42,14 +49,26 @@ else
{
@: """@(Model.Name)
}
+@if (Model.ReadOnlyAttributes.Any())
+{
+@EmptyLine
+@: @WrapComment(string.Empty, "Variables are only populated by the server, and will be ignored when sending a request.")
+}
@if (Model.ComposedProperties.Any())
{
@EmptyLine
- foreach (var property in Model.ComposedProperties)
- {
+ foreach (var property in Model.ComposedProperties)
+ {
@: @ParameterWrapComment(string.Empty, ModelTemplateModel.GetPropertyDocumentationString(property))
+ if (property.IsConstant || property.IsReadOnly)
+ {
+@: @ParameterWrapComment(string.Empty, ":vartype " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type))
+ }
+ else
+ {
@: @ParameterWrapComment(string.Empty, ":type " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type))
- }
+ }
+ }
}
"""
@if (Model.Validators.Any() || Model.RequiredFieldsList.Any())
@@ -89,26 +108,37 @@ else
}
}
-@EmptyLine
- def __init__(self@(Model.MethodParameterDeclaration())):
-@if (Model.HasParent)
+@foreach(var property in Model.Properties)
{
- @:super(@(Model.Name), self).__init__(@(Model.SuperParameterDeclaration()))
+ if (property.IsConstant)
+ {
+@EmptyLine
+ @:@(Model.InitializeProperty(String.Empty, property))
+ }
}
-@{
- var propertyList = new List(Model.Properties);
- if (propertyList.Count > 0)
- {
- for (int i = 0; i < propertyList.Count; i++)
- {
+@if (Model.NeedsConstructor)
+{
+@EmptyLine
+ @:def __init__(self@(Model.MethodParameterDeclaration())):
+ if (Model.HasParent)
+ {
+ @:super(@(Model.Name), self).__init__(@(Model.SuperParameterDeclaration()))
+ }
+ var propertyList = new List(Model.Properties);
+ if (propertyList.Count > 0)
+ {
+ for (int i = 0; i < propertyList.Count; i++)
+ {
+ if (!propertyList[i].IsConstant)
+ {
@:@(Model.InitializeProperty("self", propertyList[i]))
- }
+ }
+ }
}
-}
-
-@if (Model.NeedsPolymorphicConverter)
-{
+ if (Model.NeedsPolymorphicConverter)
+ {
@:self.@Model.BasePolymorphicDiscriminator = '@Model.SerializedName'
+ }
}
@if (Model.IsException)
{
diff --git a/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs b/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs
index bcb90309c677e..c40423ee1b4ae 100644
--- a/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs
+++ b/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs
@@ -372,6 +372,10 @@ private IType NormalizePrimaryType(PrimaryType primaryType)
{
primaryType.Name = "Duration";
}
+ else if (primaryType.Type == KnownPrimaryType.UnixTime)
+ {
+ primaryType.Name = "Bignum";
+ }
else if (primaryType.Type == KnownPrimaryType.Object)
{
primaryType.Name = "Object";
diff --git a/AutoRest/Modelers/Swagger/CollectionFormatBuilder.cs b/AutoRest/Modelers/Swagger/CollectionFormatBuilder.cs
index edfba8a2c1340..f9ee08f3c57f6 100644
--- a/AutoRest/Modelers/Swagger/CollectionFormatBuilder.cs
+++ b/AutoRest/Modelers/Swagger/CollectionFormatBuilder.cs
@@ -80,7 +80,7 @@ private static void AddCollectionFormat(SwaggerParameter swaggerParameter, Strin
break;
case CollectionFormat.Multi:
- // TODO multi is not supported yet: http://vstfrd:8080/Azure/RD/_workitems/edit/3172867
+ // TODO multi is not supported yet: https://github.com/Azure/autorest/issues/717
throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture,
Resources.MultiCollectionFormatNotSupported,
swaggerParameter.Name));
diff --git a/AutoRest/Modelers/Swagger/Model/SwaggerObject.cs b/AutoRest/Modelers/Swagger/Model/SwaggerObject.cs
index 2ca86ef10d3e1..02bfb0d23b8bc 100644
--- a/AutoRest/Modelers/Swagger/Model/SwaggerObject.cs
+++ b/AutoRest/Modelers/Swagger/Model/SwaggerObject.cs
@@ -132,6 +132,10 @@ public PrimaryType ToType()
{
return new PrimaryType(KnownPrimaryType.Long);
}
+ if (string.Equals("unixtime", Format, StringComparison.OrdinalIgnoreCase))
+ {
+ return new PrimaryType(KnownPrimaryType.UnixTime);
+ }
return new PrimaryType(KnownPrimaryType.Int);
case DataType.Boolean:
return new PrimaryType(KnownPrimaryType.Boolean);
diff --git a/AutoRest/TestServer/server/app.js b/AutoRest/TestServer/server/app.js
index f0da0d60682c8..9453e73965c22 100644
--- a/AutoRest/TestServer/server/app.js
+++ b/AutoRest/TestServer/server/app.js
@@ -195,15 +195,6 @@ var coverage = {
"getStringWithLeadingAndTrailingWhitespace" : 0,
"putStringWithLeadingAndTrailingWhitespace" : 0,
"getStringNotProvided": 0,
- /* TODO: only C# and node.js support the base64url format currently. Exclude these tests from code coverage until it is implemented in other languages */
- "getStringBase64Encoded": 1,
- "getStringBase64UrlEncoded": 1,
- "putStringBase64UrlEncoded": 1,
- "getStringNullBase64UrlEncoding": 1,
- "getArrayBase64Url": 1,
- "getDictionaryBase64Url": 1,
- "UrlPathsStringBase64Url": 1,
- "UrlPathsArrayCSVInPath": 1,
"getEnumNotExpandable": 0,
"putEnumNotExpandable":0,
"putComplexBasicValid": 0,
@@ -428,6 +419,8 @@ var coverage = {
"ConstantsInPath": 0,
"ConstantsInBody": 0,
"CustomBaseUri": 0,
+ //Once all the languages implement this test, the scenario counter should be reset to zero. It is currently implemented in C# and node.js
+ "CustomBaseUriMoreOptions": 1,
'getModelFlattenArray': 0,
'putModelFlattenArray': 0,
'getModelFlattenDictionary': 0,
@@ -436,7 +429,22 @@ var coverage = {
'putModelFlattenResourceCollection': 0,
'putModelFlattenCustomBase': 0,
'postModelFlattenCustomParameter': 0,
- 'putModelFlattenCustomGroupedParameter': 0
+ 'putModelFlattenCustomGroupedParameter': 0,
+ /* TODO: only C# and node.js support the base64url format currently. Exclude these tests from code coverage until it is implemented in other languages */
+ "getStringBase64Encoded": 1,
+ "getStringBase64UrlEncoded": 1,
+ "putStringBase64UrlEncoded": 1,
+ "getStringNullBase64UrlEncoding": 1,
+ "getArrayBase64Url": 1,
+ "getDictionaryBase64Url": 1,
+ "UrlPathsStringBase64Url": 1,
+ "UrlPathsArrayCSVInPath": 1,
+ /* TODO: only C# supports the unixtime format currently. Exclude these tests from code coverage until it is implemented in other languages */
+ "getUnixTime": 1,
+ "getInvalidUnixTime": 1,
+ "getNullUnixTime": 1,
+ "putUnixTime": 1,
+ "UrlPathsIntUnixTime": 1
};
// view engine setup
diff --git a/AutoRest/TestServer/server/routes/customUri.js b/AutoRest/TestServer/server/routes/customUri.js
index 2eee79cadfc33..85d074cdeceb2 100644
--- a/AutoRest/TestServer/server/routes/customUri.js
+++ b/AutoRest/TestServer/server/routes/customUri.js
@@ -9,6 +9,17 @@ var specials = function (coverage) {
coverage['CustomBaseUri']++;
res.status(200).end();
});
+
+ router.get('/:subscriptionId/:keyName', function (req, res, next) {
+ if (req.params.subscriptionId === 'test12' && req.params.keyName === 'key1'
+ && Object.keys(req.query).length == 1 && req.query.keyVersion === 'v1') {
+ coverage['CustomBaseUriMoreOptions']++;
+ res.status(200).end();
+ } else {
+ utils.send400(res, next, 'Either one of the path parameters (subscriptionId=test12, keyName=key1) or query parameter (keyVersion=v1) did not match. ' +
+ 'Received parameters are: subscriptionId ' + subscriptionId + ', keyName ' + keyName + ', keyVersion ' + keyVersion);
+ }
+ });
}
specials.prototype.router = router;
diff --git a/AutoRest/TestServer/server/routes/int.js b/AutoRest/TestServer/server/routes/int.js
index 2299732ca5ad1..f4acbd7104cd2 100644
--- a/AutoRest/TestServer/server/routes/int.js
+++ b/AutoRest/TestServer/server/routes/int.js
@@ -65,10 +65,27 @@ var integer = function(coverage) {
} else if (req.params.scenario === 'underflowint64') {
coverage['getLongUnderflow']++;
res.status(200).end('-9223372036854775910');
+ } else if (req.params.scenario === 'unixtime') {
+ coverage['getUnixTime']++;
+ res.status(200).end('1460505600');
+ } else if (req.params.scenario === 'invalidunixtime') {
+ coverage['getInvalidUnixTime']++;
+ res.status(200).end('123jkl');
+ } else if (req.params.scenario === 'nullunixtime') {
+ coverage['getNullUnixTime']++;
+ res.status(200).end();
} else {
res.status(400).send('Request path must contain true or false');
}
-
+ });
+
+ router.put('/unixtime', function(req, res, next) {
+ if (req.body != 1460505600) {
+ utils.send400(res, next, "Did not like the value provided for unixtime in the req " + util.inspect(req.body));
+ } else {
+ coverage['putUnixTime']++;
+ res.status(200).end();
+ }
});
}
diff --git a/AutoRest/TestServer/server/routes/lros.js b/AutoRest/TestServer/server/routes/lros.js
index 9d9dc540e16aa..ca11fa50082be 100644
--- a/AutoRest/TestServer/server/routes/lros.js
+++ b/AutoRest/TestServer/server/routes/lros.js
@@ -940,6 +940,17 @@ var lros = function (coverage) {
res.status(400).end('{ "message" : "Error from the server" }');
});
+ /* TODO: only C# has implemented this test. Exclude it from code coverage until it is implemented in other languages */
+ coverage['LRONonRetryPut201Creating400InvalidJson'] = 1;
+ router.put('/nonretryerror/put/201/creating/400/invalidjson', function (req, res, next) {
+ res.status(201).end('{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }');
+ });
+
+ router.get('/nonretryerror/put/201/creating/400/invalidjson', function (req, res, next) {
+ coverage['LRONonRetryPut201Creating400InvalidJson']++;
+ res.status(400).end('<{ "message" : "Error from the server" }');
+ });
+
coverage['LRONonRetryPutAsyncRetry400'] = 0;
router.put('/nonretryerror/putasync/retry/400', function (req, res, next) {
var pollingUri = 'http://localhost.:' + utils.getPort() + '/lro/nonretryerror/putasync/retry/failed/operationResults/400';
diff --git a/AutoRest/TestServer/server/routes/paths.js b/AutoRest/TestServer/server/routes/paths.js
index ba1b8e99df9e6..04b5002453c3c 100644
--- a/AutoRest/TestServer/server/routes/paths.js
+++ b/AutoRest/TestServer/server/routes/paths.js
@@ -23,6 +23,7 @@ var scenarioMap = {
"2012-01-01T01:01:01Z": "Valid",
"green color" : "Valid",
"bG9yZW0" : "Base64Url",
+ "1460505600": "UnixTime",
"ArrayPath1,begin!*'();:@ &=+$,/?#[]end,,": "CSVInPath"
};
diff --git a/AutoRest/TestServer/swagger/body-integer.json b/AutoRest/TestServer/swagger/body-integer.json
index 00b73a2c2731c..5f321e2981692 100644
--- a/AutoRest/TestServer/swagger/body-integer.json
+++ b/AutoRest/TestServer/swagger/body-integer.json
@@ -251,6 +251,95 @@
}
}
}
+ },
+ "/int/unixtime": {
+ "get": {
+ "operationId": "int_getUnixTime",
+ "description": "Get datetime encoded as Unix time value",
+ "responses": {
+ "200": {
+ "description": "The date value encoded as Unix time",
+ "schema": {
+ "type": "integer",
+ "format": "unixtime"
+ }
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ },
+ "put": {
+ "operationId": "int_putUnixTimeDate",
+ "description": "Put datetime encoded as Unix time",
+ "parameters": [
+ {
+ "name": "intBody",
+ "in": "body",
+ "schema": {
+ "type": "integer",
+ "format": "unixtime"
+ },
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "The datetime value encoded as Unix time"
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
+ },
+ "/int/invalidunixtime": {
+ "get": {
+ "operationId": "int_getInvalidUnixTime",
+ "description": "Get invalid Unix time value",
+ "responses": {
+ "200": {
+ "description": "The invalid Unix time value",
+ "schema": {
+ "type": "integer",
+ "format": "unixtime"
+ }
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
+ },
+ "/int/nullunixtime": {
+ "get": {
+ "operationId": "int_getNullUnixTime",
+ "description": "Get null Unix time value",
+ "responses": {
+ "200": {
+ "description": "The null Unix time value",
+ "schema": {
+ "type": "integer",
+ "format": "unixtime"
+ }
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
}
},
"definitions": {
diff --git a/AutoRest/TestServer/swagger/custom-baseUrl-more-options.json b/AutoRest/TestServer/swagger/custom-baseUrl-more-options.json
new file mode 100644
index 0000000000000..75ef7453976ee
--- /dev/null
+++ b/AutoRest/TestServer/swagger/custom-baseUrl-more-options.json
@@ -0,0 +1,108 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "title": "AutoRest Parameterized Custom Host Test Client",
+ "description": "Test Infrastructure for AutoRest",
+ "version": "1.0.0"
+ },
+ "x-ms-parameterized-host": {
+ "hostTemplate": "{vault}{secret}{dnsSuffix}",
+ "useSchemePrefix": false,
+ "parameters": [
+ {
+ "name": "vault",
+ "description": "The vault name, e.g. https://myvault",
+ "required": true,
+ "type": "string",
+ "in": "path",
+ "x-ms-skip-url-encoding": true
+ },
+ {
+ "name": "secret",
+ "description": "Secret value.",
+ "required": true,
+ "type": "string",
+ "in": "path",
+ "x-ms-skip-url-encoding": true
+ },
+ {
+ "$ref": "#/parameters/dnsSuffix"
+ }
+ ]
+ },
+ "produces": [ "application/json" ],
+ "consumes": [ "application/json" ],
+ "paths": {
+ "/customuri/{subscriptionId}/{keyName}": {
+ "get": {
+ "operationId": "paths_getEmpty",
+ "description": "Get a 200 to test a valid base uri",
+ "tags": [
+ "Path Operations"
+ ],
+ "parameters": [
+ {
+ "name": "keyName",
+ "in": "path",
+ "required": true,
+ "type": "string",
+ "description": "The key name with value 'key1'."
+ },
+ {
+ "$ref": "#/parameters/SubscriptionIdParameter"
+ },
+ {
+ "name": "keyVersion",
+ "in": "query",
+ "required": false,
+ "type": "string",
+ "default": "v1",
+ "description": "The key version. Default value 'v1'."
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successfully received a 200 response"
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": {
+ "SubscriptionIdParameter": {
+ "name": "subscriptionId",
+ "in": "path",
+ "required": true,
+ "type": "string",
+ "description": "The subscription id with value 'test12'."
+ },
+ "dnsSuffix": {
+ "name": "dnsSuffix",
+ "description": "A string value that is used as a global part of the parameterized host. Default value 'host'.",
+ "type": "string",
+ "required": false,
+ "default": "host",
+ "in": "path",
+ "x-ms-skip-url-encoding": true
+ }
+ },
+ "definitions": {
+ "Error": {
+ "properties": {
+ "status": {
+ "type": "integer",
+ "format": "int32"
+ },
+ "message": {
+ "type": "string"
+ }
+ }
+ }
+ }
+}
diff --git a/AutoRest/TestServer/swagger/custom-baseUrl.json b/AutoRest/TestServer/swagger/custom-baseUrl.json
index 5ca07d1627a06..aaa0309f4b94a 100644
--- a/AutoRest/TestServer/swagger/custom-baseUrl.json
+++ b/AutoRest/TestServer/swagger/custom-baseUrl.json
@@ -8,6 +8,7 @@
"host": "badhost",
"x-ms-parameterized-host": {
"hostTemplate": "{accountName}{host}",
+ "positionInOperation": "last",
"parameters": [
{
"name": "accountName",
diff --git a/AutoRest/TestServer/swagger/lro.json b/AutoRest/TestServer/swagger/lro.json
index b064ce8c3aa2d..9f9bba0c26759 100644
--- a/AutoRest/TestServer/swagger/lro.json
+++ b/AutoRest/TestServer/swagger/lro.json
@@ -1772,6 +1772,46 @@
}
}
}
+ },
+ "/lro/nonretryerror/put/201/creating/400/invalidjson": {
+ "put": {
+ "x-ms-long-running-operation": true,
+ "operationId": "LROSADs_putNonRetry201Creating400InvalidJson",
+ "description": "Long running put request, service returns a Product with 'ProvisioningState' = 'Creating' and 201 response code",
+ "tags": [
+ "LROSAD Operations"
+ ],
+ "parameters": [
+ {
+ "name": "product",
+ "description": "Product to put",
+ "in": "body",
+ "schema": {
+ "$ref": "#/definitions/Product"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Response after completion, with ProvisioningState='Succeeded'",
+ "schema": {
+ "$ref": "#/definitions/Product"
+ }
+ },
+ "201": {
+ "description": "Initial response, with ProvisioningState = 'Creating'",
+ "schema": {
+ "$ref": "#/definitions/Product"
+ }
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/CloudError"
+ }
+ }
+ }
+ }
},
"/lro/nonretryerror/putasync/retry/400": {
"put": {
diff --git a/AutoRest/TestServer/swagger/url.json b/AutoRest/TestServer/swagger/url.json
index 4bf4530d177fb..670ff00f9bd1d 100644
--- a/AutoRest/TestServer/swagger/url.json
+++ b/AutoRest/TestServer/swagger/url.json
@@ -773,6 +773,36 @@
}
}
},
+ "/paths/int/1460505600/{unixTimeUrlPath}": {
+ "get": {
+ "operationId": "paths_unixTimeUrl",
+ "description": "Get the date 2016-04-13 encoded value as '1460505600' (Unix time)",
+ "tags": [
+ "Path Operations"
+ ],
+ "parameters": [
+ {
+ "name": "unixTimeUrlPath",
+ "in": "path",
+ "description": "Unix time encoded value",
+ "type": "integer",
+ "format": "unixtime",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successfully Received date 2016-04-13 encoded value as '1460505600' (Unix time)"
+ },
+ "default": {
+ "description": "Unexpected error",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
+ },
"/queries/bool/true": {
"get": {
"operationId": "queries_getBooleanTrue",
diff --git a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/LongRunningOperationsTest.cs b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/LongRunningOperationsTest.cs
index bf999fe9f7c1b..1d0bb2069f1bf 100644
--- a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/LongRunningOperationsTest.cs
+++ b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/LongRunningOperationsTest.cs
@@ -104,6 +104,19 @@ public void TestAsyncOperationWithMissingProvisioningState()
Assert.Equal("100", resource.Id);
}
+ [Fact]
+ public void TestAsyncOperationWithNonSuccessStatusAndInvalidResponseContent()
+ {
+ var tokenCredentials = new TokenCredentials("123", "abc");
+ var handler = new PlaybackTestHandler(MockAsyncOperaionWithNonSuccessStatusAndInvalidResponseContent());
+ var fakeClient = new RedisManagementClient(tokenCredentials, handler);
+ fakeClient.LongRunningOperationInitialTimeout = fakeClient.LongRunningOperationRetryTimeout = 0;
+ var error = Assert.Throws(() =>
+ fakeClient.RedisOperations.Delete("rg", "redis", "1234"));
+ Assert.Equal("Long running operation failed with status 'BadRequest'.", error.Message);
+ Assert.Null(error.Body);
+ }
+
[Fact]
public void TestPutOperationWithoutProvisioningState()
{
@@ -737,6 +750,22 @@ private IEnumerable MockAsyncOperaionWithMissingProvisionin
yield return response3;
}
+ private IEnumerable MockAsyncOperaionWithNonSuccessStatusAndInvalidResponseContent()
+ {
+ var response1 = new HttpResponseMessage(HttpStatusCode.Accepted)
+ {
+ Content = new StringContent("")
+ };
+ response1.Headers.Add("Location", "http://custom/status");
+ yield return response1;
+
+ var response2 = new HttpResponseMessage(HttpStatusCode.BadRequest)
+ {
+ Content = new StringContent("<")
+ };
+ yield return response2;
+ }
+
private IEnumerable MockPutOperaionWithoutProvisioningStateInResponse()
{
var response1 = new HttpResponseMessage(HttpStatusCode.Created)
diff --git a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/ODataTests.cs b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/ODataTests.cs
index 639023af44855..e267142696404 100644
--- a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/ODataTests.cs
+++ b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure.Tests/ODataTests.cs
@@ -7,6 +7,7 @@
using Microsoft.Rest.Azure.OData;
using Newtonsoft.Json;
using Xunit;
+using System.Collections.Generic;
namespace Microsoft.Rest.ClientRuntime.Azure.Test
{
@@ -227,7 +228,6 @@ public void EncodingTheParameters()
[Fact]
public void ODataQuerySupportsAllParameters()
{
- var queryString = "foo eq 'bar'";
var query = new ODataQuery(p => p.Foo == "bar")
{
Expand = "param1",
@@ -235,7 +235,7 @@ public void ODataQuerySupportsAllParameters()
Skip = 10,
Top = 100
};
- Assert.Equal(string.Format("$filter={0}&$orderby=d&$expand=param1&$top=100&$skip=10", Uri.EscapeDataString(queryString)), query.ToString());
+ Assert.Equal("$filter=foo eq 'bar'&$orderby=d&$expand=param1&$top=100&$skip=10", query.ToString());
}
[Fact]
@@ -249,49 +249,86 @@ public void ODataQuerySupportsEmptyState()
{
Value = null
};
+ var paramEncoded = new InputParam1
+ {
+ Value = "bar/car"
+ };
query = new ODataQuery(p => p.Foo == param.Value);
Assert.Equal("", query.ToString());
query = new ODataQuery(p => p.Foo == param.Value && p.AssignedTo(param.Value));
Assert.Equal("", query.ToString());
query = new ODataQuery(p => p.AssignedTo(param.Value));
Assert.Equal("", query.ToString());
+ query = new ODataQuery(p => p.AssignedTo(paramEncoded.Value));
+ Assert.Equal("$filter=assignedTo('bar%2Fcar')", query.ToString());
+ }
+
+ [Fact]
+ public void ODataQuerySupportsCustomDateTimeOffsetFilter()
+ {
+ var param = new Param1
+ {
+ SubmitTime = DateTimeOffset.Parse("2016-03-28T08:15:00.0971693+00:00"),
+ State = "Ended"
+
+ };
+
+ var filter = new List();
+ filter.Add(string.Format("submitTime lt datetimeoffset'{0}'", Uri.EscapeDataString(param.SubmitTime.Value.ToString("O"))));
+ filter.Add(string.Format("state ne '{0}'", param.State));
+ var filterString = string.Join(" and ", filter.ToArray());
+
+
+ var query = new ODataQuery
+ {
+ Filter = filterString
+ };
+ Assert.Equal("$filter=submitTime lt datetimeoffset'2016-03-28T08%3A15%3A00.0971693%2B00%3A00' and state ne 'Ended'", query.ToString());
}
+
[Fact]
public void ODataQuerySupportsPartialState()
{
- var queryString = "foo eq 'bar'";
var query = new ODataQuery(p => p.Foo == "bar")
{
Top = 100
};
- Assert.Equal(string.Format("$filter={0}&$top=100", Uri.EscapeDataString(queryString)), query.ToString());
+ Assert.Equal("$filter=foo eq 'bar'&$top=100", query.ToString());
+ }
+
+ [Fact]
+ public void ODataQuerySupportsPartialStateWithSlashes()
+ {
+ var queryString = "$filter=foo eq 'bar%2Fclub'&$top=100";
+ var query = new ODataQuery(p => p.Foo == "bar/club")
+ {
+ Top = 100
+ };
+ Assert.Equal(queryString, query.ToString());
}
[Fact]
public void ODataQuerySupportsImplicitConversionFromFilterString()
{
- var queryString = "foo eq 'bar'";
- ODataQuery query = queryString;
+ ODataQuery query = "foo eq 'bar'";
query.Top = 100;
- Assert.Equal(string.Format("$filter={0}&$top=100", Uri.EscapeDataString(queryString)), query.ToString());
+ Assert.Equal("$filter=foo eq 'bar'&$top=100", query.ToString());
}
[Fact]
public void ODataQuerySupportsImplicitConversionFromFullFilterString()
{
- var queryString = "foo eq 'bar'";
- ODataQuery query = string.Format("$filter={0}", queryString);
+ ODataQuery query = "$filter=foo eq 'bar'";
query.Top = 100;
- Assert.Equal(string.Format("$filter={0}&$top=100", Uri.EscapeDataString(queryString)), query.ToString());
+ Assert.Equal("$filter=foo eq 'bar'&$top=100", query.ToString());
}
[Fact]
public void ODataQuerySupportsImplicitConversionFromQueryString()
{
- var queryString = "foo eq 'bar'";
- ODataQuery query = string.Format("$filter={0}&$top=100", queryString);
- Assert.Equal(string.Format("$filter={0}&$top=100", Uri.EscapeDataString(queryString)), query.ToString());
+ ODataQuery query = "$filter=foo eq 'bar'&$top=100";
+ Assert.Equal("$filter=foo eq 'bar'&$top=100", query.ToString());
}
[Fact]
@@ -323,7 +360,7 @@ public void ODataQuerySupportsMethod()
var filterString = FilterString.Generate(parameters => parameters.AtScope() &&
parameters.AssignedTo(param.Value));
- Assert.Equal(filterString, "atScope() and assignedTo('Microsoft.Web%2Fsites')");
+ Assert.Equal("atScope() and assignedTo('Microsoft.Web%2Fsites')", filterString);
}
}
@@ -361,6 +398,10 @@ public class Param1
[JsonProperty("d")]
public DateTime Date { get; set; }
public DateTime Date2 { get; set; }
+ [JsonProperty("submitTime")]
+ public DateTimeOffset? SubmitTime { get; set; }
+ [JsonProperty("state")]
+ public string State { get; set; }
[JsonProperty("vals")]
public string[] Values { get; set; }
[JsonProperty("param2")]
diff --git a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure/AzureClientExtensions.cs b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure/AzureClientExtensions.cs
index 57bbd064b95c2..422f074bd3028 100644
--- a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure/AzureClientExtensions.cs
+++ b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime.Azure/AzureClientExtensions.cs
@@ -122,6 +122,38 @@ await UpdateStateFromGetResourceOperation(client, pollingState, getOperationUrl,
return pollingState.AzureOperationResponse;
}
+ ///
+ /// Gets operation result for PUT and PATCH operations.
+ ///
+ /// IAzureClient
+ /// Response from the begin operation
+ /// Headers that will be added to request
+ /// Cancellation token
+ /// Operation response
+ public static async Task GetPutOrPatchOperationResultAsync(
+ this IAzureClient client,
+ AzureOperationResponse response,
+ Dictionary> customHeaders,
+ CancellationToken cancellationToken)
+ {
+ var newResponse = new AzureOperationResponse