Skip to content

Commit

Permalink
Merge pull request Azure#2 from amarzavery/readonly
Browse files Browse the repository at this point in the history
Readonly NodeJS
  • Loading branch information
stankovski committed Feb 27, 2016
2 parents 13feba3 + 35d7abe commit 0deeea8
Show file tree
Hide file tree
Showing 515 changed files with 48,294 additions and 8,782 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ reports
.gradle
.idea
*.iml
Tools/7-Zip

# Sensitive files
*.keys
Expand Down
2 changes: 2 additions & 0 deletions AutoRest/AutoRest.Core/AutoRest.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<Compile Include="Logging\CodeGenerationException.cs" />
<Compile Include="SettingsInfoAttribute.cs" />
<Compile Include="Logging\ErrorManager.cs" />
<Compile Include="Utilities\IScopeProvider.cs" />
<Compile Include="Utilities\ScopeProvider.cs" />
<Compile Include="Utilities\TemplateConstants.cs" />
<Compile Include="Utilities\CamelCaseContractResolver.cs" />
<Compile Include="Utilities\Extensions.cs" />
Expand Down
7 changes: 7 additions & 0 deletions AutoRest/AutoRest.Core/ClientModel/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Method()
RequestHeaders = new Dictionary<string, string>();
Responses = new Dictionary<HttpStatusCode, Response>();
InputParameterTransformation = new List<ParameterTransformation>();
Scope = new ScopeProvider();
}

/// <summary>
Expand Down Expand Up @@ -144,6 +145,11 @@ public Parameter Body
/// </summary>
public Dictionary<string, object> Extensions { get; private set; }

/// <summary>
/// Gets
/// </summary>
public IScopeProvider Scope { get; private set; }

/// <summary>
/// Returns a string representation of the Method object.
/// </summary>
Expand All @@ -169,6 +175,7 @@ public object Clone()
newMethod.RequestHeaders = new Dictionary<string, string>();
newMethod.Responses = new Dictionary<HttpStatusCode, Response>();
newMethod.InputParameterTransformation = new List<ParameterTransformation>();
newMethod.Scope = new ScopeProvider();
this.Extensions.ForEach(e => newMethod.Extensions[e.Key] = e.Value);
this.Parameters.ForEach(p => newMethod.Parameters.Add((Parameter)p.Clone()));
this.InputParameterTransformation.ForEach(m => newMethod.InputParameterTransformation.Add((ParameterTransformation)m.Clone()));
Expand Down
4 changes: 2 additions & 2 deletions AutoRest/AutoRest.Core/CodeNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ public virtual void NormalizeMethod(Method method)
}
foreach (var parameter in method.Parameters)
{
parameter.Name = GetParameterName(parameter.Name);
parameter.Name = method.Scope.GetUniqueName(GetParameterName(parameter.Name));
parameter.Type = NormalizeTypeReference(parameter.Type);
QuoteParameter(parameter);
}

