From c36232aa4eddf250a061780444797e7ea6fab470 Mon Sep 17 00:00:00 2001 From: Ricky Kaare Engelharth Date: Fri, 9 Aug 2024 07:49:24 +0200 Subject: [PATCH] Fix indention of generated code --- .../ClientEndpointGenerator.cs | 108 +++++++++++------- .../Descriptors/EndpointMethodDescriptor.cs | 10 +- .../EmbeddedSource/EmbeddedSourceGenerator.cs | 9 +- ...Token_Parameter#TestEndpoint.g.verified.cs | 52 ++++----- ...ame_From_NameOf#TestEndpoint.g.verified.cs | 12 +- ...tions_Parameter#TestEndpoint.g.verified.cs | 56 ++++----- ..._DeleteEndpoint#TestEndpoint.g.verified.cs | 52 ++++----- ...ate_GetEndpoint#TestEndpoint.g.verified.cs | 52 ++++----- ...edPathParameter#TestEndpoint.g.verified.cs | 60 +++++----- ...dQueryParameter#TestEndpoint.g.verified.cs | 60 +++++----- ...nation_Endpoint#TestEndpoint.g.verified.cs | 12 +- ...e_PathParameter#TestEndpoint.g.verified.cs | 60 +++++----- ...ate_PutEndpoint#TestEndpoint.g.verified.cs | 56 ++++----- ...Generate_Usings#TestEndpoint.g.verified.cs | 56 ++++----- 14 files changed, 347 insertions(+), 308 deletions(-) diff --git a/src/Cabazure.Client/ClientEndpointGenerator.cs b/src/Cabazure.Client/ClientEndpointGenerator.cs index 99c1ca0..b0d4463 100644 --- a/src/Cabazure.Client/ClientEndpointGenerator.cs +++ b/src/Cabazure.Client/ClientEndpointGenerator.cs @@ -56,25 +56,27 @@ private static void ProcessEndpoint( source.AppendLine(); } + var indention = ""; if (endpoint.Namespace != null) { source.AppendLine($"namespace {endpoint.Namespace}"); source.AppendLine($"{{"); + indention = " "; } source.AppendLine($$""" - internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; - - public {{endpoint.ClassName}}( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + {{indention}}internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} + {{indention}}{ + {{indention}} private readonly IHttpClientFactory factory; + {{indention}} private readonly IMessageRequestFactory requestFactory; + {{indention}} + {{indention}} public {{endpoint.ClassName}}( + {{indention}} IHttpClientFactory factory, + {{indention}} IMessageRequestFactory requestFactory) + {{indention}} { + {{indention}} this.factory = factory; + {{indention}} this.requestFactory = requestFactory; + {{indention}} } """); foreach (var method in endpoint.Methods) @@ -82,10 +84,11 @@ internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} GenerateEndpointMethod( source, method, - endpoint.ClientName); + endpoint.ClientName, + indention); } - source.AppendLine(" }"); + source.AppendLine($"{indention}}}"); if (endpoint.Namespace != null) { source.AppendLine($"}}"); @@ -100,35 +103,54 @@ internal partial class {{endpoint.ClassName}} : {{endpoint.InterfaceName}} private static void GenerateEndpointMethod( StringBuilder source, EndpointMethodDescriptor method, - string clientName) + string clientName, + string indention) { var clientOptions = new StringBuilder(); var requestOptions = new StringBuilder(); foreach (var p in method.PathParameters) { - requestOptions.Append($"\n .WithPathParameter(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($""" + + {indention} .WithPathParameter("{p.Name}", {GetParameterValue(p)}) + """); } foreach (var p in method.QueryParameters) { - requestOptions.Append($"\n .WithQueryParameter(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($""" + + {indention} .WithQueryParameter("{p.Name}", {GetParameterValue(p)}) + """); } foreach (var p in method.HeaderParameters) { - requestOptions.Append($"\n .WithHeader(\"{p.Name}\", {GetParameterValue(p)})"); + requestOptions.Append($""" + + {indention} .WithHeader("{p.Name}", {GetParameterValue(p)}) + """); } if (method.BodyParameter is { } b) { - requestOptions.Append($"\n .WithBody({b})"); + requestOptions.Append($""" + + {indention} .WithBody({b}) + """); } if (method.OptionsParameter is { } o) { - clientOptions.Append($"\n .WithRequestOptions({o})"); - requestOptions.Append($"\n .WithRequestOptions({o})"); + clientOptions.Append($""" + + {indention} .WithRequestOptions({o}) + """); + requestOptions.Append($""" + + {indention} .WithRequestOptions({o}) + """); } var cancellationToken = method.CancellationTokenParameter @@ -142,27 +164,35 @@ private static void GenerateEndpointMethod( var resultConversion = method.ResponseType == null ? null - : $"\n response => new {method.ResponseType}(response),\n "; + : $""" - source.AppendLine($$""" - - {{method.Signature}} - { - var client = factory.CreateClient("{{clientName}}"); - - using var requestMessage = requestFactory - .FromTemplate("{{clientName}}", "{{method.RouteTemplate}}"){{requestOptions}} - .Build(HttpMethod.{{method.HttpMethod}}); + {indention} response => new {method.ResponseType}(response), + {indention} + """; - using var response = await client{{clientOptions}} - .SendAsync(requestMessage, {{cancellationToken}}); + var parameters = string.Join( + ",", + method.Parameters.Select(p => $"\n{indention} {p}")); - return await requestFactory - .FromResponse("{{clientName}}", response) - .AddSuccessResponse{{resultGeneric}}(HttpStatusCode.OK) - .GetAsync({{resultConversion}}{{cancellationToken}}); - } - """); + source.AppendLine(); + source.AppendLine($$""" + {{indention}} public async {{method.ReturnType}} {{method.Name}}({{parameters}}) + {{indention}} { + {{indention}} var client = factory.CreateClient("{{clientName}}"); + {{indention}} + {{indention}} using var requestMessage = requestFactory + {{indention}} .FromTemplate("{{clientName}}", "{{method.RouteTemplate}}"){{requestOptions}} + {{indention}} .Build(HttpMethod.{{method.HttpMethod}}); + {{indention}} + {{indention}} using var response = await client{{clientOptions}} + {{indention}} .SendAsync(requestMessage, {{cancellationToken}}); + {{indention}} + {{indention}} return await requestFactory + {{indention}} .FromResponse("{{clientName}}", response) + {{indention}} .AddSuccessResponse{{resultGeneric}}(HttpStatusCode.OK) + {{indention}} .GetAsync({{resultConversion}}{{cancellationToken}}); + {{indention}} } + """); } private static string GetParameterValue(EndpointParameter parameter) diff --git a/src/Cabazure.Client/Descriptors/EndpointMethodDescriptor.cs b/src/Cabazure.Client/Descriptors/EndpointMethodDescriptor.cs index 9b649d5..fd3b6bb 100644 --- a/src/Cabazure.Client/Descriptors/EndpointMethodDescriptor.cs +++ b/src/Cabazure.Client/Descriptors/EndpointMethodDescriptor.cs @@ -9,9 +9,10 @@ namespace Cabazure.Client.SourceGenerator.Descriptors; public record EndpointMethodDescriptor( string Name, - string Signature, - string? ResultType, + string[] Parameters, + string ReturnType, string? ResponseType, + string? ResultType, string HttpMethod, string RouteTemplate, string? OptionsParameter, @@ -164,9 +165,10 @@ public record EndpointMethodDescriptor( return new EndpointMethodDescriptor( method.Identifier.ValueText, - $"public async {method.ReturnType} {method.Identifier}{method.ParameterList}", - returnType, + method.ParameterList.Parameters.Select(p => $"{p.Type} {p.Identifier}").ToArray(), + method.ReturnType.ToString(), responseType, + returnType, httpMethod, routeTemplate, optionsParameter, diff --git a/src/Cabazure.Client/EmbeddedSource/EmbeddedSourceGenerator.cs b/src/Cabazure.Client/EmbeddedSource/EmbeddedSourceGenerator.cs index d7e0711..7d7826f 100644 --- a/src/Cabazure.Client/EmbeddedSource/EmbeddedSourceGenerator.cs +++ b/src/Cabazure.Client/EmbeddedSource/EmbeddedSourceGenerator.cs @@ -22,7 +22,14 @@ private static void AddEmbeddedSources(GeneratorPostInitializationContext contex { var hintName = sourceFile.Substring(prefix.Length); var stream = assembly.GetManifestResourceStream(sourceFile); - context.AddSource(hintName, SourceText.From(stream, canBeEmbedded: true)); + context.AddSource( + hintName, + SourceText.From( + stream, + encoding: System.Text.Encoding.UTF8, + checksumAlgorithm: SourceHashAlgorithm.Sha1, + throwIfBinaryDetected: true, + canBeEmbedded: true)); } } } diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs index 5f1b1cc..2e20f2c 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_CancellationToken_Parameter#TestEndpoint.g.verified.cs @@ -6,37 +6,37 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( + public async Task> ExecuteAsync( CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .Build(HttpMethod.Get); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs index 3edbc2f..18b5b21 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientName_From_NameOf#TestEndpoint.g.verified.cs @@ -12,7 +12,7 @@ internal partial class TestEndpoint : ITestEndpoint { private readonly IHttpClientFactory factory; private readonly IMessageRequestFactory requestFactory; - + public TestEndpoint( IHttpClientFactory factory, IMessageRequestFactory requestFactory) @@ -22,20 +22,20 @@ public TestEndpoint( } public async Task> ExecuteAsync( - ClientRequestOptions options, - CancellationToken cancellationToken) + ClientRequestOptions options, + CancellationToken cancellationToken) { var client = factory.CreateClient("String"); - + using var requestMessage = requestFactory .FromTemplate("String", "/routes") .WithRequestOptions(options) .Build(HttpMethod.Get); - + using var response = await client .WithRequestOptions(options) .SendAsync(requestMessage, cancellationToken); - + return await requestFactory .FromResponse("String", response) .AddSuccessResponse(HttpStatusCode.OK) diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs index d705b79..d4b6327 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_ClientRequestOptions_Parameter#TestEndpoint.g.verified.cs @@ -6,39 +6,39 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( + public async Task> ExecuteAsync( ClientRequestOptions options) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, CancellationToken.None); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, CancellationToken.None); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - CancellationToken.None); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + CancellationToken.None); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs index a9e97c1..91601a9 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_DeleteEndpoint#TestEndpoint.g.verified.cs @@ -6,37 +6,37 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task ExecuteAsync( - [Path] string id, + public async Task ExecuteAsync( + string id, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .Build(HttpMethod.Delete); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .Build(HttpMethod.Delete); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync(cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync(cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs index ef315fe..e8386c6 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_GetEndpoint#TestEndpoint.g.verified.cs @@ -6,36 +6,36 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync() - { - var client = factory.CreateClient("ClientName"); + public async Task> ExecuteAsync() + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .Build(HttpMethod.Get); - using var response = await client - .SendAsync(requestMessage, CancellationToken.None); + using var response = await client + .SendAsync(requestMessage, CancellationToken.None); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - CancellationToken.None); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + CancellationToken.None); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs index 5d52b8c..08b8c48 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedPathParameter#TestEndpoint.g.verified.cs @@ -6,42 +6,42 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( - [Path("id")] string itemId, + public async Task> ExecuteAsync( + string itemId, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", itemId) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", itemId) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs index d9301d2..c51efe4 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_NamedQueryParameter#TestEndpoint.g.verified.cs @@ -6,42 +6,42 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( - [Query("s")] string searchText, + public async Task> ExecuteAsync( + string searchText, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items") - .WithQueryParameter("s", searchText) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items") + .WithQueryParameter("s", searchText) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs index 5c0236a..bf10b80 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Pagination_Endpoint#TestEndpoint.g.verified.cs @@ -12,7 +12,7 @@ internal partial class TestEndpoint : ITestEndpoint { private readonly IHttpClientFactory factory; private readonly IMessageRequestFactory requestFactory; - + public TestEndpoint( IHttpClientFactory factory, IMessageRequestFactory requestFactory) @@ -22,20 +22,20 @@ public TestEndpoint( } public async Task> ExecuteAsync( - PagedRequestOptions options, - CancellationToken cancellationToken) + PagedRequestOptions options, + CancellationToken cancellationToken) { var client = factory.CreateClient("ClientName"); - + using var requestMessage = requestFactory .FromTemplate("ClientName", "/routes") .WithRequestOptions(options) .Build(HttpMethod.Get); - + using var response = await client .WithRequestOptions(options) .SendAsync(requestMessage, cancellationToken); - + return await requestFactory .FromResponse("ClientName", response) .AddSuccessResponse(HttpStatusCode.OK) diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs index 4eb4463..03ef3b5 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PathParameter#TestEndpoint.g.verified.cs @@ -6,42 +6,42 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( - [Path] string id, + public async Task> ExecuteAsync( + string id, ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs index f47138f..6fa6ca3 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_PutEndpoint#TestEndpoint.g.verified.cs @@ -6,39 +6,39 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task ExecuteAsync( - [Path("id")] string id, - [Body] string body, + public async Task ExecuteAsync( + string id, + string body, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/items/{id}") - .WithPathParameter("id", id) - .WithBody(body) - .Build(HttpMethod.Put); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/items/{id}") + .WithPathParameter("id", id) + .WithBody(body) + .Build(HttpMethod.Put); - using var response = await client - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync(cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync(cancellationToken); } +} #nullable disable diff --git a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs index b25cd39..a6d70a8 100644 --- a/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs +++ b/test/Cabazure.Client.Tests/ClientEndpointGeneratorTests.CanGenerate_Usings#TestEndpoint.g.verified.cs @@ -7,40 +7,40 @@ using Cabazure.Client; using Cabazure.Client.Builder; - internal partial class TestEndpoint : ITestEndpoint - { - private readonly IHttpClientFactory factory; - private readonly IMessageRequestFactory requestFactory; +internal partial class TestEndpoint : ITestEndpoint +{ + private readonly IHttpClientFactory factory; + private readonly IMessageRequestFactory requestFactory; - public TestEndpoint( - IHttpClientFactory factory, - IMessageRequestFactory requestFactory) - { - this.factory = factory; - this.requestFactory = requestFactory; - } + public TestEndpoint( + IHttpClientFactory factory, + IMessageRequestFactory requestFactory) + { + this.factory = factory; + this.requestFactory = requestFactory; + } - public async Task> ExecuteAsync( + public async Task> ExecuteAsync( ClientRequestOptions options, CancellationToken cancellationToken) - { - var client = factory.CreateClient("ClientName"); + { + var client = factory.CreateClient("ClientName"); - using var requestMessage = requestFactory - .FromTemplate("ClientName", "/routes") - .WithRequestOptions(options) - .Build(HttpMethod.Get); + using var requestMessage = requestFactory + .FromTemplate("ClientName", "/routes") + .WithRequestOptions(options) + .Build(HttpMethod.Get); - using var response = await client - .WithRequestOptions(options) - .SendAsync(requestMessage, cancellationToken); + using var response = await client + .WithRequestOptions(options) + .SendAsync(requestMessage, cancellationToken); - return await requestFactory - .FromResponse("ClientName", response) - .AddSuccessResponse(HttpStatusCode.OK) - .GetAsync( - response => new EndpointResponse(response), - cancellationToken); - } + return await requestFactory + .FromResponse("ClientName", response) + .AddSuccessResponse(HttpStatusCode.OK) + .GetAsync( + response => new EndpointResponse(response), + cancellationToken); } +} #nullable disable