From 44efe3ddd8dc498779fc35046b26965116ebb93c Mon Sep 17 00:00:00 2001 From: Teimuraz Nikolaishvili Date: Mon, 22 Jan 2024 22:52:56 +0400 Subject: [PATCH] Fixed swagger type trailling coma for linux and windows systems --- .../Helpers/MethodGeneratorHelper.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs index 8f572d6..6bb03d6 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs @@ -1,8 +1,9 @@ -using AltaSoft.DomainPrimitives.Generator.Extensions; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AltaSoft.DomainPrimitives.Generator.Extensions; using AltaSoft.DomainPrimitives.Generator.Models; using Microsoft.CodeAnalysis; -using System.Collections.Generic; -using System.Linq; namespace AltaSoft.DomainPrimitives.Generator.Helpers; @@ -11,6 +12,17 @@ namespace AltaSoft.DomainPrimitives.Generator.Helpers; /// internal static class MethodGeneratorHelper { + /// + /// Represents the length of a new line character sequence. + /// + internal static readonly int s_newLineLength = GetNewLineLength(); + + /// + /// Retrieves the length of a new line character sequence. + /// + /// The length of a new line character sequence. + private static int GetNewLineLength() => new StringBuilder().AppendLine().Length; + /// /// Adds Swagger mappings for specific custom types to ensure proper OpenAPI documentation generation. /// @@ -111,7 +123,7 @@ void AddMapping(bool isNullable) } } - sb.Length -= 3; + sb.Length -= s_newLineLength + 1; sb.NewLine(); sb.AppendLine("});"); } @@ -746,4 +758,4 @@ public static void GenerateIXmlSerializableMethods(GeneratorData data, SourceCod sb.AppendLine($"public void WriteXml(XmlWriter writer) => writer.WriteString({data.FieldName}.ToString(\"{data.SerializationFormat}\"));"); sb.NewLine(); } -} \ No newline at end of file +}