foreach (var parameterTransformation in method.InputParameterTransformation)
{
parameterTransformation.OutputParameter.Name = GetParameterName(parameterTransformation.OutputParameter.Name);
parameterTransformation.OutputParameter.Name = method.Scope.GetUniqueName(GetParameterName(parameterTransformation.OutputParameter.Name));
parameterTransformation.OutputParameter.Type = NormalizeTypeReference(parameterTransformation.OutputParameter.Type);

QuoteParameter(parameterTransformation.OutputParameter);
Expand Down
6 changes: 6 additions & 0 deletions AutoRest/AutoRest.Core/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.Method.#InputParameterMappings")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rfc", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.KnownPrimaryType.#DateTimeRfc1123")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.PrimaryType.#Type")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.CompositeType.#Properties")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.EnumType.#Values")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.Method.#InputParameterTransformation")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.ServiceClient.#Methods")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.ServiceClient.#Properties")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.ClientModel.ParameterTransformation.#ParameterMappings")]

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Rest.Generator.CSharp
namespace Microsoft.Rest.Generator.Utilities
{
public interface IScopeProvider
{
string GetVariableName(string prefix);
string GetUniqueName(string variableName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

using System.Collections.Generic;

namespace Microsoft.Rest.Generator.CSharp
namespace Microsoft.Rest.Generator.Utilities
{
/// <summary>
/// Provides scope for variable names.
/// </summary>
public class ScopeProvider : IScopeProvider
{
/// <summary>
Expand All @@ -13,18 +16,18 @@ public class ScopeProvider : IScopeProvider
private readonly HashSet<string> _variables = new HashSet<string>();

/// <summary>
/// Get a variable name that is unique in this method's scope
/// Get a unique variable name in the current scope
/// </summary>
/// <param name="prefix">The variable prefix</param>
/// <param name="variableName">The variable name</param>
/// <returns>A variable name unique in this method</returns>
public string GetVariableName(string prefix)
public string GetUniqueName(string variableName)
{
if (_variables.Add(prefix))
if (_variables.Add(variableName))
{
return prefix;
return variableName;
}

return GetAlternateVariableName(prefix, 1);
return GetAlternateVariableName(variableName, 1);
}

private string GetAlternateVariableName(string prefix, int suffix)
Expand Down
8 changes: 4 additions & 4 deletions AutoRest/AutoRest/HelpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public static string Generate(string template)

// Generate parameters section
var parametersSection = new StringBuilder();
const string parametersPattern = @"\$parameters-start\$\r\n(.+)\r\n\$parameters-end\$";
var parameterTemplate = Regex.Match(template, parametersPattern, RegexOptions.Singleline).Groups[1].Value;
const string parametersPattern = @"\$parameters-start\$(.+)\$parameters-end\$";
var parameterTemplate = Regex.Match(template, parametersPattern, RegexOptions.Singleline).Groups[1].Value.Trim();
foreach (PropertyInfo property in typeof(Settings).GetProperties())
{
SettingsInfoAttribute doc = (SettingsInfoAttribute)property.GetCustomAttributes(
Expand All @@ -131,8 +131,8 @@ public static string Generate(string template)

// Generate examples section.
var examplesSection = new StringBuilder();
const string examplesPattern = @"\$examples-start\$\r\n(.+)\r\n\$examples-end\$";
var exampleTemplate = Regex.Match(template, examplesPattern, RegexOptions.Singleline).Groups[1].Value;
const string examplesPattern = @"\$examples-start\$(.+)\$examples-end\$";
var exampleTemplate = Regex.Match(template, examplesPattern, RegexOptions.Singleline).Groups[1].Value.Trim() + Environment.NewLine;
foreach (HelpExample example in Examples)
{
examplesSection.AppendLine(exampleTemplate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public partial class AzureCompositeModel : ServiceClient<AzureCompositeModel>, I
/// </summary>
public virtual IPolymorphicrecursiveOperations Polymorphicrecursive { get; private set; }

/// <summary>
/// Gets the IReadonlypropertyOperations.
/// </summary>
public virtual IReadonlypropertyOperations Readonlyproperty { get; private set; }

/// <summary>
/// Initializes a new instance of the AzureCompositeModel class.
/// </summary>
Expand Down Expand Up @@ -294,6 +299,7 @@ private void Initialize()
this.Inheritance = new InheritanceOperations(this);
this.Polymorphism = new PolymorphismOperations(this);
this.Polymorphicrecursive = new PolymorphicrecursiveOperations(this);
this.Readonlyproperty = new ReadonlypropertyOperations(this);
this.BaseUri = new Uri("http://localhost");
this.SubscriptionId = "123456";
this.AcceptLanguage = "en-US";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public partial interface IAzureCompositeModel : IDisposable
/// </summary>
IPolymorphicrecursiveOperations Polymorphicrecursive { get; }

/// <summary>
/// Gets the IReadonlypropertyOperations.
/// </summary>
IReadonlypropertyOperations Readonlyproperty { get; }

/// <summary>
/// Product Types
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.AcceptanceTestsAzureCompositeModelClient
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Rest;
using Microsoft.Rest.Azure;
using Models;

/// <summary>
/// ReadonlypropertyOperations operations.
/// </summary>
public partial interface IReadonlypropertyOperations
{
/// <summary>
/// Get complex types that have readonly properties
/// </summary>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<ReadonlyObj>> GetValidWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Put complex types that have readonly properties
/// </summary>
/// <param name='complexBody'>
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse> PutValidWithHttpMessagesAsync(ReadonlyObj complexBody, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.AcceptanceTestsAzureCompositeModelClient.Models
{
using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.Rest;
using Microsoft.Rest.Serialization;
using Microsoft.Rest.Azure;

public partial class ReadonlyObj
{
/// <summary>
/// Initializes a new instance of the ReadonlyObj class.
/// </summary>
public ReadonlyObj() { }

/// <summary>
/// Initializes a new instance of the ReadonlyObj class.
/// </summary>
public ReadonlyObj(string id = default(string), int? size = default(int?))
{
Id = id;
Size = size;
}

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "id")]
public string Id { get; private set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "size")]
public int? Size { get; set; }

}
}
Loading

0 comments on commit 0deeea8

Please sign in to comment.