Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): Standardize on encoding and final newlines #97

Merged
merged 1 commit into from
Nov 16, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion TypeContractor/TypeScript/ApiClientWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class ApiClientWriter(string outputPath, string? relativeRoot)
{
private static readonly Encoding _utf8WithoutBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
private static readonly Dictionary<EndpointMethod, string> _httpMethods = new()
{
{ EndpointMethod.GET, "get" },
Expand All @@ -18,7 +19,7 @@
{ EndpointMethod.DELETE, "delete" },
};

public string Write(ApiClient apiClient, IEnumerable<OutputType> allTypes, TypeScriptConverter converter, bool buildZodSchema, HandlebarsTemplate<object, ApiClientTemplateDto> template)

Check warning on line 22 in TypeContractor/TypeScript/ApiClientWriter.cs

View workflow job for this annotation

GitHub Actions / build

Argument type 'HandlebarsTemplate<object, ApiClientTemplateDto>' is not CLS-compliant

Check warning on line 22 in TypeContractor/TypeScript/ApiClientWriter.cs

View workflow job for this annotation

GitHub Actions / build

Argument type 'HandlebarsTemplate<object, ApiClientTemplateDto>' is not CLS-compliant

Check warning on line 22 in TypeContractor/TypeScript/ApiClientWriter.cs

View workflow job for this annotation

GitHub Actions / build

Argument type 'HandlebarsTemplate<object, ApiClientTemplateDto>' is not CLS-compliant

Check warning on line 22 in TypeContractor/TypeScript/ApiClientWriter.cs

View workflow job for this annotation

GitHub Actions / build

Argument type 'HandlebarsTemplate<object, ApiClientTemplateDto>' is not CLS-compliant
{
var _builder = new StringBuilder();
ArgumentNullException.ThrowIfNull(apiClient);
Expand Down Expand Up @@ -126,7 +127,7 @@
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;
Expand Down
5 changes: 3 additions & 2 deletions TypeContractor/TypeScript/TypeScriptWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutputType> allTypes, bool buildZodSchema)
Expand All @@ -29,7 +30,7 @@ public string Write(OutputType outputType, IEnumerable<OutputType> 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;
Expand Down
Loading