From afdfbd1126582c6724d1c6e8d886d852b7267647 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sat, 7 Sep 2024 17:50:07 +0400 Subject: [PATCH] fix: Fixed init command issue with binary files. --- .../Commands/InitializeCommand.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libs/OpenApiGenerator.Cli/Commands/InitializeCommand.cs b/src/libs/OpenApiGenerator.Cli/Commands/InitializeCommand.cs index 9d2942ffb2..61f3378402 100644 --- a/src/libs/OpenApiGenerator.Cli/Commands/InitializeCommand.cs +++ b/src/libs/OpenApiGenerator.Cli/Commands/InitializeCommand.cs @@ -117,9 +117,19 @@ private static async Task HandleAsync( Directory.CreateDirectory(directory); } - await File.WriteAllTextAsync( - path, - Replace(resource.AsString())).ConfigureAwait(false); + var extension = Path.GetExtension(path); + if (extension.ToUpperInvariant() is ".PNG" or ".JPG" or ".JPEG" or ".GIF" or ".SVG" or ".SNK") + { + await File.WriteAllBytesAsync( + path, + resource.AsBytes()).ConfigureAwait(false); + } + else + { + await File.WriteAllTextAsync( + path, + Replace(resource.AsString())).ConfigureAwait(false); + } } Console.WriteLine("Done.");