Skip to content

Commit

Permalink
Merge pull request #126 from NSwag/master
Browse files Browse the repository at this point in the history
Release v2.31
  • Loading branch information
RicoSuter committed May 20, 2016
2 parents 8cb870a + 2d20150 commit a484a37
Showing 39 changed files with 718 additions and 354 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NSwag: The Swagger API toolchain for .NET and TypeScript

[![NuGet Version](https://badge.fury.io/nu/nswag.core.svg)](https://www.nuget.org/packages?q=NSwag)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-1dce73.svg)](https://gitter.im/NSwag/NSwag)
[![Build status](https://ci.appveyor.com/api/projects/status/aajfgxqf5dic7tkk?svg=true)](https://ci.appveyor.com/project/rsuter/nswag)
CI: [![Build status](https://ci.appveyor.com/api/projects/status/sfoha01b3i841iky?svg=true)](https://ci.appveyor.com/project/rsuter/nswag-25x6o)

2 changes: 1 addition & 1 deletion src/NSwag.Annotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.Annotations")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.30.*")]
[assembly: AssemblyVersion("2.31.*")]
4 changes: 2 additions & 2 deletions src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=2.21.5981.35957, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.21.5981.35957\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Reference Include="NJsonSchema, Version=2.22.5984.16716, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.22.5984.16716\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
2 changes: 1 addition & 1 deletion src/NSwag.AssemblyLoader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.AssemblyLoader")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.30.*")]
[assembly: AssemblyVersion("2.31.*")]
Original file line number Diff line number Diff line change
@@ -31,14 +31,18 @@ public WebApiAssemblyToSwaggerGenerator(WebApiAssemblyToSwaggerGeneratorSettings

/// <summary>Gets the available controller classes from the given assembly.</summary>
/// <returns>The controller classes.</returns>
/// <exception cref="FileNotFoundException">The assembly could not be found.</exception>
/// <exception cref="FileNotFoundException">The assembly config file could not be found..</exception>
public string[] GetControllerClasses()
{
if (File.Exists(Settings.AssemblyPath))
{
using (var isolated = new AppDomainIsolation<WebApiAssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath), Settings.AssemblyConfig))
return isolated.Object.GetControllerClasses(Settings.AssemblyPath, Settings.ReferencePaths);
}
return new string[] { };
if (!File.Exists(Settings.AssemblyPath))
throw new FileNotFoundException("The assembly could not be found.", Settings.AssemblyPath);

if (!string.IsNullOrEmpty(Settings.AssemblyConfig) && !File.Exists(Settings.AssemblyConfig))
throw new FileNotFoundException("The assembly config file could not be found.", Settings.AssemblyConfig);

using (var isolated = new AppDomainIsolation<WebApiAssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath), Settings.AssemblyConfig))
return isolated.Object.GetControllerClasses(Settings.AssemblyPath, Settings.ReferencePaths);
}

/// <summary>Generates the Swagger definition for the given controller.</summary>
2 changes: 1 addition & 1 deletion src/NSwag.AssemblyLoader/app.config
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NJsonSchema" publicKeyToken="c2f9c3bdfae56102" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.21.5981.35957" newVersion="2.21.5981.35957" />
<bindingRedirect oldVersion="0.0.0.0-2.22.5984.16716" newVersion="2.22.5984.16716" />
</dependentAssembly>
</assemblyBinding>
</runtime>
2 changes: 1 addition & 1 deletion src/NSwag.AssemblyLoader/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
<package id="NJsonSchema" version="2.21.5981.35957" targetFramework="net45" />
<package id="NJsonSchema" version="2.22.5984.16716" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
@@ -39,12 +39,12 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=2.21.5981.35957, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.21.5981.35957\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Reference Include="NJsonSchema, Version=2.22.5984.16716, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.22.5984.16716\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema.CodeGeneration, Version=2.21.5981.35959, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.2.21.5981.35959\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll</HintPath>
<Reference Include="NJsonSchema.CodeGeneration, Version=2.22.5984.16718, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.2.22.5984.16718\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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.30.*")]
// [assembly: AssemblyVersion("2.31.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NJsonSchema" version="2.21.5981.35957" targetFramework="net45" />
<package id="NJsonSchema.CodeGeneration" version="2.21.5981.35959" targetFramework="net45" />
<package id="NJsonSchema" version="2.22.5984.16716" targetFramework="net45" />
<package id="NJsonSchema.CodeGeneration" version="2.22.5984.16718" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
@@ -1288,39 +1288,39 @@ public virtual string TransformText()

