Skip to content

Commit

Permalink
Merge pull request #143 from NSwag/master
Browse files Browse the repository at this point in the history
Release v2.39
  • Loading branch information
RicoSuter committed May 29, 2016
2 parents 169515e + d2221bd commit 4d7a95d
Show file tree
Hide file tree
Showing 28 changed files with 875 additions and 873 deletions.
2 changes: 1 addition & 1 deletion src/NSwag.Annotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.Annotations")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.38.*")]
[assembly: AssemblyVersion("2.39.*")]
2 changes: 1 addition & 1 deletion src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.AssemblyLoader")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.38.*")]
[assembly: AssemblyVersion("2.39.*")]
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.38.*")]
// [assembly: AssemblyVersion("2.39.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.CodeGeneration")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.38.*")]
[assembly: AssemblyVersion("2.39.*")]
2 changes: 1 addition & 1 deletion src/NSwag.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.38.*")]
[assembly: AssemblyVersion("2.39.*")]
2 changes: 1 addition & 1 deletion src/NSwag.Demo.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.38.*")]
// [assembly: AssemblyVersion("2.39.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion src/NSwag.MSBuild/NSwag.MSBuild.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>NSwag.MSBuild</id>
<version>2.38</version>
<version>2.39</version>
<authors>Rico Suter</authors>
<owners>Rico Suter</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.38.*")]
// [assembly: AssemblyVersion("2.39.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
24 changes: 13 additions & 11 deletions src/NSwag/Commands/AssemblyTypeToSwaggerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class AssemblyTypeToSwaggerCommand : OutputCommandBase
public AssemblyTypeToSwaggerCommand()
{
Settings = new AssemblyTypeToSwaggerGeneratorSettings();
ClassNames = new string[] { };
}

[JsonIgnore]
Expand All @@ -27,6 +26,10 @@ public string AssemblyPath
set { Settings.AssemblyPath = value; }
}

[Description("The class names.")]
[Argument(Name = "ClassNames")]
public string[] ClassNames { get; set; }

[Description("The path to the assembly App.config or Web.config (optional).")]
[Argument(Name = "AssemblyConfig", IsRequired = false)]
public string AssemblyConfig
Expand All @@ -44,7 +47,7 @@ public string[] ReferencePaths
}

[Description("The default enum handling ('String' or 'Integer'), default: Integer.")]
[Argument(Name = "DefaultEnumHandling", IsRequired = true)]
[Argument(Name = "DefaultEnumHandling", IsRequired = false)]
public EnumHandling DefaultEnumHandling
{
get { return Settings.DefaultEnumHandling; }
Expand All @@ -67,21 +70,20 @@ public bool GenerateKnownTypes
set { Settings.GenerateKnownTypes = value; }
}

[Description("The class names.")]
[Argument(Name = "ClassNames", IsRequired = false)]
public string[] ClassNames { get; set; }

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var service = Run();
WriteFileOutput(host, () => service.ToJson());
var service = await RunAsync();
TryWriteFileOutput(host, () => service.ToJson());
return service;
}

public SwaggerService Run()
public async Task<SwaggerService> RunAsync()
{
var generator = new AssemblyTypeToSwaggerGenerator(Settings);
return generator.Generate(ClassNames);
return await Task.Run(() =>
{
var generator = new AssemblyTypeToSwaggerGenerator(Settings);
return generator.Generate(ClassNames);
});
}
}
}
14 changes: 10 additions & 4 deletions src/NSwag/Commands/Base/InputOutputCommandBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
Expand All @@ -10,20 +11,22 @@ namespace NSwag.Commands.Base
public abstract class InputOutputCommandBase : OutputCommandBase
{
[Description("A file path or URL to the data or the JSON data itself.")]
[Argument(Name = "Input", AcceptsCommandInput = true, IsRequired = true)]
[Argument(Name = "Input", IsRequired = true, AcceptsCommandInput = true)]
public object Input { get; set; }

/// <exception cref="ArgumentException" accessor="get">The argument 'Input' was empty.</exception>
[JsonIgnore]
protected SwaggerService InputSwaggerService
{
get
{
if (Input is SwaggerService)
return (SwaggerService)Input;
var swaggerService = Input as SwaggerService;
if (swaggerService != null)
return swaggerService;

var inputString = Input.ToString();
if (string.IsNullOrEmpty(inputString))
return null;
throw new ArgumentException("The argument 'Input' was empty.");

if (IsJson(inputString))
return SwaggerService.FromJson(inputString);
Expand All @@ -35,12 +38,15 @@ protected SwaggerService InputSwaggerService
}
}

/// <exception cref="ArgumentException" accessor="get">The argument 'Input' was empty.</exception>
[JsonIgnore]
protected string InputJson
{
get
{
var inputString = Input.ToString();
if (string.IsNullOrEmpty(inputString))
throw new ArgumentException("The argument 'Input' was empty.");

if (IsJson(inputString))
return inputString;
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag/Commands/Base/OutputCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class OutputCommandBase : IConsoleCommand

public abstract Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host);

protected void WriteFileOutput(IConsoleHost host, Func<string> generator)
protected void TryWriteFileOutput(IConsoleHost host, Func<string> generator)
{
if (!string.IsNullOrEmpty(OutputFilePath))
{
Expand Down
15 changes: 5 additions & 10 deletions src/NSwag/Commands/JsonSchemaToCSharpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public class JsonSchemaToCSharpCommand : InputOutputCommandBase
[Argument(Name = "DictionaryType", IsRequired = false)]
public string DictionaryType { get; set; } = "Dictionary";

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var code = Run();
WriteFileOutput(host, () => code);
return code;
}

public string Run()
public override Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var settings = new CSharpGeneratorSettings
{
Expand All @@ -47,10 +40,12 @@ public string Run()
ArrayType = ArrayType,
DictionaryType = DictionaryType,
};

var schema = JsonSchema4.FromJson(InputJson);
var generator = new CSharpGenerator(schema, settings);
return generator.GenerateFile();
var code = generator.GenerateFile();
TryWriteFileOutput(host, () => code);
return Task.FromResult<object>(code);
}
}
}
13 changes: 4 additions & 9 deletions src/NSwag/Commands/JsonSchemaToTypeScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ namespace NSwag.Commands
[Description("Generates TypeScript interfaces from a JSON Schema.")]
public class JsonSchemaToTypeScriptCommand : InputOutputCommandBase
{
public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var code = Run();
WriteFileOutput(host, () => code);
return code;
}

