From 25bca96bd113950d67e6806669e75edc63f4f114 Mon Sep 17 00:00:00 2001 From: Kaoticz <1812311+Kaoticz@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:21:29 -0300 Subject: [PATCH] Added newline to the end of Python types --- Json2SharpLib/Emitters/Python/PythonClassEmitter.cs | 4 ---- Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs | 4 ---- Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs | 3 +++ Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs | 3 +++ Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs | 3 +++ Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs | 3 +++ Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs | 3 +++ Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs | 3 +++ 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Json2SharpLib/Emitters/Python/PythonClassEmitter.cs b/Json2SharpLib/Emitters/Python/PythonClassEmitter.cs index f8af0fa..dd1941a 100644 --- a/Json2SharpLib/Emitters/Python/PythonClassEmitter.cs +++ b/Json2SharpLib/Emitters/Python/PythonClassEmitter.cs @@ -54,10 +54,6 @@ public string Parse(string objectName, JsonElement jsonElement) if (--_stackCounter == default && _addTypeHint && stringBuilder.Contains("Optional[")) stringBuilder.Insert(0, "from typing import Optional" + Environment.NewLine + Environment.NewLine + Environment.NewLine); - // Remove the last newline - if (_stackCounter == default) - stringBuilder.Remove(stringBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length); - return stringBuilder.ToStringAndClear(); } diff --git a/Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs b/Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs index 395e6d4..b2e7cf8 100644 --- a/Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs +++ b/Json2SharpLib/Emitters/Python/PythonDataClassEmitter.cs @@ -50,10 +50,6 @@ public string Parse(string objectName, JsonElement jsonElement) stringBuilder.Insert(0, "from typing import Optional" + Environment.NewLine); } - // Remove the last newline - if (_stackCounter == default) - stringBuilder.Remove(stringBuilder.Length - Environment.NewLine.Length, Environment.NewLine.Length); - return stringBuilder.ToStringAndClear(); } diff --git a/Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs index c3ba22f..1cb9f87 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/ArrayTypes.cs @@ -46,6 +46,7 @@ class ArrayTypes: nullable_mixed_array: Optional[list[object]] thing_array: list[ThingArray] nullable_thing_array: list[Optional[NullableThingArray]] + """; public const string Output = """ @@ -91,6 +92,7 @@ def __init__( self.nullable_mixed_array = nullable_mixed_array self.thing_array = thing_array self.nullable_thing_array = nullable_thing_array + """; public const string OutputNoTypeHints = """ @@ -133,5 +135,6 @@ def __init__( self.nullable_mixed_array = nullable_mixed_array self.thing_array = thing_array self.nullable_thing_array = nullable_thing_array + """; } \ No newline at end of file diff --git a/Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs index d883faa..775d0b8 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/BoolTypes.cs @@ -17,6 +17,7 @@ from dataclasses import dataclass class BoolTypes: true_bool: bool false_bool: bool + """; public const string Output = """ @@ -27,6 +28,7 @@ def __init__( ) -> None: self.true_bool = true_bool self.false_bool = false_bool + """; public const string OutputNoTypeHints = """ @@ -37,5 +39,6 @@ def __init__( ): self.true_bool = true_bool self.false_bool = false_bool + """; } \ No newline at end of file diff --git a/Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs index e32cefe..14efeb3 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/FloatTypes.cs @@ -19,6 +19,7 @@ class FloatTypes: float_number: float double_number: float decimal_number: float + """; public const string Output = """ @@ -31,6 +32,7 @@ def __init__( self.float_number = float_number self.double_number = double_number self.decimal_number = decimal_number + """; public const string OutputNoTypeHints = """ @@ -43,5 +45,6 @@ def __init__( self.float_number = float_number self.double_number = double_number self.decimal_number = decimal_number + """; } \ No newline at end of file diff --git a/Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs index 4e2dd23..9b431bd 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/IntegerTypes.cs @@ -21,6 +21,7 @@ class IntegerTypes: uint_number: int long_number: int ulong_number: int + """; public const string Output = """ @@ -35,6 +36,7 @@ def __init__( self.uint_number = uint_number self.long_number = long_number self.ulong_number = ulong_number + """; public const string OutputNoTypeHints = """ @@ -49,5 +51,6 @@ def __init__( self.uint_number = uint_number self.long_number = long_number self.ulong_number = ulong_number + """; } \ No newline at end of file diff --git a/Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs index 74a65ac..59b93a1 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/ObjectTypes.cs @@ -31,6 +31,7 @@ class ObjectTypes: null_thing: Optional[object] empty_thing: object thing: Thing + """; public const string Output = """ @@ -57,6 +58,7 @@ def __init__( self.null_thing = null_thing self.empty_thing = empty_thing self.thing = thing + """; public const string OutputNoTypeHints = """ @@ -80,5 +82,6 @@ def __init__( self.null_thing = null_thing self.empty_thing = empty_thing self.thing = thing + """; } \ No newline at end of file diff --git a/Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs b/Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs index f4ae9fa..f848a2f 100644 --- a/Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs +++ b/Json2SharpTests/PythonTests/Models/Answers/TextTypes.cs @@ -17,6 +17,7 @@ from dataclasses import dataclass class TextTypes: text: str empty_text: str + """; public const string Output = """ @@ -27,6 +28,7 @@ def __init__( ) -> None: self.text = text self.empty_text = empty_text + """; public const string OutputNoTypeHints = """ @@ -37,5 +39,6 @@ def __init__( ): self.text = text self.empty_text = empty_text + """; } \ No newline at end of file