Skip to content

Commit

Permalink
Improve missing FileResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Sep 14, 2020
1 parent e3c747b commit c069345
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/NSwag.Core/OpenApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ public bool IsBinary(OpenApiOperation operation)
{
if (ActualResponse.Content.Any())
{
if (ActualResponse.Content.All(c => c.Value.Schema?.ActualSchema.IsBinary == true))
{
return true;
}

var contentIsBinary =
ActualResponse.Content.All(c => c.Value.Schema?.ActualSchema.IsAnyType != false ||
c.Value.Schema?.ActualSchema.IsBinary != false) && // is binary only if there is no JSON schema defined
c.Value.Schema?.ActualSchema.IsBinary != false) &&
!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"));
Expand All @@ -137,6 +142,11 @@ public bool IsBinary(OpenApiOperation operation)
var actualProduces = (ActualResponse.Parent as OpenApiOperation)?.ActualProduces;
if (actualProduces?.Any() == true)
{
if (Schema?.ActualSchema.IsBinary == true)
{
return true;
}

var producesIsBinary =
(Schema?.ActualSchema.IsAnyType != false ||
Schema?.ActualSchema.IsBinary != false) && // is binary only if there is no JSON schema defined
Expand Down

0 comments on commit c069345

Please sign in to comment.