diff --git a/README.md b/README.md index ff8bf3b1ad..0fbf6cf9d9 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,10 @@ The NSwag project heavily uses [NJsonSchema for .NET](http://njsonschema.org) fo **NuGet Packages** -- [NSwag.Core](https://www.nuget.org/packages/NSwag.Core/): The Swagger reader and writer classes ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.Core)) -- [NSwag.Annotations](https://www.nuget.org/packages/NSwag.Annotations/): Attributes to decorate Web API controllers to control the Swagger generation ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.Annotations)) -- [NSwag.CodeGeneration](https://www.nuget.org/packages/NSwag.CodeGeneration/): Classes to generate C# and TypeScript clients ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.CodeGeneration)) +- [NSwag.Core](https://www.nuget.org/packages/NSwag.Core/) (PCL 259): The Swagger reader and writer classes ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.Core)) +- [NSwag.Annotations](https://www.nuget.org/packages/NSwag.Annotations/) (PCL 259): Attributes to decorate Web API controllers to control the Swagger generation ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.Annotations)) +- [NSwag.CodeGeneration](https://www.nuget.org/packages/NSwag.CodeGeneration/) (PCL 259): Classes to generate C# and TypeScript clients ([Source Code](https://github.com/NSwag/NSwag/tree/master/src/NSwag.CodeGeneration)) +- [NSwag.AssemblyLoader](https://www.nuget.org/packages/NSwag.AssemblyLoader/) (.NET 4.5+): Classes to load assemblies in an isolated AppDomain and generate Swagger specs from Web API controllers ### Usage in C# diff --git a/src/NSwag.Annotations/Properties/AssemblyInfo.cs b/src/NSwag.Annotations/Properties/AssemblyInfo.cs index b62a49ec3c..614651799e 100644 --- a/src/NSwag.Annotations/Properties/AssemblyInfo.cs +++ b/src/NSwag.Annotations/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwag.Annotations")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index 6807d06705..36051cdcac 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -39,8 +39,8 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True diff --git a/src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs b/src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs index db7d68752f..aae7d4961f 100644 --- a/src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs +++ b/src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwag.AssemblyLoader")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwag.AssemblyLoader/app.config b/src/NSwag.AssemblyLoader/app.config index ccc9ddf44d..a9acb11a1a 100644 --- a/src/NSwag.AssemblyLoader/app.config +++ b/src/NSwag.AssemblyLoader/app.config @@ -4,7 +4,7 @@ - + diff --git a/src/NSwag.AssemblyLoader/packages.config b/src/NSwag.AssemblyLoader/packages.config index 1dc1ea8003..6787c3ca25 100644 --- a/src/NSwag.AssemblyLoader/packages.config +++ b/src/NSwag.AssemblyLoader/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj index e7783b4d12..89dc1f34f8 100644 --- a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj +++ b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj @@ -39,12 +39,12 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True - - ..\packages\NJsonSchema.CodeGeneration.2.18.5976.28451\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.2.19.5978.21535\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll True diff --git a/src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs b/src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs index d5718d7b1c..46dd1e37e3 100644 --- a/src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs +++ b/src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("2.21.*")] +// [assembly: AssemblyVersion("2.22.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/NSwag.CodeGeneration.Tests/packages.config b/src/NSwag.CodeGeneration.Tests/packages.config index c1ec64e199..3ab13fdaa3 100644 --- a/src/NSwag.CodeGeneration.Tests/packages.config +++ b/src/NSwag.CodeGeneration.Tests/packages.config @@ -3,6 +3,6 @@ - - + + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs index e2611e3088..789685573a 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs @@ -62,13 +62,14 @@ internal override string RenderFile(string clientCode) var template = new FileTemplate(); template.Initialize(new { - Toolchain = SwaggerService.ToolchainVersion, - IsAngular2 = Settings.GenerateClientClasses && Settings.Template == TypeScriptTemplate.Angular2, + Toolchain = SwaggerService.ToolchainVersion, + IsAngular2 = Settings.GenerateClientClasses && Settings.Template == TypeScriptTemplate.Angular2, - Clients = Settings.GenerateClientClasses ? clientCode : string.Empty, + Clients = Settings.GenerateClientClasses ? clientCode : string.Empty, Interfaces = Settings.GenerateDtoTypes ? _resolver.GenerateTypes() : string.Empty, + AdditionalCode = Settings.TypeScriptGeneratorSettings.TransformedAdditionalCode, - HasModuleName = !string.IsNullOrEmpty(Settings.ModuleName), + HasModuleName = !string.IsNullOrEmpty(Settings.ModuleName), ModuleName = Settings.ModuleName }); return template.Render(); @@ -85,15 +86,16 @@ internal override string RenderClientCode(string controllerName, IEnumerable - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True - - ..\packages\NJsonSchema.CodeGeneration.2.18.5976.28451\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.2.19.5978.21535\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll True diff --git a/src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs b/src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs index 1f32965678..eddf421009 100644 --- a/src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs +++ b/src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwag.CodeGeneration")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwag.CodeGeneration/packages.config b/src/NSwag.CodeGeneration/packages.config index 0f734864b7..06d984ef11 100644 --- a/src/NSwag.CodeGeneration/packages.config +++ b/src/NSwag.CodeGeneration/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index d707e2053a..2a089d72aa 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -46,8 +46,8 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True diff --git a/src/NSwag.Core/Properties/AssemblyInfo.cs b/src/NSwag.Core/Properties/AssemblyInfo.cs index d5cf758823..6d502efa5a 100644 --- a/src/NSwag.Core/Properties/AssemblyInfo.cs +++ b/src/NSwag.Core/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwag")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwag.Core/packages.config b/src/NSwag.Core/packages.config index a73e89bf4e..a78ec281ca 100644 --- a/src/NSwag.Core/packages.config +++ b/src/NSwag.Core/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/NSwag.Demo.Client/Properties/AssemblyInfo.cs b/src/NSwag.Demo.Client/Properties/AssemblyInfo.cs index e6f8ee2d74..c3d78f1a9a 100644 --- a/src/NSwag.Demo.Client/Properties/AssemblyInfo.cs +++ b/src/NSwag.Demo.Client/Properties/AssemblyInfo.cs @@ -50,6 +50,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("2.21.*")] +// [assembly: AssemblyVersion("2.22.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj index 23701a9d7a..df9aa34308 100644 --- a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj +++ b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj @@ -47,8 +47,8 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True diff --git a/src/NSwag.Demo.Web/Web.config b/src/NSwag.Demo.Web/Web.config index 6f57576599..cf6d93b764 100644 --- a/src/NSwag.Demo.Web/Web.config +++ b/src/NSwag.Demo.Web/Web.config @@ -58,7 +58,7 @@ - + diff --git a/src/NSwag.Demo.Web/packages.config b/src/NSwag.Demo.Web/packages.config index 39549b1bf5..e06eb20c62 100644 --- a/src/NSwag.Demo.Web/packages.config +++ b/src/NSwag.Demo.Web/packages.config @@ -7,5 +7,5 @@ - + \ No newline at end of file diff --git a/src/NSwag.Tests/NSwag.Tests.csproj b/src/NSwag.Tests/NSwag.Tests.csproj index 629f6e97b4..98a95a19cf 100644 --- a/src/NSwag.Tests/NSwag.Tests.csproj +++ b/src/NSwag.Tests/NSwag.Tests.csproj @@ -39,8 +39,8 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True diff --git a/src/NSwag.Tests/Properties/AssemblyInfo.cs b/src/NSwag.Tests/Properties/AssemblyInfo.cs index 70cdafa218..41f3180efd 100644 --- a/src/NSwag.Tests/Properties/AssemblyInfo.cs +++ b/src/NSwag.Tests/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("2.21.*")] +// [assembly: AssemblyVersion("2.22.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/NSwag.Tests/app.config b/src/NSwag.Tests/app.config index f9e9e96f04..4a93b8a4a7 100644 --- a/src/NSwag.Tests/app.config +++ b/src/NSwag.Tests/app.config @@ -8,7 +8,7 @@ - + diff --git a/src/NSwag.Tests/packages.config b/src/NSwag.Tests/packages.config index a25347c1f6..cdfde686ae 100644 --- a/src/NSwag.Tests/packages.config +++ b/src/NSwag.Tests/packages.config @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/src/NSwag/Commands/SwaggerToTypeScriptCommand.cs b/src/NSwag/Commands/SwaggerToTypeScriptCommand.cs index 8fef6f6435..b7abed2d51 100644 --- a/src/NSwag/Commands/SwaggerToTypeScriptCommand.cs +++ b/src/NSwag/Commands/SwaggerToTypeScriptCommand.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.IO; using System.Threading.Tasks; using NConsole; using Newtonsoft.Json; @@ -100,6 +101,19 @@ public TypeScriptTypeStyle TypeStyle set { Settings.TypeScriptGeneratorSettings.TypeStyle = value; } } + // TODO: Implement a way to pass mappings via cmd line + //[Description("Type class mappings.")] + //[Argument(Name = "ClassMappings", DefaultValue = null)] + public TypeScriptClassMapping[] ClassMappings + { + get { return Settings.TypeScriptGeneratorSettings.ClassMappings; } + set { Settings.TypeScriptGeneratorSettings.ClassMappings = value; } + } + + [Description("The additional code (string or file path).")] + [Argument(Name = "AdditionalCode", DefaultValue = "")] + public string AdditionalCode { get; set; } + public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var output = await RunAsync(); @@ -108,6 +122,11 @@ public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost public async Task RunAsync() { + var additionalCode = AdditionalCode ?? ""; + if (File.Exists(additionalCode)) + additionalCode = File.ReadAllText(additionalCode); + Settings.TypeScriptGeneratorSettings.AdditionalCode = additionalCode; + var clientGenerator = new SwaggerToTypeScriptClientGenerator(InputSwaggerService, Settings); return clientGenerator.GenerateFile(); } diff --git a/src/NSwag/NSwag.csproj b/src/NSwag/NSwag.csproj index 92a6fd0de1..66b929af98 100644 --- a/src/NSwag/NSwag.csproj +++ b/src/NSwag/NSwag.csproj @@ -42,12 +42,12 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True - - ..\packages\NJsonSchema.CodeGeneration.2.18.5976.28451\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.2.19.5978.21535\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll True diff --git a/src/NSwag/Properties/AssemblyInfo.cs b/src/NSwag/Properties/AssemblyInfo.cs index 0dd1354944..a5970051bf 100644 --- a/src/NSwag/Properties/AssemblyInfo.cs +++ b/src/NSwag/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwag.Console")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwag/packages.config b/src/NSwag/packages.config index 5b9fe1b721..f487aed64c 100644 --- a/src/NSwag/packages.config +++ b/src/NSwag/packages.config @@ -2,6 +2,6 @@ - - + + \ No newline at end of file diff --git a/src/NSwagStudio.Installer/Generated.wxs b/src/NSwagStudio.Installer/Generated.wxs index 3c95a5c83a..f3259a60dc 100644 --- a/src/NSwagStudio.Installer/Generated.wxs +++ b/src/NSwagStudio.Installer/Generated.wxs @@ -516,197 +516,197 @@ - - + + - - - - + - + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - + - + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -715,128 +715,128 @@ - - + + - - + + - - + + - - + + - + - - - - - + + - + - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -845,507 +845,504 @@ - - - - - + + - + - - + + - - + + - - + + - + - - + + - + - - - - - + + - - + + - + - - + + - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + - - + + - - + + - + - + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + - - + + - + - - - - + - - - - + - + - + + + + + + + - + - - - - - + + - + - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1359,6 +1356,9 @@ + + + diff --git a/src/NSwagStudio/NSwagDocument.cs b/src/NSwagStudio/NSwagDocument.cs index c451dcedd3..ef723a1122 100644 --- a/src/NSwagStudio/NSwagDocument.cs +++ b/src/NSwagStudio/NSwagDocument.cs @@ -6,9 +6,11 @@ // Rico Suter, mail@rsuter.com //----------------------------------------------------------------------- +using System.Collections.Generic; using System.IO; using MyToolkit.Model; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using NSwag.Commands; using NSwagStudio.Utilities; @@ -54,8 +56,14 @@ public static NSwagDocument LoadDocument(string filePath) public void Save() { ConvertToRelativePaths(); - - _latestData = JsonConvert.SerializeObject(this, Formatting.Indented); + + _latestData = JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings + { + Converters = new List + { + new StringEnumConverter() + } + }); ConvertToAbsolutePaths(); File.WriteAllText(Path, _latestData); } @@ -66,6 +74,8 @@ private void ConvertToAbsolutePaths() AssemblyTypeToSwaggerCommand.AssemblyPath = ConvertToAbsolute(AssemblyTypeToSwaggerCommand.AssemblyPath); WebApiToSwaggerCommand.AssemblyConfig = ConvertToAbsolute(WebApiToSwaggerCommand.AssemblyConfig); AssemblyTypeToSwaggerCommand.AssemblyConfig = ConvertToAbsolute(AssemblyTypeToSwaggerCommand.AssemblyConfig); + + SwaggerToTypeScriptCommand.AdditionalCode = ConvertToAbsolute(SwaggerToTypeScriptCommand.AdditionalCode); } private string ConvertToAbsolute(string path) @@ -81,13 +91,15 @@ private void ConvertToRelativePaths() AssemblyTypeToSwaggerCommand.AssemblyPath = ConvertToRelativePath(AssemblyTypeToSwaggerCommand.AssemblyPath); WebApiToSwaggerCommand.AssemblyConfig = ConvertToRelativePath(WebApiToSwaggerCommand.AssemblyConfig); AssemblyTypeToSwaggerCommand.AssemblyConfig = ConvertToRelativePath(AssemblyTypeToSwaggerCommand.AssemblyConfig); + + SwaggerToTypeScriptCommand.AdditionalCode = ConvertToRelativePath(SwaggerToTypeScriptCommand.AdditionalCode); } private string ConvertToRelativePath(string path) { if (!string.IsNullOrEmpty(path)) return PathUtilities.MakeRelativePath(path, System.IO.Path.GetDirectoryName(Path)); - return path; + return path; } public static NSwagDocument CreateDocument() @@ -113,7 +125,13 @@ public string Path public string Name => System.IO.Path.GetFileName(Path); [JsonIgnore] - public bool IsDirty => _latestData != JsonConvert.SerializeObject(this, Formatting.Indented); + public bool IsDirty => _latestData != JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings + { + Converters = new List + { + new StringEnumConverter() + } + }); /// Gets or sets the selected Swagger generator. [JsonProperty("SelectedSwaggerGenerator")] @@ -136,7 +154,7 @@ public int SelectedClientGenerator [JsonProperty("InputSwaggerUrl")] public string InputSwaggerUrl { get; set; } - + [JsonProperty("InputJsonSchema")] public string InputJsonSchema { get; set; } diff --git a/src/NSwagStudio/NSwagStudio.csproj b/src/NSwagStudio/NSwagStudio.csproj index 2d94cb7490..1d13f2ad91 100644 --- a/src/NSwagStudio/NSwagStudio.csproj +++ b/src/NSwagStudio/NSwagStudio.csproj @@ -70,12 +70,12 @@ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.2.18.5976.28450\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll + + ..\packages\NJsonSchema.2.19.5978.21534\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll True - - ..\packages\NJsonSchema.CodeGeneration.2.18.5976.28451\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.2.19.5978.21535\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll True diff --git a/src/NSwagStudio/Properties/AssemblyInfo.cs b/src/NSwagStudio/Properties/AssemblyInfo.cs index 4bfad1fe6d..64a1552fae 100644 --- a/src/NSwagStudio/Properties/AssemblyInfo.cs +++ b/src/NSwagStudio/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Rico Suter")] [assembly: AssemblyProduct("NSwagStudio")] [assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")] -[assembly: AssemblyVersion("2.21.*")] +[assembly: AssemblyVersion("2.22.*")] diff --git a/src/NSwagStudio/ViewModels/CodeGenerators/TypeScriptClientGeneratorViewModel.cs b/src/NSwagStudio/ViewModels/CodeGenerators/TypeScriptClientGeneratorViewModel.cs index c8b8df71b9..b14822cc3e 100644 --- a/src/NSwagStudio/ViewModels/CodeGenerators/TypeScriptClientGeneratorViewModel.cs +++ b/src/NSwagStudio/ViewModels/CodeGenerators/TypeScriptClientGeneratorViewModel.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows; using MyToolkit.Storage; +using Newtonsoft.Json; using NJsonSchema.CodeGeneration.TypeScript; using NSwag.CodeGeneration.CodeGenerators; using NSwag.CodeGeneration.CodeGenerators.TypeScript; @@ -45,7 +46,7 @@ public TypeScriptTemplate[] Templates { get { return Enum.GetNames(typeof(TypeScriptTemplate)).Select(t => (TypeScriptTemplate)Enum.Parse(typeof(TypeScriptTemplate), t)).ToArray(); } } - + /// Gets the operation modes. public OperationGenerationMode[] OperationGenerationModes { @@ -69,6 +70,22 @@ public TypeScriptTypeStyle[] TypeStyles } } + public string ClassMappings + { + get { return _command.ClassMappings != null ? JsonConvert.SerializeObject(_command.ClassMappings, Formatting.Indented) : "[]"; } + set + { + try + { + _command.ClassMappings = JsonConvert.DeserializeObject(value); + } + catch + { + _command.ClassMappings = new TypeScriptClassMapping[] { }; + } + RaisePropertyChanged(); + } + } /// Gets or sets the client code. public string ClientCode diff --git a/src/NSwagStudio/Views/CodeGenerators/TypeScriptClientGeneratorView.xaml b/src/NSwagStudio/Views/CodeGenerators/TypeScriptClientGeneratorView.xaml index 1b657a9fe1..6cc8d2a81e 100644 --- a/src/NSwagStudio/Views/CodeGenerators/TypeScriptClientGeneratorView.xaml +++ b/src/NSwagStudio/Views/CodeGenerators/TypeScriptClientGeneratorView.xaml @@ -83,6 +83,15 @@ + + + + + + diff --git a/src/NSwagStudio/packages.config b/src/NSwagStudio/packages.config index 5ee64802de..5feadf9112 100644 --- a/src/NSwagStudio/packages.config +++ b/src/NSwagStudio/packages.config @@ -7,6 +7,6 @@ - - + + \ No newline at end of file diff --git a/src/Samples/DemoWeb.nswag b/src/Samples/DemoWeb.nswag index b3315cbc1a..7381db97d7 100644 --- a/src/Samples/DemoWeb.nswag +++ b/src/Samples/DemoWeb.nswag @@ -9,12 +9,10 @@ "ReferencePaths": [], "ControllerName": "", "ControllerNames": [ - "NSwag.Demo.Web.Controllers.FileController", - "NSwag.Demo.Web.Controllers.PersonsController", - "NSwag.Demo.Web.Controllers.RequestParameterTestController" + "NSwag.Demo.Web.Controllers.PersonsController" ], "DefaultUrlTemplate": "api/{controller}/{action}/{id}", - "DefaultEnumHandling": 0, + "DefaultEnumHandling": "Integer", "FlattenInheritanceHierarchy": false, "GenerateKnownTypes": true, "OutputFilePath": null @@ -23,7 +21,7 @@ "AssemblyPath": null, "AssemblyConfig": null, "ReferencePaths": [], - "DefaultEnumHandling": 0, + "DefaultEnumHandling": "Integer", "FlattenInheritanceHierarchy": false, "GenerateKnownTypes": true, "ClassNames": [], @@ -32,14 +30,26 @@ "SwaggerToTypeScriptCommand": { "ClassName": "{controller}Client", "ModuleName": "", - "Template": 3, - "PromiseType": 0, + "Template": "JQueryPromises", + "PromiseType": "Promise", "GenerateClientClasses": true, - "GenerateClientInterfaces": true, + "GenerateClientInterfaces": false, "GenerateDtoTypes": true, - "OperationGenerationMode": 0, - "GenerateReadOnlyKeywords": false, - "TypeStyle": 1, + "OperationGenerationMode": "MultipleClientsFromOperationId", + "GenerateReadOnlyKeywords": true, + "TypeStyle": "Class", + "ClassMappings": [ + { + "Class": "Person", + "TargetModule": "MyModule", + "TargetClass": "MyPerson" + }, + { + "Class": "Car", + "TargetModule": "MyModule", + "TargetClass": "MyCar" + } + ], "Input": null, "OutputFilePath": null }, @@ -58,14 +68,14 @@ "DateTimeType": "DateTime", "ArrayType": "ObservableCollection", "DictionaryType": "Dictionary", - "ClassStyle": 0 + "ClassStyle": "Poco" }, "ClassName": "{controller}Client", "AdditionalNamespaceUsages": [ "a", "b" ], - "OperationGenerationMode": 0, + "OperationGenerationMode": "MultipleClientsFromOperationId", "GenerateDtoTypes": true, "GenerateClientInterfaces": true, "GenerateClientClasses": true @@ -80,8 +90,8 @@ "DateTimeType": "DateTime", "ArrayType": "ObservableCollection", "DictionaryType": "Dictionary", - "ClassStyle": 0, - "OperationGenerationMode": 0, + "ClassStyle": "Poco", + "OperationGenerationMode": "MultipleClientsFromOperationId", "Input": null, "OutputFilePath": null }, @@ -95,13 +105,13 @@ "DateTimeType": "DateTime", "ArrayType": "IEnumerable", "DictionaryType": "Dictionary", - "ClassStyle": 1 + "ClassStyle": "Inpc" }, "ClassName": "{controller}", "AdditionalNamespaceUsages": [ "System.Web.Http" ], - "OperationGenerationMode": 0, + "OperationGenerationMode": "MultipleClientsFromOperationId", "GenerateDtoTypes": true, "GenerateClientInterfaces": false, "GenerateClientClasses": true @@ -115,8 +125,8 @@ "DateTimeType": "DateTime", "ArrayType": "IEnumerable", "DictionaryType": "Dictionary", - "ClassStyle": 1, - "OperationGenerationMode": 0, + "ClassStyle": "Inpc", + "OperationGenerationMode": "MultipleClientsFromOperationId", "Input": null, "OutputFilePath": null }