#line default
#line hidden
this.Write(" {\r\n");
this.Write("\r\n {\r\n");

#line 178 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 179 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
if(operation.HasDefaultResponse){

#line default
#line hidden
this.Write(" var result_ = default(");

#line 179 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 180 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type));

#line default
#line hidden
this.Write("); \r\n try\r\n {\r\n if (responseData_.Length > 0" +
")\r\n result_ = JsonConvert.DeserializeObject<");

#line 183 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 184 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type));

#line default
#line hidden
this.Write(">(Encoding.UTF8.GetString(responseData_));\r\n\r\n");

#line 185 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 186 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
if(operation.HasOnlyDefaultResponse){

#line default
#line hidden
this.Write(" if (status_.Length == 3 && status_.StartsWith(\"2\"))\r\n " +
" return result_;\r\n");

#line 188 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 189 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
}

#line default
@@ -1333,15 +1333,15 @@ public virtual string TransformText()
throw new SwaggerException<");

#line 195 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 196 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type));

#line default
#line hidden
this.Write(">(\"A server side error occurred.\", response_.StatusCode, responseData_, result_, " +
"null);\r\n");

#line 196 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 197 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
}

#line default
@@ -1350,7 +1350,7 @@ public virtual string TransformText()
"onse was not expected (\" + (int)response_.StatusCode + \").\", response_.StatusCod" +
"e, responseData_, null);\r\n }\r\n\r\n");

#line 202 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 203 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
}

#line default
@@ -1388,7 +1388,7 @@ public SwaggerException(string message, HttpStatusCode statusCode, byte[] respon
}
");

#line 234 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
#line 235 "C:\Data\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\ClientTemplate.tt"
}

#line default
Original file line number Diff line number Diff line change
@@ -174,6 +174,7 @@ public partial class <#=Model.Class#> <#if(Model.HasBaseType){#>: <#}#><#if(Mode
<#}#>
}
else<#}#>

