Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Azure/autorest
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte committed May 4, 2016
2 parents 4c5f556 + 0142862 commit df8fb81
Show file tree
Hide file tree
Showing 84 changed files with 4,019 additions and 520 deletions.
3 changes: 2 additions & 1 deletion AutoRest/AutoRest/AutoRest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Compile Include="..\..\Tools\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="ExitCode.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="HelpExample.cs" />
<Compile Include="HelpGenerator.cs" />
Expand Down Expand Up @@ -70,4 +71,4 @@
</Content>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
14 changes: 14 additions & 0 deletions AutoRest/AutoRest/ExitCode.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Available exit codes.
/// </summary>
public enum ExitCode : int
{
Success = 0,
Error = 1
}
}
6 changes: 5 additions & 1 deletion AutoRest/AutoRest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +71,7 @@ private static void Main(string[] args)
{
Console.WriteLine(Resources.GenerationComplete,
settings.CodeGenerator, settings.Input);
exitCode = (int)ExitCode.Success;
}
}

Expand All @@ -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;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ItemGroup>
<Compile Include="SchemaProperty.cs" />
<Compile Include="Definition.cs" />
<Compile Include="ResourceProperty.cs" />
<Compile Include="ResourceSchema.cs" />
<Compile Include="AzureResourceSchemaCodeGenerator.cs" />
<Compile Include="$(SolutionDir)\Tools\AssemblyVersionInfo.cs">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Rest.Generator.AzureResourceSchema
{
public class ResourceProperty
{
private readonly string name;
private readonly bool isRequired;
private readonly string propertyType;
private readonly IEnumerable<string> allowedValues;
private readonly string description;

public ResourceProperty(string name, bool isRequired, string propertyType, IEnumerable<string> allowedValues, string description)
{
this.name = name;
this.isRequired = isRequired;
this.propertyType = propertyType;
this.allowedValues = allowedValues;
this.description = description;
}

public string Name
{
get { return name; }
}

public bool IsRequired
{
get { return isRequired; }
}

public string PropertyType
{
get { return propertyType; }
}

public IEnumerable<string> AllowedValues
{
get { return allowedValues; }
}

public string Description
{
get { return description; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloudException>(() => 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<CloudException>(
() => client.LROSADs.PutAsyncRelativeRetry400(new Product {Location = "West US"}));
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ public partial interface ILROSADsOperations
/// </param>
Task<AzureOperationResponse<Product>> BeginPutNonRetry201Creating400WithHttpMessagesAsync(Product product = default(Product), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Long running put request, service returns a Product with
/// 'ProvisioningState' = 'Creating' and 201 response code
/// </summary>
/// <param name='product'>
/// Product to put
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<Product>> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Long running put request, service returns a Product with
/// 'ProvisioningState' = 'Creating' and 201 response code
/// </summary>
/// <param name='product'>
/// Product to put
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<Product>> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
/// Azure-AsyncOperation header for operation status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,209 @@ public async Task<AzureOperationResponse<Product>> BeginPutNonRetry201Creating40
return _result;
}

/// <summary>
/// Long running put request, service returns a Product with
/// 'ProvisioningState' = 'Creating' and 201 response code
/// </summary>
/// <param name='product'>
/// Product to put
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public async Task<AzureOperationResponse<Product>> PutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
// Send Request
AzureOperationResponse<Product> _response = await BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(
product, customHeaders, cancellationToken);
return await this.Client.GetPutOrPatchOperationResultAsync(_response,
customHeaders,
cancellationToken);
}

/// <summary>
/// Long running put request, service returns a Product with
/// 'ProvisioningState' = 'Creating' and 201 response code
/// </summary>
/// <param name='product'>
/// Product to put
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async Task<AzureOperationResponse<Product>> BeginPutNonRetry201Creating400InvalidJsonWithHttpMessagesAsync(Product product = default(Product), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
// Tracing
bool _shouldTrace = ServiceClientTracing.IsEnabled;
string _invocationId = null;
if (_shouldTrace)
{
_invocationId = ServiceClientTracing.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
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<string> _queryParameters = new List<string>();
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<CloudError>(_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<Product>();
_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<Product>(_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<Product>(_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;
}

/// <summary>
/// Long running put request, service returns a 200 with
/// ProvisioningState=’Creating’. Poll the endpoint indicated in the
Expand Down

0 comments on commit df8fb81

Please sign in to comment.