Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ApiCodeGenerator.OpenApi.Refit.Tests/FunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
" /// <exception cref=\"Refit.ApiException\">A server side error occurred.</exception>\n" +
" [Get(\"/download\")]\n" +
" System.Threading.Tasks.Task<System.Net.Http.HttpContent> Download();\n" +
"\n" +
" }\n";

RunTest(settings, expected, "streamResponse.yaml", " \n");
}
}
}
15 changes: 15 additions & 0 deletions ApiCodeGenerator.OpenApi.Refit.Tests/swagger/streamResponse.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion ApiCodeGenerator.OpenApi.Refit/RefitCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -48,6 +53,8 @@ internal RefitCodeGenerator(OpenApiDocument openApiDocument, RefitCodeGeneratorS
/// </summary>
protected OpenApiDocument OpenApiDocument { get; }

public override string GetBinaryResponseTypeName() => _settings.BinaryResponseType;

/// <inheritdoc />
protected override IEnumerable<CodeArtifact> GenerateClientTypes(string controllerName, string controllerClassName, IEnumerable<CSharpOperationModel> operations)
{
Expand Down
5 changes: 5 additions & 0 deletions ApiCodeGenerator.OpenApi.Refit/RefitCodeGeneratorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public RefitCodeGeneratorSettings()
/// Тип используемый для двоичного содержимого.
/// </summary>
public string BinaryPartType { get; set; } = "StreamPart";

/// <summary>
/// Тип используемый для двоичного ответа.
/// </summary>
public string BinaryResponseType { get; set; } = "System.IO.Stream";
}
}
5 changes: 5 additions & 0 deletions schemas/nswag.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
Loading