{
<#if(operation.HasDefaultResponse){#>
var result_ = default(<#=operation.DefaultResponse.Type#>);
Original file line number Diff line number Diff line change
@@ -58,14 +58,14 @@ public string GetOperationName(SwaggerService service, string path, SwaggerOpera

private string GetClientName(SwaggerOperation operation)
{
var segments = operation.OperationId.Split('_');
return segments.Length >= 2 ? segments[0] : "Anonymous";
var segments = operation.OperationId.Split('_').Reverse().ToArray();
return segments.Length >= 2 ? segments[1] : string.Empty;
}

private string GetOperationName(SwaggerOperation operation)
{
var segments = operation.OperationId.Split('_');
return segments.Length >= 2 ? segments[1] : "Anonymous";
var segments = operation.OperationId.Split('_').Reverse().ToArray();
return segments.First();
}
}
}
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public class MultipleClientsFromPathSegmentsOperationNameGenerator : IOperationN
public string GetClientName(SwaggerService service, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation)
{
var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray();
return pathSegments.Length >= 2 ? pathSegments[1] : "Unknown";
return pathSegments.Length >= 2 ? pathSegments[1] : string.Empty;
}

/// <summary>Gets the client name for a given operation.</summary>
@@ -37,7 +37,7 @@ public string GetClientName(SwaggerService service, string path, SwaggerOperatio
public string GetOperationName(SwaggerService service, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation)
{
var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray();
return pathSegments.Length >= 1 ? pathSegments[0] : "Unknown";
return pathSegments.First();
}
}
}
8 changes: 4 additions & 4 deletions src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=2.21.5981.35957, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.21.5981.35957\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Reference Include="NJsonSchema, Version=2.22.5984.16716, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.22.5984.16716\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema.CodeGeneration, Version=2.21.5981.35959, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.2.21.5981.35959\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll</HintPath>
<Reference Include="NJsonSchema.CodeGeneration, Version=2.22.5984.16718, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.2.22.5984.16718\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.CodeGeneration")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.30.*")]
[assembly: AssemblyVersion("2.31.*")]
Original file line number Diff line number Diff line change
@@ -301,14 +301,7 @@ private void LoadParameters(SwaggerService service, SwaggerOperation operation,
{
foreach (var parameter in parameters)
{
// TODO: Refactor this
var isCollection = parameter.ParameterType.IsArray || parameter.ParameterType.GetTypeInfo().ImplementedInterfaces.Any(i => i.Name == "IEnumerable");
var parameterType = isCollection && parameter.ParameterType.GenericTypeArguments.Any() ? parameter.ParameterType.GenericTypeArguments[0] : parameter.ParameterType;
if (IsFileParameter(parameterType))
{
AddFileParameter(parameter, isCollection, operation, service, schemaResolver);
}
else
if (TryAddFileParameter(service, operation, schemaResolver, parameter) == false)
{
// http://blogs.msdn.com/b/jmstall/archive/2012/04/16/how-webapi-does-parameter-binding.aspx

@@ -343,6 +336,21 @@ private void LoadParameters(SwaggerService service, SwaggerOperation operation,
throw new InvalidOperationException("The operation '" + operation.OperationId + "' has more than one body parameter.");
}

private bool TryAddFileParameter(SwaggerService service, SwaggerOperation operation, ISchemaResolver schemaResolver, ParameterInfo parameter)
{
var isEnumerable = parameter.ParameterType.IsArray || parameter.ParameterType.GetTypeInfo().ImplementedInterfaces.Any(i => i.Name == "IEnumerable");
var parameterType = isEnumerable && parameter.ParameterType.GenericTypeArguments.Any()
? parameter.ParameterType.GenericTypeArguments[0]
: parameter.ParameterType;
var isFormFileCollection = parameter.ParameterType.Name == "IFormFileCollection";
if (IsFileParameter(parameterType) || isFormFileCollection)
{
AddFileParameter(parameter, isEnumerable || isFormFileCollection, operation, service, schemaResolver);
return true;
}
return false;
}

private static bool IsFileParameter(Type type)
{
var parameterTypeName = type.Name;
@@ -352,7 +360,7 @@ private static bool IsFileParameter(Type type)
type.InheritsFrom("HttpPostedFileBase");
}

private void AddFileParameter(ParameterInfo parameter, bool isCollection, SwaggerOperation operation, SwaggerService service, ISchemaResolver schemaResolver)
private void AddFileParameter(ParameterInfo parameter, bool isEnumerable, SwaggerOperation operation, SwaggerService service, ISchemaResolver schemaResolver)
{
operation.Consumes = new List<string> {"multipart/form-data"};

@@ -364,7 +372,7 @@ private void AddFileParameter(ParameterInfo parameter, bool isCollection, Swagge
operationParameter.IsRequired = attributes.Any(a => a.GetType().Name == "RequiredAttribute");
operationParameter.Kind = SwaggerParameterKind.FormData;

if (isCollection)
if (isEnumerable)
operationParameter.CollectionFormat = SwaggerParameterCollectionFormat.Multi;

operation.Parameters.Add(operationParameter);
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NJsonSchema" version="2.21.5981.35957" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="NJsonSchema.CodeGeneration" version="2.21.5981.35959" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="NJsonSchema" version="2.22.5984.16716" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="NJsonSchema.CodeGeneration" version="2.22.5984.16718" targetFramework="portable45-net45+win8+wp8+wpa81" />
</packages>
4 changes: 2 additions & 2 deletions src/NSwag.Core/NSwag.Core.csproj
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=2.21.5981.35957, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.21.5981.35957\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Reference Include="NJsonSchema, Version=2.22.5984.16716, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.2.22.5984.16716\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
2 changes: 1 addition & 1 deletion src/NSwag.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.30.*")]
[assembly: AssemblyVersion("2.31.*")]
Loading

0 comments on commit a484a37

Please sign in to comment.