public string Run()
public override Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var schema = JsonSchema4.FromJson(InputJson);
var generator = new TypeScriptGenerator(schema);
return generator.GenerateFile();
var code = generator.GenerateFile();
TryWriteFileOutput(host, () => code);
return Task.FromResult<object>(code);
}
}
}
13 changes: 8 additions & 5 deletions src/NSwag/Commands/SwaggerToCSharpClientCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ public bool UseHttpClientCreationMethod

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var code = Run();
WriteFileOutput(host, () => code);
var code = await RunAsync();
TryWriteFileOutput(host, () => code);
return code;
}

public string Run()
public async Task<string> RunAsync()
{
var clientGenerator = new SwaggerToCSharpClientGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
return await Task.Run(() =>
{
var clientGenerator = new SwaggerToCSharpClientGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
});
}
}
}
13 changes: 8 additions & 5 deletions src/NSwag/Commands/SwaggerToCSharpControllerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ public string ControllerBaseClass

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var code = Run();
WriteFileOutput(host, () => code);
var code = await RunAsync();
TryWriteFileOutput(host, () => code);
return code;
}

public string Run()
public async Task<string> RunAsync()
{
var clientGenerator = new SwaggerToCSharpWebApiControllerGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
return await Task.Run(() =>
{
var clientGenerator = new SwaggerToCSharpWebApiControllerGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
});
}
}
}
25 changes: 13 additions & 12 deletions src/NSwag/Commands/SwaggerToTypeScriptClientCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,23 @@ public string[] ExtendedClasses

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
host.WriteMessage("Generating TypeScript code...\n");

var code = Run();
WriteFileOutput(host, () => code);
var code = await RunAsync();
TryWriteFileOutput(host, () => code);
return code;
}

public string Run()
public async Task<string> RunAsync()
{
var additionalCode = ExtensionCode ?? string.Empty;
if (File.Exists(additionalCode))
additionalCode = File.ReadAllText(additionalCode);
Settings.TypeScriptGeneratorSettings.ExtensionCode = additionalCode;

var clientGenerator = new SwaggerToTypeScriptClientGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
return await Task.Run(() =>
{
var additionalCode = ExtensionCode ?? string.Empty;
if (File.Exists(additionalCode))
additionalCode = File.ReadAllText(additionalCode);
Settings.TypeScriptGeneratorSettings.ExtensionCode = additionalCode;

var clientGenerator = new SwaggerToTypeScriptClientGenerator(InputSwaggerService, Settings);
return clientGenerator.GenerateFile();
});
}
}
}
29 changes: 16 additions & 13 deletions src/NSwag/Commands/WebApiToSwaggerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -15,7 +16,6 @@ public class WebApiToSwaggerCommand : OutputCommandBase
public WebApiToSwaggerCommand()
{
Settings = new WebApiAssemblyToSwaggerGeneratorSettings();
ReferencePaths = new string[] { };
ControllerNames = new string[] { };
}

Expand Down Expand Up @@ -50,7 +50,7 @@ public string[] ReferencePaths
[Argument(Name = "Controller", IsRequired = false)]
public string ControllerName { get; set; }

[Description("The Web API controller full class names or empty to load all controllers from the assembly.")]
[Description("The Web API controller full class names or empty to load all controllers from the assembly (comma separated).")]
[Argument(Name = "Controllers", IsRequired = false)]
public string[] ControllerNames { get; set; }

Expand Down Expand Up @@ -88,24 +88,27 @@ public bool GenerateKnownTypes

public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
{
var service = Run();
WriteFileOutput(host, () => service.ToJson());
var service = await RunAsync();
TryWriteFileOutput(host, () => service.ToJson());
return service;
}

public SwaggerService Run()
public async Task<SwaggerService> RunAsync()
{
var generator = new WebApiAssemblyToSwaggerGenerator(Settings);
return await Task.Run(() =>
{
var generator = new WebApiAssemblyToSwaggerGenerator(Settings);

var controllerNames = ControllerNames.ToList();
if (!string.IsNullOrEmpty(ControllerName))
controllerNames.Add(ControllerName);
var controllerNames = ControllerNames.ToList();
if (!string.IsNullOrEmpty(ControllerName))
controllerNames.Add(ControllerName);

controllerNames = controllerNames.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
if (!controllerNames.Any() && !string.IsNullOrEmpty(Settings.AssemblyPath))
controllerNames = generator.GetControllerClasses().ToList();
controllerNames = controllerNames.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
if (!controllerNames.Any() && !string.IsNullOrEmpty(Settings.AssemblyPath))
controllerNames = generator.GetControllerClasses().ToList();

return generator.GenerateForControllers(controllerNames);
return generator.GenerateForControllers(controllerNames);
});
}
}
}
2 changes: 1 addition & 1 deletion src/NSwag/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.Console")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.38.*")]
[assembly: AssemblyVersion("2.39.*")]
Loading

0 comments on commit 4d7a95d

Please sign in to comment.