From c0693456186e3c39e8c9fb590aa33842b76e299d Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 14 Sep 2020 13:53:15 +0200 Subject: [PATCH] Improve missing FileResponse --- src/NSwag.Core/OpenApiResponse.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/NSwag.Core/OpenApiResponse.cs b/src/NSwag.Core/OpenApiResponse.cs index 98c8aa8484..0ee195b259 100644 --- a/src/NSwag.Core/OpenApiResponse.cs +++ b/src/NSwag.Core/OpenApiResponse.cs @@ -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")); @@ -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