Skip to content
Merged
496 changes: 249 additions & 247 deletions AutoRest.sln

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/core/AutoRest.Core.Tests/AutoRestSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public void CreateWithoutArgumentsReturnsBlankSettings()
{
using (NewContext)
{
var settings = Settings.Create((string[]) null);
var settings = Settings.Create((string[])null);
Assert.NotNull(settings);
}
using (NewContext)
{
var settings = Settings.Create((IDictionary<string, object>) null);
var settings = Settings.Create((IDictionary<string, object>)null);
Assert.NotNull(settings);
}
using (NewContext)
Expand All @@ -47,7 +47,7 @@ public void CreateWithMultipleEmptyKeysStoreInCustomDictonary()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-Help", " -Bar ", " -Foo"});
var settings = Settings.Create(new[] { "-Help", " -Bar ", " -Foo" });
Assert.True(settings.ShowHelp);
Assert.Equal("", settings.CustomSettings["Foo"]);
Assert.Equal("", settings.CustomSettings["Bar"]);
Expand All @@ -62,12 +62,12 @@ public void LoadCodeGenSettingsFromJsonFile()
var codeBaseUrl = new Uri(Utilities.Extensions.CodeBaseDirectory); // travis error here... I guess the constructor isn't happy 'bout linux paths?
var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
var settingsFile = Path.Combine(codeBasePath, Path.Combine("Resource", "SampleSettings.json"));
var settings = Settings.Create(new[] {"-cgs", settingsFile});
Assert.False((bool) settings.CustomSettings["sampleSwitchFalse"]);
Assert.True((bool) settings.CustomSettings["sampleSwitchTrue"]);
var settings = Settings.Create(new[] { "-cgs", settingsFile });
Assert.False((bool)settings.CustomSettings["sampleSwitchFalse"]);
Assert.True((bool)settings.CustomSettings["sampleSwitchTrue"]);
Assert.Equal("Foo", settings.CustomSettings["sampleString"]);
Assert.Equal(typeof(JArray), settings.CustomSettings["filePathArray"].GetType());
Assert.Equal(2, ((JArray) settings.CustomSettings["filePathArray"]).Count);
Assert.Equal(2, ((JArray)settings.CustomSettings["filePathArray"]).Count);
Assert.Equal(typeof(JArray), settings.CustomSettings["intArray"].GetType());
Assert.Equal(typeof(long), settings.CustomSettings["intFoo"].GetType());
}
Expand All @@ -78,7 +78,7 @@ public void EmptyCredentialsSettingIsSetToTrueIfPassed()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-AddCredentials"});
var settings = Settings.Create(new[] { "-AddCredentials" });
Assert.True(settings.AddCredentials);
}
}
Expand All @@ -88,7 +88,7 @@ public void NonEmptyCredentialsSettingIsSetToValueIfPassed()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-AddCredentials false"});
var settings = Settings.Create(new[] { "-AddCredentials false" });
Assert.False(settings.AddCredentials);
}
}
Expand All @@ -98,7 +98,7 @@ public void NonEmptyPackageVersionIsSet()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-pv", "1.2.1"});
var settings = Settings.Create(new[] { "-pv", "1.2.1" });
Assert.Equal("1.2.1", settings.PackageVersion);
}
}
Expand All @@ -108,7 +108,7 @@ public void NonEmptyPackageNameIsSet()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-pn", "HelloWorld"});
var settings = Settings.Create(new[] { "-pn", "HelloWorld" });
Assert.Equal("HelloWorld", settings.PackageName);
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void MissingParameterThrowsException()
{
using (NewContext)
{
var settings = Settings.Create(new[] {"-Modeler", "foo"});
var settings = Settings.Create(new[] { "-Modeler", "foo" });
try
{
settings.Validate();
Expand Down
7 changes: 5 additions & 2 deletions src/core/AutoRest.Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using AutoRest.Core.Logging;
using AutoRest.Core.Properties;
using AutoRest.Core.Utilities;
Expand Down Expand Up @@ -45,7 +46,7 @@ limitations under the License.

private string _header;

public static string AutoRestFolder{ get;set;}
public static string AutoRestFolder { get; set; }

public Settings()
{
Expand Down Expand Up @@ -99,6 +100,8 @@ public Uri InputFolder
/// </summary>
public IDictionary<string, object> CustomSettings { get; private set; }

private string _input;

// The CommandLineInfo attribute is reflected to display help.
// Prefer to show required properties before optional.
// Although not guaranteed by the Framework, the iteration order matches the
Expand Down Expand Up @@ -192,7 +195,7 @@ public Uri InputFolder
"Possible values: rest, rest-client, rest-server. " +
"Determines whether AutoRest generates " +
"the client or server side code for given spec.")]
public string CodeGenerationMode{ get; set; }
public string CodeGenerationMode { get; set; }

/// <summary>
/// Gets or sets a comment header to include in each generated file.
Expand Down
36 changes: 30 additions & 6 deletions src/core/AutoRest.Core/Utilities/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void WriteFile(string path, string contents)
if (File.Exists(path))
{
var mvname = $"{path}_{new Random().Next(999999)}";
File.Move(path,mvname);
File.Move(path, mvname);
File.Delete(mvname);
}
// write out the file, with correct line endings for file.
Expand Down Expand Up @@ -51,7 +51,31 @@ public bool IsCompletePath(string path)
/// <param name="relativePath"></param>
/// <returns></returns>
public string MakePathRooted(Uri rootPath, string relativePath)
=> Path.Combine(rootPath.ToString(), relativePath);
{
//Path.Combine("/usr/foo", "./bar/baz") -> "/usr/foo/./bar/baz". Hence we need to prepend
//file scheme to the absolute path and then use new Uri("file:///usr/foo/./bar/baz").AbsoluteUri
//to get "/usr/foo/bar/baz".
var fileSchemaPrefix = "file://";
var rootPathAsString = rootPath.ToString();
if (rootPath != null && !Regex.IsMatch(rootPathAsString, @"^(file|https?)://.*$", RegexOptions.IgnoreCase))
{
//On a linux system, Path.IsPathRooted("C:/Foo") -> false. Ideally, it is not expected from
//someone to provide that kind of a file path while running AutoRest on a linux based system.
//However, adding the extra condition to do the right behavior for "C:\\Foo". The focus is to
//do the right thing based on the initial characters. If the provided path is incorrect, it will
//eventually fail.
if (Path.IsPathRooted(rootPathAsString) || (Path.PathSeparator != ';' && Regex.IsMatch(rootPathAsString, @"^[a-zA-Z]:(\\{1,2}|/)\w+.*$", RegexOptions.IgnoreCase)))
{
rootPathAsString = string.Concat(fileSchemaPrefix, rootPathAsString);
}
else
{
rootPathAsString = string.Concat(fileSchemaPrefix, Path.GetFullPath(rootPathAsString));
}
}

return new Uri(Path.Combine(new Uri(rootPathAsString).AbsoluteUri, relativePath), UriKind.Absolute).ToString();
}

public string ReadFileAsText(string path)
{
Expand All @@ -68,10 +92,10 @@ public string ReadFileAsText(string path)
{
return File.ReadAllText(uri.LocalPath, Encoding.UTF8);
}
using (var client = new System.Net.Http.HttpClient( ))

using (var client = new System.Net.Http.HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent","AutoRest");
client.DefaultRequestHeaders.Add("User-Agent", "AutoRest");
// client.Encoding = Encoding.UTF8;
return client.GetAsync(path).Result.Content.ReadAsStringAsync().Result;
//return client.DownloadString(path);
Expand All @@ -85,7 +109,7 @@ public TextWriter GetTextWriter(string path)
return File.AppendText(path);
}
// ensure that we're being very very explicit: NO BYTE ORDER MARK.
return new StreamWriter(new FileStream( path,FileMode.Create), new UTF8Encoding(false, true));
return new StreamWriter(new FileStream(path, FileMode.Create), new UTF8Encoding(false, true));
}

public bool FileExists(string path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"swagger": "2.0",
"info": {
"title": "NetworkManagementClient",
"description": "The Microsoft Azure Network management API provides a RESTful set of web services that interact with Microsoft Azure Networks service to manage your network resources. The API has entities that capture the relationship between an end user and the Microsoft Azure Networks service.",
"version": "2016-09-01"
},
"host": "management.azure.com",
"schemes": [
"https"
],
"consumes": [
"application/json",
"text/json"
],
"produces": [
"application/json",
"text/json"
],
"security": [
{
"azure_auth": [
"user_impersonation"
]
}
],
"securityDefinitions": {
"azure_auth": {
"type": "oauth2",
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
"flow": "implicit",
"description": "Azure Active Directory OAuth2 Flow",
"scopes": {
"user_impersonation": "impersonate your user account"
}
}
},
"paths": {},
"definitions": {
"ApplicationGatewayBackendAddressPool": {
"properties": {
"properties": {
"x-ms-client-flatten": true,
"$ref": "#/definitions/ApplicationGatewayBackendAddressPoolPropertiesFormat"
},
"name": {
"type": "string",
"description": "Resource that is unique within a resource group. This name can be used to access the resource."
},
"etag": {
"type": "string",
"description": "A unique read-only string that changes whenever the resource is updated."
}
},
"description": "Backend Address Pool of an application gateway."
},
"ApplicationGatewayBackendAddressPoolPropertiesFormat": {
"properties": {
"backendIPConfigurations": {
"type": "array",
"items": {
"$ref": "./networkInterface.json#/definitions/NetworkInterfaceIPConfiguration"
},
"description": "Collection of references to IPs defined in network interfaces."
},
"backendAddresses": {
"type": "array",
"items": {
"$ref": "#/definitions/ApplicationGatewayBackendAddress"
},
"description": "Backend addresses"
},
"provisioningState": {
"type": "string",
"description": "Provisioning state of the backend address pool resource. Possible values are: 'Updating', 'Deleting', and 'Failed'."
}
},
"description": "Properties of Backend Address Pool of an application gateway."
}
},
"parameters": {
"SubscriptionIdParameter": {
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription ID forms part of the URI for every service call."
},
"ApiVersionParameter": {
"name": "api-version",
"in": "query",
"required": true,
"type": "string",
"description": "Client API version."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"swagger": "2.0",
"info": {
"title": "NetworkManagementClient",
"description": "The Microsoft Azure Network management API provides a RESTful set of web services that interact with Microsoft Azure Networks service to manage your network resources. The API has entities that capture the relationship between an end user and the Microsoft Azure Networks service.",
"version": "2016-09-01"
},
"host": "management.azure.com",
"schemes": [
"https"
],
"consumes": [
"application/json",
"text/json"
],
"produces": [
"application/json",
"text/json"
],
"security": [
{
"azure_auth": [
"user_impersonation"
]
}
],
"securityDefinitions": {
"azure_auth": {
"type": "oauth2",
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
"flow": "implicit",
"description": "Azure Active Directory OAuth2 Flow",
"scopes": {
"user_impersonation": "impersonate your user account"
}
}
},
"paths": {},
"definitions": {
"NetworkInterfaceIPConfiguration": {
"properties": {
"properties": {
"x-ms-client-flatten": true,
"$ref": "#/definitions/NetworkInterfaceIPConfigurationPropertiesFormat"
},
"name": {
"type": "string",
"description": "The name of the resource that is unique within a resource group. This name can be used to access the resource."
},
"etag": {
"type": "string",
"description": "A unique read-only string that changes whenever the resource is updated."
}
},
"description": "IPConfiguration in a network interface."
},
"NetworkInterfaceIPConfigurationPropertiesFormat": {
"properties": {
"applicationGatewayBackendAddressPools": {
"type": "array",
"items": {
"$ref": "./applicationGateway.json#/definitions/ApplicationGatewayBackendAddressPool"
},
"description": "The reference of ApplicationGatewayBackendAddressPool resource."
}
},
"description": "Properties of IP configuration."
}
},
"parameters": {
"SubscriptionIdParameter": {
"name": "subscriptionId",
"in": "path",
"required": true,
"type": "string",
"description": "The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription ID forms part of the URI for every service call."
},
"ApiVersionParameter": {
"name": "api-version",
"in": "query",
"required": true,
"type": "string",
"description": "Client API version."
}
}
}
Loading