diff --git a/AutoRest.sln b/AutoRest.sln index b11b89d798..e9e2ddf312 100644 --- a/AutoRest.sln +++ b/AutoRest.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Core", "AutoRest\AutoRest.Core\AutoRest.Core.csproj", "{C876085F-9DC3-41F0-B7B4-17022CD84684}" EndProject @@ -372,6 +372,14 @@ Global {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs b/AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs index c58c81e4e6..8cadb3f641 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/AutoRest.nuget.proj b/AutoRest/AutoRest.Core/AutoRest.nuget.proj index 86429ba41f..83546d434a 100644 --- a/AutoRest/AutoRest.Core/AutoRest.nuget.proj +++ b/AutoRest/AutoRest.Core/AutoRest.nuget.proj @@ -2,7 +2,7 @@ - 0.16.0$(NightlyBuildVersion) + 0.17.0$(NightlyBuildVersion) true diff --git a/AutoRest/AutoRest.Core/AutoRest.nuspec b/AutoRest/AutoRest.Core/AutoRest.nuspec index 0451285cb5..2af544a885 100644 --- a/AutoRest/AutoRest.Core/AutoRest.nuspec +++ b/AutoRest/AutoRest.Core/AutoRest.nuspec @@ -31,6 +31,7 @@ + diff --git a/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs b/AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs index 200dcfe018..94dd5ffd7b 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 8efb1c0311..57dbecb697 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/Properties/AssemblyInfo.cs b/AutoRest/AutoRest.Core/Properties/AssemblyInfo.cs index aa48e093ad..f1686e2433 100644 --- a/AutoRest/AutoRest.Core/Properties/AssemblyInfo.cs +++ b/AutoRest/AutoRest.Core/Properties/AssemblyInfo.cs @@ -11,8 +11,8 @@ [assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyProduct("Microsoft AutoRest")] [assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")] -[assembly: AssemblyVersion("0.16.0.0")] -[assembly: AssemblyFileVersion("0.16.0.0")] +[assembly: AssemblyVersion("0.17.0.0")] +[assembly: AssemblyFileVersion("0.17.0.0")] [assembly: NeutralResourcesLanguage("en")] [assembly: CLSCompliant(true)] diff --git a/AutoRest/AutoRest.Core/Utilities/Extensions.cs b/AutoRest/AutoRest.Core/Utilities/Extensions.cs index 23bea5173d..9a18e21f1f 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 91b4f6c18b..13fab28c4c 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.Release.json b/AutoRest/AutoRest/AutoRest.Release.json index b488b12ca1..f368702db7 100644 --- a/AutoRest/AutoRest/AutoRest.Release.json +++ b/AutoRest/AutoRest/AutoRest.Release.json @@ -29,6 +29,9 @@ }, "Azure.Python": { "type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python" + }, + "AzureResourceSchema": { + "type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema" } }, "modelers": { diff --git a/AutoRest/AutoRest/AutoRest.csproj b/AutoRest/AutoRest/AutoRest.csproj index 8bd5ec84e9..7c578e0980 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/AutoRest.json b/AutoRest/AutoRest/AutoRest.json index b488b12ca1..f368702db7 100644 --- a/AutoRest/AutoRest/AutoRest.json +++ b/AutoRest/AutoRest/AutoRest.json @@ -29,6 +29,9 @@ }, "Azure.Python": { "type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python" + }, + "AzureResourceSchema": { + "type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema" } }, "modelers": { diff --git a/AutoRest/AutoRest/ExitCode.cs b/AutoRest/AutoRest/ExitCode.cs new file mode 100644 index 0000000000..fe09a82b44 --- /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 b0c4aa7abe..f7bdf406b1 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/AcceptanceTests.cs b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AcceptanceTests.cs new file mode 100644 index 0000000000..97cbab6189 --- /dev/null +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AcceptanceTests.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. + +using Microsoft.Rest.Generator.AzureResourceSchema; +using Microsoft.Rest.Modeler.Swagger.Tests; +using System.IO; +using Xunit; + +namespace AutoRest.Generator.AzureResourceSchema.Tests +{ + [Collection("AutoRest Azure Resource Schema Tests")] + public static class AcceptanceTests + { + [Fact] + public static void Storage() + { + RunSwaggerTest("storage.json", "Storage"); + } + + [Fact] + public static void Batch() + { + RunSwaggerTest("BatchManagement.json", "Batch"); + } + + [Fact] + public static void Cdn() + { + RunSwaggerTest("cdn.json", "CDN"); + } + + [Fact] + public static void Compute() + { + RunSwaggerTest("compute.json", "Compute"); + } + + [Fact] + public static void Network() + { + RunSwaggerTest("network.json", "Network"); + } + + [Fact] + public static void Web() + { + RunSwaggerTest("web.json", "Web"); + } + + private static void RunSwaggerTest(string swaggerFileName, string expectedFolderName) + { + SwaggerSpecHelper.RunTests( + Path.Combine("Swagger", swaggerFileName), + Path.Combine("Expected", expectedFolderName)); + } + } +} 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 079278b9d7..3624fde45d 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj @@ -1,6 +1,7 @@  - - + + + Debug @@ -8,6 +9,7 @@ {1C3B4A33-E045-4C8F-9202-1B651A686567} Library Properties + Microsoft.Rest.Generator.AzureResourceSchema.Tests AutoRest.Generator.AzureResourceSchema.Tests AutoRest.Generator.AzureResourceSchema.Tests v4.5.2 @@ -33,6 +35,10 @@ 4 + + ..\..\..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -42,40 +48,104 @@ - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + ..\..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll True - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll + ..\..\..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll True - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll + ..\..\..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll True - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll + ..\..\..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll True + + + + + + + + + {c876085f-9dc3-41f0-b7b4-17022cd84684} + AutoRest.Core + - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + {c6c4e139-d7af-486c-95ba-2b879f58f18d} + AutoRest.Modeler.Swagger.Tests + {654344a5-0556-49c7-bfb3-59676d7440d3} AutoRest.Generator.AzureResourceSchema + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + +