diff --git a/ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs b/ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs index 67fb187..3a526f7 100644 --- a/ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs +++ b/ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs @@ -541,5 +541,31 @@ public void GenerateClientInterface_AuthHeaderParameter() //Act & Assert RunTest(settings, expected, "authSchema.json"); } + + [Test] + public void GenerateClientInterface_BinaryResponse() + { + var settings = new RefitCodeGeneratorSettings + { + BinaryResponseType = "System.Net.Http.HttpContent", + GenerateClientInterfaces = true, + GenerateOptionalParameters = false, + CSharpGeneratorSettings = + { + Namespace = "TestNS", + }, + }; + + var expected = + " public partial interface IClient\n" + + " {\n" + + " /// A server side error occurred.\n" + + " [Get(\"/download\")]\n" + + " System.Threading.Tasks.Task Download();\n" + + "\n" + + " }\n"; + + RunTest(settings, expected, "streamResponse.yaml", " \n"); + } } } diff --git a/ApiCodeGenerator.OpenApi.Refit.Tests/swagger/streamResponse.yaml b/ApiCodeGenerator.OpenApi.Refit.Tests/swagger/streamResponse.yaml new file mode 100644 index 0000000..8f81257 --- /dev/null +++ b/ApiCodeGenerator.OpenApi.Refit.Tests/swagger/streamResponse.yaml @@ -0,0 +1,15 @@ +openapi: 3.0.0 +info: + title: "" + version: "1.0.0" +paths: + /download: + get: + responses: + "200": + description: "" + content: + "application/json": + schema: + type: string + format: binary diff --git a/ApiCodeGenerator.OpenApi.Refit/RefitCodeGenerator.cs b/ApiCodeGenerator.OpenApi.Refit/RefitCodeGenerator.cs index 836abfe..c2f62b6 100644 --- a/ApiCodeGenerator.OpenApi.Refit/RefitCodeGenerator.cs +++ b/ApiCodeGenerator.OpenApi.Refit/RefitCodeGenerator.cs @@ -31,7 +31,12 @@ public RefitCodeGenerator(OpenApiDocument openApiDocument, RefitCodeGeneratorSet OpenApiDocument = openApiDocument; BaseSettings = settings; _settings = settings; - _settings.CSharpGeneratorSettings.ExcludedTypeNames = ["FileParameter", .. _settings.CSharpGeneratorSettings.ExcludedTypeNames]; + _settings.CSharpGeneratorSettings.ExcludedTypeNames = + [ + "FileParameter", + "FileResponse", + .. _settings.CSharpGeneratorSettings.ExcludedTypeNames + ]; SetUsages(); } @@ -48,6 +53,8 @@ internal RefitCodeGenerator(OpenApiDocument openApiDocument, RefitCodeGeneratorS /// protected OpenApiDocument OpenApiDocument { get; } + public override string GetBinaryResponseTypeName() => _settings.BinaryResponseType; + /// protected override IEnumerable GenerateClientTypes(string controllerName, string controllerClassName, IEnumerable operations) { diff --git a/ApiCodeGenerator.OpenApi.Refit/RefitCodeGeneratorSettings.cs b/ApiCodeGenerator.OpenApi.Refit/RefitCodeGeneratorSettings.cs index 31d1b53..9dc152b 100644 --- a/ApiCodeGenerator.OpenApi.Refit/RefitCodeGeneratorSettings.cs +++ b/ApiCodeGenerator.OpenApi.Refit/RefitCodeGeneratorSettings.cs @@ -69,5 +69,10 @@ public RefitCodeGeneratorSettings() /// Тип используемый для двоичного содержимого. /// public string BinaryPartType { get; set; } = "StreamPart"; + + /// + /// Тип используемый для двоичного ответа. + /// + public string BinaryResponseType { get; set; } = "System.IO.Stream"; } } diff --git a/schemas/nswag.json b/schemas/nswag.json index e3e2077..686c466 100644 --- a/schemas/nswag.json +++ b/schemas/nswag.json @@ -78,6 +78,11 @@ "type": "string", "description": "The .NET type used for binary data (default: StreamPart).", "default": "StreamPart" + }, + "binaryResponseType": { + "type": "string", + "description": "The .NET type used for binary response (default: System.IO.Stream).", + "default": "System.IO.Stream" } } }