diff --git a/CHANGELOG.md b/CHANGELOG.md index efffabe..60d343b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't generate types for parameters with an `[FromServices]` annotation (#95) +### Changed + +- Standardize on encoding generated files as UTF-8 without BOM +- Write a final newline in the files + ## [0.13.1] - 2024-11-11 ### Added diff --git a/TypeContractor/TypeScript/ApiClientWriter.cs b/TypeContractor/TypeScript/ApiClientWriter.cs index ba8d31c..07d0e73 100644 --- a/TypeContractor/TypeScript/ApiClientWriter.cs +++ b/TypeContractor/TypeScript/ApiClientWriter.cs @@ -9,6 +9,7 @@ namespace TypeContractor.TypeScript; public class ApiClientWriter(string outputPath, string? relativeRoot) { + private static readonly Encoding _utf8WithoutBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); private static readonly Dictionary _httpMethods = new() { { EndpointMethod.GET, "get" }, @@ -126,7 +127,7 @@ public string Write(ApiClient apiClient, IEnumerable allTypes, TypeS Directory.CreateDirectory(directory); // Write file - File.WriteAllText(filePath, result); + File.WriteAllText(filePath, result.Trim() + Environment.NewLine + Environment.NewLine, _utf8WithoutBom); // Return the path we wrote to return filePath; diff --git a/TypeContractor/TypeScript/TypeScriptWriter.cs b/TypeContractor/TypeScript/TypeScriptWriter.cs index a96a574..e292788 100644 --- a/TypeContractor/TypeScript/TypeScriptWriter.cs +++ b/TypeContractor/TypeScript/TypeScriptWriter.cs @@ -7,7 +7,8 @@ namespace TypeContractor.TypeScript; #pragma warning disable CA1305 // Specify IFormatProvider public class TypeScriptWriter(string outputPath) -{ +{ + private static readonly Encoding _utf8WithoutBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); private readonly StringBuilder _builder = new(); public string Write(OutputType outputType, IEnumerable allTypes, bool buildZodSchema) @@ -29,7 +30,7 @@ public string Write(OutputType outputType, IEnumerable allTypes, boo Directory.CreateDirectory(directory); // Write file - File.WriteAllText(filePath, _builder.ToString()); + File.WriteAllText(filePath, _builder.ToString().Trim() + Environment.NewLine + Environment.NewLine, _utf8WithoutBom); // Return the path we wrote to return filePath;