Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/RicoSuter/NSwag
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Apr 12, 2019
2 parents 9d31d2a + 76e9121 commit 0174ac9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/NSwag.Commands/NSwag.Commands.csproj
Expand Up @@ -45,24 +45,24 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.6" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.1.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.4" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.6" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/NSwag.Console.x86/NSwag.Console.x86.csproj
Expand Up @@ -39,9 +39,9 @@
<PackageReference Include="NConsole" Version="3.9.6519.30868" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NSwag.Annotations\NSwag.Annotations.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions src/NSwag.Console/NSwag.Console.csproj
Expand Up @@ -37,9 +37,9 @@
<PackageReference Include="NConsole" Version="3.9.6519.30868" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NSwag.Annotations\NSwag.Annotations.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/NSwag.Core.Tests/SwaggerResponseTests.cs
Expand Up @@ -10,6 +10,8 @@ public class SwaggerResponseTests
[InlineData("text/plain", false)]
[InlineData("application/json", false)]
[InlineData("application/vnd.model+json", false)]
[InlineData("*/*", false)]
[InlineData("application/json;charset=UTF-8", false)]
public void When_response_contains_produces_detect_if_binary_response(string contentType, bool expectsBinary)
{
// Arrange
Expand Down
8 changes: 5 additions & 3 deletions src/NSwag.Core/SwaggerParameter.cs
Expand Up @@ -195,14 +195,16 @@ public override bool IsNullable(SchemaType schemaType)
/// <summary>Gets a value indicating whether this is an XML body parameter.</summary>
[JsonIgnore]
public bool IsXmlBodyParameter => Kind == SwaggerParameterKind.Body &&
(Parent as SwaggerOperation)?.ActualConsumes?.FirstOrDefault() == "application/xml" &&
((SwaggerOperation)Parent).ActualConsumes?.Contains("application/json") != true;
((SwaggerOperation)Parent).ActualConsumes?.Any() == true &&
((SwaggerOperation)Parent).ActualConsumes.Any(p => p.Contains("application/xml")) &&
((SwaggerOperation)Parent).ActualConsumes.Any(p => p.Contains("application/json")) == false;

/// <summary>Gets a value indicating whether this is an binary body parameter.</summary>
[JsonIgnore]
public bool IsBinaryBodyParameter => !IsXmlBodyParameter &&
Kind == SwaggerParameterKind.Body &&
((SwaggerOperation)Parent).ActualConsumes?.Any() == true &&
((SwaggerOperation)Parent).ActualConsumes?.Any(p => p.Contains("application/json")) == false;
((SwaggerOperation)Parent).ActualConsumes.Any(p => p.Contains("*/*")) == false && // supports json
((SwaggerOperation)Parent).ActualConsumes.Any(p => p.Contains("application/json")) == false;
}
}
14 changes: 10 additions & 4 deletions src/NSwag.Core/SwaggerResponse.cs
Expand Up @@ -120,9 +120,13 @@ public bool IsBinary(SwaggerOperation operation)
if (ActualResponse.Content.Any())
{
var contentIsBinary =
!ActualResponse.Content.ContainsKey("application/json") &&
!ActualResponse.Content.ContainsKey("text/plain") &&
ActualResponse.Content.All(c => c.Value.Schema?.ActualSchema.IsAnyType != false ||
c.Value.Schema?.ActualSchema.Type == JsonObjectType.File) && // is binary only if there is no JSON schema defined
!ActualResponse.Content.Keys.Any(p => p.Contains("*/*")) && // supports json
!ActualResponse.Content.Keys.Any(p => p.Contains("application/json")) &&
!ActualResponse.Content.Keys.Any(p => p.Contains("text/plain")) &&
!ActualResponse.Content.Keys.Any(p => p.StartsWith("application/") && p.EndsWith("+json"));

if (contentIsBinary)
{
return true;
Expand All @@ -133,8 +137,10 @@ public bool IsBinary(SwaggerOperation operation)
if (actualProduces?.Any() == true)
{
var producesIsBinary =
actualProduces?.Contains("application/json") != true &&
actualProduces?.Contains("text/plain") != true &&
(Schema?.ActualSchema.IsAnyType != false || Schema?.ActualSchema.Type == JsonObjectType.File) && // is binary only if there is no JSON schema defined
actualProduces?.Any(p => p.Contains("*/*")) != true && // supports json
actualProduces?.Any(p => p.Contains("application/json")) != true &&
actualProduces?.Any(p => p.Contains("text/plain")) != true &&
actualProduces?.Any(p => p.StartsWith("application/") && p.EndsWith("+json")) != true;

if (producesIsBinary)
Expand Down

0 comments on commit 0174ac9

Please sign in to comment.