From b6ba1630412dc6ddd074f254fcc87573fc876e78 Mon Sep 17 00:00:00 2001 From: Rostislav Kirillov Date: Fri, 26 Jul 2024 21:24:33 +0400 Subject: [PATCH] fix: cleanup --- ...anced.cs => BatchJsonRpcResultAdvanced.cs} | 0 ... SingleJsonSingleJsonRpcResultAdvanced.cs} | 0 .../Services/JsonSchemaBuilderExtensions.cs | 16 ++++++++++++++ .../Services/OpenRpcSchemaGenerator.cs | 15 +------------ .../ClassWithEmptyConstructor.cs | 7 +++++++ .../ClassWithoutEmptyConstructor.cs | 3 +++ .../NonPublicClass.cs | 3 +++ .../SealedClass.cs | 3 +++ .../TypeEmitterTests.cs | 11 +--------- .../Tochka.JsonRpc.TestUtils/TestData.cs | 9 +------- .../Tochka.JsonRpc.TestUtils/TestEnum.cs | 8 +++++++ .../CustomGroupNameJsonRpcController.cs | 5 ----- .../FluentValidationJsonRpcController.cs | 21 +------------------ .../Controllers/ModelValidator.cs | 12 +++++++++++ .../Controllers/StringValidator.cs | 12 +++++++++++ .../Controllers/TestObject.cs | 6 ++++++ .../Controllers/ValidationModel.cs | 3 +++ 17 files changed, 77 insertions(+), 57 deletions(-) rename src/Tochka.JsonRpc.Client/Models/BatchResult/{BatchRpcResultAdvanced.cs => BatchJsonRpcResultAdvanced.cs} (100%) rename src/Tochka.JsonRpc.Client/Models/SingleResult/{SingleRpcResultAdvanced.cs => SingleJsonSingleJsonRpcResultAdvanced.cs} (100%) create mode 100644 src/Tochka.JsonRpc.OpenRpc/Services/JsonSchemaBuilderExtensions.cs create mode 100644 src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithEmptyConstructor.cs create mode 100644 src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithoutEmptyConstructor.cs create mode 100644 src/tests/Tochka.JsonRpc.ApiExplorer.Tests/NonPublicClass.cs create mode 100644 src/tests/Tochka.JsonRpc.ApiExplorer.Tests/SealedClass.cs create mode 100644 src/tests/Tochka.JsonRpc.TestUtils/TestEnum.cs create mode 100644 src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ModelValidator.cs create mode 100644 src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/StringValidator.cs create mode 100644 src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/TestObject.cs create mode 100644 src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ValidationModel.cs diff --git a/src/Tochka.JsonRpc.Client/Models/BatchResult/BatchRpcResultAdvanced.cs b/src/Tochka.JsonRpc.Client/Models/BatchResult/BatchJsonRpcResultAdvanced.cs similarity index 100% rename from src/Tochka.JsonRpc.Client/Models/BatchResult/BatchRpcResultAdvanced.cs rename to src/Tochka.JsonRpc.Client/Models/BatchResult/BatchJsonRpcResultAdvanced.cs diff --git a/src/Tochka.JsonRpc.Client/Models/SingleResult/SingleRpcResultAdvanced.cs b/src/Tochka.JsonRpc.Client/Models/SingleResult/SingleJsonSingleJsonRpcResultAdvanced.cs similarity index 100% rename from src/Tochka.JsonRpc.Client/Models/SingleResult/SingleRpcResultAdvanced.cs rename to src/Tochka.JsonRpc.Client/Models/SingleResult/SingleJsonSingleJsonRpcResultAdvanced.cs diff --git a/src/Tochka.JsonRpc.OpenRpc/Services/JsonSchemaBuilderExtensions.cs b/src/Tochka.JsonRpc.OpenRpc/Services/JsonSchemaBuilderExtensions.cs new file mode 100644 index 0000000..a487fc6 --- /dev/null +++ b/src/Tochka.JsonRpc.OpenRpc/Services/JsonSchemaBuilderExtensions.cs @@ -0,0 +1,16 @@ +using Json.Schema; + +namespace Tochka.JsonRpc.OpenRpc.Services; + +internal static class JsonSchemaBuilderExtensions +{ + public static JsonSchemaBuilder TryAppendTitle(this JsonSchemaBuilder builder, string? propertySummary) + { + if (propertySummary is { Length: > 0 }) + { + builder.Title(propertySummary); + } + + return builder; + } +} \ No newline at end of file diff --git a/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcSchemaGenerator.cs b/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcSchemaGenerator.cs index 37030ca..c7fe947 100644 --- a/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcSchemaGenerator.cs +++ b/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcSchemaGenerator.cs @@ -206,17 +206,4 @@ private void TryAddRequiredMember(string typeName, string propertyName, JsonSeri requiredPropsForSchemas.TryAdd(typeName, requiredProperties); } -} - -internal static class JsonSchemaBuilderExtensions -{ - public static JsonSchemaBuilder TryAppendTitle(this JsonSchemaBuilder builder, string? propertySummary) - { - if (propertySummary is { Length: > 0 }) - { - builder.Title(propertySummary); - } - - return builder; - } -} +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithEmptyConstructor.cs b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithEmptyConstructor.cs new file mode 100644 index 0000000..a277636 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithEmptyConstructor.cs @@ -0,0 +1,7 @@ +namespace Tochka.JsonRpc.ApiExplorer.Tests; + +public record ClassWithEmptyConstructor +{ + public string A { get; init; } + public object B { get; init; } +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithoutEmptyConstructor.cs b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithoutEmptyConstructor.cs new file mode 100644 index 0000000..6c54b86 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/ClassWithoutEmptyConstructor.cs @@ -0,0 +1,3 @@ +namespace Tochka.JsonRpc.ApiExplorer.Tests; + +public record ClassWithoutEmptyConstructor(string A, object B); \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/NonPublicClass.cs b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/NonPublicClass.cs new file mode 100644 index 0000000..e2fe941 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/NonPublicClass.cs @@ -0,0 +1,3 @@ +namespace Tochka.JsonRpc.ApiExplorer.Tests; + +internal sealed record NonPublicClass; \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/SealedClass.cs b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/SealedClass.cs new file mode 100644 index 0000000..5a4e87d --- /dev/null +++ b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/SealedClass.cs @@ -0,0 +1,3 @@ +namespace Tochka.JsonRpc.ApiExplorer.Tests; + +public sealed record SealedClass; \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/TypeEmitterTests.cs b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/TypeEmitterTests.cs index 7ddd93b..0c1916f 100644 --- a/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/TypeEmitterTests.cs +++ b/src/tests/Tochka.JsonRpc.ApiExplorer.Tests/TypeEmitterTests.cs @@ -435,17 +435,8 @@ public void CreateResponseType_ResultTypeIsVoid_GenericArgumentIsObject() public record NestedClass; } -internal sealed record NonPublicClass; - // ReSharper disable once MemberCanBeInternal -public sealed record SealedClass; // ReSharper disable once MemberCanBeInternal -public record ClassWithEmptyConstructor -{ - public string A { get; init; } - public object B { get; init; } -} -// ReSharper disable once MemberCanBeInternal -public record ClassWithoutEmptyConstructor(string A, object B); +// ReSharper disable once MemberCanBeInternal \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.TestUtils/TestData.cs b/src/tests/Tochka.JsonRpc.TestUtils/TestData.cs index 1cb0b8a..64faf7d 100644 --- a/src/tests/Tochka.JsonRpc.TestUtils/TestData.cs +++ b/src/tests/Tochka.JsonRpc.TestUtils/TestData.cs @@ -305,11 +305,4 @@ public record TestData(bool BoolField, string StringField, int IntField, double """; #endregion -} - -public enum TestEnum -{ - One, - Two, - ThreeFour -} +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.TestUtils/TestEnum.cs b/src/tests/Tochka.JsonRpc.TestUtils/TestEnum.cs new file mode 100644 index 0000000..f49ed5a --- /dev/null +++ b/src/tests/Tochka.JsonRpc.TestUtils/TestEnum.cs @@ -0,0 +1,8 @@ +namespace Tochka.JsonRpc.TestUtils; + +public enum TestEnum +{ + One, + Two, + ThreeFour +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/CustomGroupNameJsonRpcController.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/CustomGroupNameJsonRpcController.cs index fe42eb1..22127b5 100644 --- a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/CustomGroupNameJsonRpcController.cs +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/CustomGroupNameJsonRpcController.cs @@ -3,11 +3,6 @@ namespace Tochka.JsonRpc.Tests.WebApplication.Controllers; -public class TestObject -{ - public TimeSpan Ts { get; set; } = DateTime.Now.TimeOfDay; -} - [ApiExplorerSettings(GroupName = "custom")] public class CustomGroupNameJsonRpcController : JsonRpcControllerBase { diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/FluentValidationJsonRpcController.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/FluentValidationJsonRpcController.cs index e3bbc1d..63e5e6f 100644 --- a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/FluentValidationJsonRpcController.cs +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/FluentValidationJsonRpcController.cs @@ -1,5 +1,4 @@ using FluentValidation; -using JetBrains.Annotations; using Microsoft.AspNetCore.Mvc; using Tochka.JsonRpc.Server; using Tochka.JsonRpc.Server.Attributes; @@ -27,22 +26,4 @@ public async Task Validate([FromParams(BindingStyle.Object)] Vali ? Ok(errorFactory.InternalError(validationResult.ToDictionary())) : Ok(model.Str); } -} - -public record ValidationModel(string? Str); - -[UsedImplicitly] -public class ModelValidator : AbstractValidator -{ - public ModelValidator() => RuleFor(static m => m.Str).NotEmpty().WithMessage(Error); - - internal const string Error = "Str is empty"; -} - -[UsedImplicitly] -public class StringValidator : AbstractValidator -{ - public StringValidator() => RuleFor(static x => x).MinimumLength(3).WithMessage(Error); - - internal const string Error = "Str is too short"; -} +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ModelValidator.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ModelValidator.cs new file mode 100644 index 0000000..b3d5065 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ModelValidator.cs @@ -0,0 +1,12 @@ +using FluentValidation; +using JetBrains.Annotations; + +namespace Tochka.JsonRpc.Tests.WebApplication.Controllers; + +[UsedImplicitly] +public class ModelValidator : AbstractValidator +{ + public ModelValidator() => RuleFor(static m => m.Str).NotEmpty().WithMessage(Error); + + internal const string Error = "Str is empty"; +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/StringValidator.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/StringValidator.cs new file mode 100644 index 0000000..5215048 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/StringValidator.cs @@ -0,0 +1,12 @@ +using FluentValidation; +using JetBrains.Annotations; + +namespace Tochka.JsonRpc.Tests.WebApplication.Controllers; + +[UsedImplicitly] +public class StringValidator : AbstractValidator +{ + public StringValidator() => RuleFor(static x => x).MinimumLength(3).WithMessage(Error); + + internal const string Error = "Str is too short"; +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/TestObject.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/TestObject.cs new file mode 100644 index 0000000..7ec1396 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/TestObject.cs @@ -0,0 +1,6 @@ +namespace Tochka.JsonRpc.Tests.WebApplication.Controllers; + +public class TestObject +{ + public TimeSpan Ts { get; set; } = DateTime.Now.TimeOfDay; +} \ No newline at end of file diff --git a/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ValidationModel.cs b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ValidationModel.cs new file mode 100644 index 0000000..12ff1a8 --- /dev/null +++ b/src/tests/Tochka.JsonRpc.Tests.WebApplication/Controllers/ValidationModel.cs @@ -0,0 +1,3 @@ +namespace Tochka.JsonRpc.Tests.WebApplication.Controllers; + +public record ValidationModel(string? Str); \ No newline at end of file