From a8fcd127666e6d28e04f02e0a20c7b2d0c0be4ca Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:47:04 +0100 Subject: [PATCH 01/32] feat: fix form url encoded strings #1593 (#1752) --- Refit.Tests/RequestBuilder.cs | 23 +++++++++++++++++++++++ Refit/FormValueMultimap.cs | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Refit.Tests/RequestBuilder.cs b/Refit.Tests/RequestBuilder.cs index 5b8f300da..f0477c5aa 100644 --- a/Refit.Tests/RequestBuilder.cs +++ b/Refit.Tests/RequestBuilder.cs @@ -3241,6 +3241,29 @@ public void BodyContentGetsUrlEncoded() Assert.Equal("Foo=Something&Bar=100&Baz=", output.SendContent); } + [Fact] + public void BodyContentGetsUrlEncodedWithCollectionFormat() + { + var settings = new RefitSettings() { CollectionFormat = CollectionFormat.Csv }; + var fixture = new RequestBuilderImplementation(settings); + var factory = fixture.RunRequest("PostSomeUrlEncodedStuff"); + var output = factory( + new object[] + { + 6, + new + { + Foo = "Something", + Bar = 100, + FooBar = new [] {5,7}, + Baz = "" // explicitly use blank to preserve value that would be stripped if null + } + } + ); + + Assert.Equal("Foo=Something&Bar=100&FooBar=5%2C7&Baz=", output.SendContent); + } + [Fact] public void FormFieldGetsAliased() { diff --git a/Refit/FormValueMultimap.cs b/Refit/FormValueMultimap.cs index f82114006..291fb3567 100644 --- a/Refit/FormValueMultimap.cs +++ b/Refit/FormValueMultimap.cs @@ -65,7 +65,8 @@ public FormValueMultimap(object source, RefitSettings settings) // see if there's a query attribute var attrib = property.GetCustomAttribute(true); - if (value is not IEnumerable enumerable) + // add strings/non enumerable properties + if (value is not IEnumerable enumerable || value is string) { Add( fieldName, From 34153046c9fe750fc615d94c95ac1281b0012278 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:15:56 +0100 Subject: [PATCH 02/32] chore(deps): update dependency refit to v7.1.1 (#1754) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- samples/Meow.Common/Meow.Common.csproj | 2 +- .../LibraryWithSDKandRefitService.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/Meow.Common/Meow.Common.csproj b/samples/Meow.Common/Meow.Common.csproj index a105eb8b2..13eee1815 100644 --- a/samples/Meow.Common/Meow.Common.csproj +++ b/samples/Meow.Common/Meow.Common.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj b/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj index 850b2c252..3687515c1 100644 --- a/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj +++ b/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj @@ -5,7 +5,7 @@ - + From 6985161557a8dcbc4027cb55fb4e90f1ed69dbd7 Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:20:13 +0100 Subject: [PATCH 03/32] feat: extract logic and small cleanups (#1755) --- Refit/RequestBuilderImplementation.cs | 137 ++++++++++++++------------ 1 file changed, 72 insertions(+), 65 deletions(-) diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 10df8d5ac..59ef3affa 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -649,67 +649,12 @@ bool paramsContainsCancellationToken parameterInfo = parameterMapValue; if (parameterInfo.IsObjectPropertyParameter) { - foreach (var propertyInfo in parameterInfo.ParameterProperties) - { - var propertyObject = propertyInfo.PropertyInfo.GetValue(param); - urlTarget = Regex.Replace( - urlTarget, - "{" + propertyInfo.Name + "}", - Uri.EscapeDataString( - settings.UrlParameterFormatter.Format( - propertyObject, - propertyInfo.PropertyInfo, - propertyInfo.PropertyInfo.PropertyType - ) ?? string.Empty - ), - RegexOptions.IgnoreCase | RegexOptions.CultureInvariant - ); - } + urlTarget = AddObjectParametersToUrl(parameterInfo, param, urlTarget); //don't continue here as we want it to fall through so any parameters on this object not bound here get passed as query parameters } else { - string pattern; - string replacement; - if (parameterMapValue.Type == ParameterType.RoundTripping) - { - pattern = $@"{{\*\*{parameterMapValue.Name}}}"; - var paramValue = (string)param; - replacement = string.Join( - "/", - paramValue - .Split('/') - .Select( - s => - Uri.EscapeDataString( - settings.UrlParameterFormatter.Format( - s, - restMethod.ParameterInfoArray[i], - restMethod.ParameterInfoArray[i].ParameterType - ) ?? string.Empty - ) - ) - ); - } - else - { - pattern = "{" + parameterMapValue.Name + "}"; - replacement = Uri.EscapeDataString( - settings.UrlParameterFormatter.Format( - param, - restMethod.ParameterInfoArray[i], - restMethod.ParameterInfoArray[i].ParameterType - ) ?? string.Empty - ); - } - - urlTarget = Regex.Replace( - urlTarget, - pattern, - replacement, - RegexOptions.IgnoreCase | RegexOptions.CultureInvariant - ); - + urlTarget = AddValueParameterToUrl(restMethod, parameterMapValue, param, i, urlTarget); isParameterMappedToRequest = true; } } @@ -721,7 +666,6 @@ bool paramsContainsCancellationToken ) { AddBodyToRequest(restMethod, param, ret); - isParameterMappedToRequest = true; } @@ -784,7 +728,6 @@ bool paramsContainsCancellationToken ) { AddQueryParameters(restMethod, queryAttribute, param, queryParamsToAdd, i, parameterInfo); - continue; } @@ -818,6 +761,74 @@ bool paramsContainsCancellationToken }; } + string AddObjectParametersToUrl(RestMethodParameterInfo parameterInfo, object param, string urlTarget) + { + foreach (var propertyInfo in parameterInfo.ParameterProperties) + { + var propertyObject = propertyInfo.PropertyInfo.GetValue(param); + urlTarget = Regex.Replace( + urlTarget, + "{" + propertyInfo.Name + "}", + Uri.EscapeDataString( + settings.UrlParameterFormatter.Format( + propertyObject, + propertyInfo.PropertyInfo, + propertyInfo.PropertyInfo.PropertyType + ) ?? string.Empty + ), + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant + ); + } + + return urlTarget; + } + + string AddValueParameterToUrl(RestMethodInfoInternal restMethod, RestMethodParameterInfo parameterMapValue, + object param, int i, string urlTarget) + { + string pattern; + string replacement; + if (parameterMapValue.Type == ParameterType.RoundTripping) + { + pattern = $@"{{\*\*{parameterMapValue.Name}}}"; + var paramValue = (string)param; + replacement = string.Join( + "/", + paramValue + .Split('/') + .Select( + s => + Uri.EscapeDataString( + settings.UrlParameterFormatter.Format( + s, + restMethod.ParameterInfoArray[i], + restMethod.ParameterInfoArray[i].ParameterType + ) ?? string.Empty + ) + ) + ); + } + else + { + pattern = "{" + parameterMapValue.Name + "}"; + replacement = Uri.EscapeDataString( + settings.UrlParameterFormatter.Format( + param, + restMethod.ParameterInfoArray[i], + restMethod.ParameterInfoArray[i].ParameterType + ) ?? string.Empty + ); + } + + urlTarget = Regex.Replace( + urlTarget, + pattern, + replacement, + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant + ); + return urlTarget; + } + void AddBodyToRequest(RestMethodInfoInternal restMethod, object param, HttpRequestMessage ret) { if (param is HttpContent httpContentParam) @@ -940,11 +951,7 @@ void AddMultiPart(RestMethodInfoInternal restMethod, int i, object param, } // Check to see if it's an IEnumerable - var itemValue = param; - var enumerable = itemValue as IEnumerable; - var typeIsCollection = enumerable != null; - - if (typeIsCollection) + if (param is IEnumerable enumerable) { foreach (var item in enumerable!) { @@ -953,7 +960,7 @@ void AddMultiPart(RestMethodInfoInternal restMethod, int i, object param, } else { - AddMultipartItem(multiPartContent!, itemName, parameterName, itemValue); + AddMultipartItem(multiPartContent!, itemName, parameterName, param); } } From 93a3c79167e2fefe56bc4a2f14f55100e8ebf630 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:24:46 +0100 Subject: [PATCH 04/32] chore(deps): update dependency system.text.json to v8.0.4 [security] (#1757) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit/Refit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit/Refit.csproj b/Refit/Refit.csproj index 595d96a32..1c0bf8d9b 100644 --- a/Refit/Refit.csproj +++ b/Refit/Refit.csproj @@ -13,7 +13,7 @@ - + From 56378d6b41a8e65a25c83e81af87ac1a70a673d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 21:30:25 +0000 Subject: [PATCH 05/32] chore(deps): update xunit-dotnet monorepo (#1760) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.Tests/Refit.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Refit.Tests/Refit.Tests.csproj b/Refit.Tests/Refit.Tests.csproj index 5f11a9a1c..1761bed83 100644 --- a/Refit.Tests/Refit.Tests.csproj +++ b/Refit.Tests/Refit.Tests.csproj @@ -21,8 +21,8 @@ - - + + From 02750252ec7dca809930489661efd66dd3ea5ae3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 21:36:08 +0000 Subject: [PATCH 06/32] chore(deps): update dependency refit to v7.1.2 (#1758) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- samples/Meow.Common/Meow.Common.csproj | 2 +- .../LibraryWithSDKandRefitService.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/Meow.Common/Meow.Common.csproj b/samples/Meow.Common/Meow.Common.csproj index 13eee1815..bb3c4c126 100644 --- a/samples/Meow.Common/Meow.Common.csproj +++ b/samples/Meow.Common/Meow.Common.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj b/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj index 3687515c1..16e407c5b 100644 --- a/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj +++ b/samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj @@ -5,7 +5,7 @@ - + From 923b961d2efbd1b3ff33997786f61f8e62effe40 Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:24:57 +0100 Subject: [PATCH 07/32] feat: added generator tests (#1765) --- Refit.GeneratorTests/Fixture.cs | 95 +++++++++++++++++++ Refit.GeneratorTests/ModuleInitializer.cs | 19 ++++ .../Refit.GeneratorTests.csproj | 46 +++++++++ Refit.GeneratorTests/ReturnTypeTests.cs | 25 +++++ ...ericTaskShouldWork#Generated.g.verified.cs | 24 +++++ ...kShouldWork#IGeneratedClient.g.verified.cs | 66 +++++++++++++ ...ShouldWork#PreserveAttribute.g.verified.cs | 19 ++++ ...VoidTaskShouldWork#Generated.g.verified.cs | 24 +++++ ...kShouldWork#IGeneratedClient.g.verified.cs | 66 +++++++++++++ ...ShouldWork#PreserveAttribute.g.verified.cs | 19 ++++ Refit.sln | 19 ++++ 11 files changed, 422 insertions(+) create mode 100644 Refit.GeneratorTests/Fixture.cs create mode 100644 Refit.GeneratorTests/ModuleInitializer.cs create mode 100644 Refit.GeneratorTests/Refit.GeneratorTests.csproj create mode 100644 Refit.GeneratorTests/ReturnTypeTests.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs new file mode 100644 index 000000000..57f4331d7 --- /dev/null +++ b/Refit.GeneratorTests/Fixture.cs @@ -0,0 +1,95 @@ +using System.Reflection; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Refit.Generator; + +namespace Refit.GeneratorTests; + +public static class Fixture +{ + static readonly MetadataReference RefitAssembly = MetadataReference.CreateFromFile( + typeof(GetAttribute).Assembly.Location, + documentation: XmlDocumentationProvider.CreateFromFile( + Path.ChangeExtension(typeof(GetAttribute).Assembly.Location, ".xml") + ) + ); + + private static readonly Type[] ImportantAssemblies = { + typeof(Binder), + typeof(GetAttribute), + typeof(System.Reactive.Unit), + typeof(Enumerable), + typeof(Newtonsoft.Json.JsonConvert), + typeof(FactAttribute), + typeof(HttpContent), + typeof(Attribute) + }; + + private static Assembly[] AssemblyReferencesForCodegen => + AppDomain.CurrentDomain + .GetAssemblies() + .Concat(ImportantAssemblies.Select(x=>x.Assembly)) + .Distinct() + .Where(a => !a.IsDynamic) + .ToArray(); + + public static Task VerifyForBody(string body) + { + var source = + $$""" + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + namespace RefitGeneratorTest; + + public interface IGeneratedClient + { + {{body}} + } + """; + + return VerifyGenerator(source); + } + + private static CSharpCompilation CreateLibrary(params string[] source) + { + var references = new List(); + var assemblies = AssemblyReferencesForCodegen; + foreach (var assembly in assemblies) + { + if (!assembly.IsDynamic) + { + references.Add(MetadataReference.CreateFromFile(assembly.Location)); + } + } + + references.Add(RefitAssembly); + var compilation = CSharpCompilation.Create( + "compilation", + source.Select(s => CSharpSyntaxTree.ParseText(s)), + references, + new CSharpCompilationOptions(OutputKind.ConsoleApplication) + ); + + return compilation; + } + + private static Task VerifyGenerator(string source) + { + var compilation = CreateLibrary(source); + + var generator = new InterfaceStubGenerator(); + var driver = CSharpGeneratorDriver.Create(generator); + + var ranDriver = driver.RunGenerators(compilation); + var settings = new VerifySettings(); + var verify = VerifyXunit.Verifier.Verify(ranDriver, settings); + return verify.ToTask(); + } +} diff --git a/Refit.GeneratorTests/ModuleInitializer.cs b/Refit.GeneratorTests/ModuleInitializer.cs new file mode 100644 index 000000000..db1bea6a0 --- /dev/null +++ b/Refit.GeneratorTests/ModuleInitializer.cs @@ -0,0 +1,19 @@ +using System.Runtime.CompilerServices; +using VerifyTests.DiffPlex; + +namespace Refit.GeneratorTests; + +public static class ModuleInitializer +{ + // ModuleInitializer should only be used in apps +#pragma warning disable CA2255 + [ModuleInitializer] +#pragma warning restore CA2255 + public static void Init() + { + DerivePathInfo((file, _, type, method) => new(Path.Combine(Path.GetDirectoryName(file), "_snapshots"), type.Name, method.Name)); + + VerifySourceGenerators.Initialize(); + VerifyDiffPlex.Initialize(OutputType.Compact); + } +} diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj new file mode 100644 index 000000000..12d4cd631 --- /dev/null +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -0,0 +1,46 @@ + + + + + + net6.0;net8.0 + enable + enable + + false + true + $(NoWarn);CS1591;CA1819;CA2000;CA2007;CA1056;CA1707;CA1861;xUnit1031 + + + + + + + + + + + + + + + + + + + + + + + + + %(RecursiveDir)\resources\%(Filename)%(Extension) + Always + + + + + + + + diff --git a/Refit.GeneratorTests/ReturnTypeTests.cs b/Refit.GeneratorTests/ReturnTypeTests.cs new file mode 100644 index 000000000..1e9605b6e --- /dev/null +++ b/Refit.GeneratorTests/ReturnTypeTests.cs @@ -0,0 +1,25 @@ +namespace Refit.GeneratorTests; + +[UsesVerify] +public class ReturnTypeTests +{ + [Fact] + public Task GenericTaskShouldWork() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get(); + """); + } + + [Fact] + public Task VoidTaskShouldWork() + { + return Fixture.VerifyForBody( + """ + [Post("/users")] + Task Post(); + """); + } +} diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..19a9fc649 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#IGeneratedClient.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..09c2eec91 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#IGeneratedClient.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Post() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Post", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Post() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Post", global::System.Array.Empty() ); + try + { + await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.sln b/Refit.sln index 6edc2aa7b..fdeb099bb 100644 --- a/Refit.sln +++ b/Refit.sln @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Refit.Xml", "Refit.Xml\Refi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Refit.Benchmarks", "Refit.Benchmarks\Refit.Benchmarks.csproj", "{ABD72A27-9C30-481A-8303-D8F825A8FD47}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Refit.GeneratorTests", "Refit.GeneratorTests\Refit.GeneratorTests.csproj", "{CE7894EA-D411-494A-BA8B-1C231D45025D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -174,6 +176,22 @@ Global {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x64.Build.0 = Release|Any CPU {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x86.ActiveCfg = Release|Any CPU {ABD72A27-9C30-481A-8303-D8F825A8FD47}.Release|x86.Build.0 = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|ARM.ActiveCfg = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|ARM.Build.0 = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|x64.ActiveCfg = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|x64.Build.0 = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|x86.ActiveCfg = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Debug|x86.Build.0 = Debug|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|Any CPU.Build.0 = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|ARM.ActiveCfg = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|ARM.Build.0 = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|x64.ActiveCfg = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|x64.Build.0 = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|x86.ActiveCfg = Release|Any CPU + {CE7894EA-D411-494A-BA8B-1C231D45025D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -181,6 +199,7 @@ Global GlobalSection(NestedProjects) = preSolution {EB833B36-D3CA-4308-A776-8D574F2ADF64} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} {ABD72A27-9C30-481A-8303-D8F825A8FD47} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} + {CE7894EA-D411-494A-BA8B-1C231D45025D} = {0E99249A-FB80-4C60-8FD3-13820E853FF7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6E9C2873-AFF9-4D32-A784-1BA094814054} From 9331797d5d939aa15a3f576333b9708418e64784 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:43:21 +0100 Subject: [PATCH 08/32] chore(deps): update dependency coverlet.collector to v6.0.2 (#1766) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 12d4cd631..45e5be705 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -13,7 +13,7 @@ - + From 37a4f6e1e202158bfe68f04cf667f01b05b95ffb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 08:51:11 +0000 Subject: [PATCH 09/32] chore(deps): update xunit-dotnet monorepo (#1771) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 45e5be705..f5d032fab 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -15,8 +15,8 @@ - - + + From c9f8304ee1ab368f986223ea878ea00fd610d9bb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:21:19 +0100 Subject: [PATCH 10/32] chore(deps): update dependency verify.xunit to v22.11.5 (#1770) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index f5d032fab..09359bd80 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + From 4373adb9935a653f12cb8a3570662250af518309 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:27:13 +0000 Subject: [PATCH 11/32] chore(deps): update dependency microsoft.codeanalysis.csharp.sourcegenerators.testing to v1.1.2 (#1767) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 09359bd80..289172254 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -24,7 +24,7 @@ - + From 040b01e0c11a27cb5879317d2fa34931ae17511b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 27 Jul 2024 00:18:42 +0100 Subject: [PATCH 12/32] chore(deps): update dependency verify.diffplex to v3 (#1772) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 289172254..048ad2411 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -18,7 +18,7 @@ - + From 3300ac54dd81dd36e249a7c7bb7d7635fd592bb8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 23:26:38 +0000 Subject: [PATCH 13/32] chore(deps): update dependency microsoft.net.test.sdk to v17.10.0 (#1769) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 048ad2411..e578d04ee 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -14,7 +14,7 @@ - + From e82a8c7e2e007cb724ca335ae8f85d50341ca833 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:37:06 +0100 Subject: [PATCH 14/32] chore(deps): update dependency serilog to v4.0.1 (#1778) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- samples/Meow.Common/Meow.Common.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Meow.Common/Meow.Common.csproj b/samples/Meow.Common/Meow.Common.csproj index bb3c4c126..b22fbf74c 100644 --- a/samples/Meow.Common/Meow.Common.csproj +++ b/samples/Meow.Common/Meow.Common.csproj @@ -6,7 +6,7 @@ - + From c7b8301094f08054a4d12d3d823e78df9cd9e2e6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:44:27 +0000 Subject: [PATCH 15/32] chore(deps): update dependency verify.sourcegenerators to v2.3.0 (#1780) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index e578d04ee..442eb0149 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -19,7 +19,7 @@ - + From 1c56e32a5e2412a3bddc57fdb2c8bb87e8d87507 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Sat, 17 Aug 2024 04:31:22 +0200 Subject: [PATCH 16/32] Add MemberNotNullWhen annotation for Content / HasContent pair (#1779) * Add MemberNotNullWhen annotation for Content / HasContent pair * Add missing using statement * Update API Tests Bump Version due to API change --------- Co-authored-by: Chris Pulman --- Directory.Build.props | 2 +- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- Refit.GeneratorTests/ReturnTypeTests.cs | 3 +-- .../API/ApiApprovalTests.Refit.DotNet6_0.verified.txt | 2 ++ .../API/ApiApprovalTests.Refit.DotNet8_0.verified.txt | 2 ++ Refit/ApiException.cs | 6 +++++- version.json | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 1694c5b65..a74ab1597 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,7 +36,7 @@ - + diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 442eb0149..74506732f 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + diff --git a/Refit.GeneratorTests/ReturnTypeTests.cs b/Refit.GeneratorTests/ReturnTypeTests.cs index 1e9605b6e..099a888dd 100644 --- a/Refit.GeneratorTests/ReturnTypeTests.cs +++ b/Refit.GeneratorTests/ReturnTypeTests.cs @@ -1,6 +1,5 @@ -namespace Refit.GeneratorTests; +namespace Refit.GeneratorTests; -[UsesVerify] public class ReturnTypeTests { [Fact] diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index 15d17e534..f5e519fed 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -18,6 +18,8 @@ namespace Refit protected ApiException(string exceptionMessage, System.Net.Http.HttpRequestMessage message, System.Net.Http.HttpMethod httpMethod, string? content, System.Net.HttpStatusCode statusCode, string? reasonPhrase, System.Net.Http.Headers.HttpResponseHeaders headers, Refit.RefitSettings refitSettings, System.Exception? innerException = null) { } public string? Content { get; } public System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; } + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] public bool HasContent { get; } public System.Net.Http.Headers.HttpResponseHeaders Headers { get; } public System.Net.Http.HttpMethod HttpMethod { get; } diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index 8c9b3cce6..cbe45beb8 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -18,6 +18,8 @@ namespace Refit protected ApiException(string exceptionMessage, System.Net.Http.HttpRequestMessage message, System.Net.Http.HttpMethod httpMethod, string? content, System.Net.HttpStatusCode statusCode, string? reasonPhrase, System.Net.Http.Headers.HttpResponseHeaders headers, Refit.RefitSettings refitSettings, System.Exception? innerException = null) { } public string? Content { get; } public System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; } + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] public bool HasContent { get; } public System.Net.Http.Headers.HttpResponseHeaders Headers { get; } public System.Net.Http.HttpMethod HttpMethod { get; } diff --git a/Refit/ApiException.cs b/Refit/ApiException.cs index 5db3d5c5d..7959e7df3 100644 --- a/Refit/ApiException.cs +++ b/Refit/ApiException.cs @@ -1,4 +1,5 @@ -using System.Net; +using System.Diagnostics.CodeAnalysis; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -53,6 +54,9 @@ public class ApiException : Exception /// /// Does the response have content? /// + #if NET6_0_OR_GREATER + [MemberNotNullWhen(true, nameof(Content))] + #endif public bool HasContent => !string.IsNullOrWhiteSpace(Content); /// diff --git a/version.json b/version.json index 20873affd..cc296dfba 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "7.1.2", + "version": "7.2.0", "publicReleaseRefSpec": [ "^refs/heads/main$", // we release out of main "^refs/heads/rel/v\\d+\\.\\d+" // we also release branches starting with vN.N From 5259e083447066221bc22404e4a7999b7688d8b3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 17 Aug 2024 02:37:21 +0000 Subject: [PATCH 17/32] chore(deps): update dependency benchmarkdotnet to v0.14.0 (#1784) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.Benchmarks/Refit.Benchmarks.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.Benchmarks/Refit.Benchmarks.csproj b/Refit.Benchmarks/Refit.Benchmarks.csproj index ab5e7133a..357353e74 100644 --- a/Refit.Benchmarks/Refit.Benchmarks.csproj +++ b/Refit.Benchmarks/Refit.Benchmarks.csproj @@ -19,7 +19,7 @@ - + From 7cfdeded6363adf5c7eb0d3902db528e92a17f17 Mon Sep 17 00:00:00 2001 From: Pavel Kravtsov <45625714+MikeAmputer@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:14:34 +0300 Subject: [PATCH 18/32] Extend url parameters default formatting (#1781) * Refactor DefaultUrlParameterFormatter * Extend URL parameters formatting through DefaultUrlParameterFormatter * Add DefaultUrlParameterFormatterTests * Rename DefaultUrlParameterFormatterTests test methods * Union DefaultUrlParameterFormatterTestRequest * Update API * Add DefaultUrlParameterFormatter tests with URI building --------- Co-authored-by: Chris Pulman --- ...ApprovalTests.Refit.DotNet6_0.verified.txt | 2 + ...ApprovalTests.Refit.DotNet8_0.verified.txt | 2 + .../DefaultUrlParameterFormatterTest.cs | 303 ++++++++++++++++++ Refit/RefitSettings.cs | 104 ++++-- 4 files changed, 380 insertions(+), 31 deletions(-) create mode 100644 Refit.Tests/DefaultUrlParameterFormatterTest.cs diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index f5e519fed..faa5be175 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -119,6 +119,8 @@ namespace Refit public class DefaultUrlParameterFormatter : Refit.IUrlParameterFormatter { public DefaultUrlParameterFormatter() { } + public void AddFormat(string format) { } + public void AddFormat(string format) { } public virtual string? Format(object? parameterValue, System.Reflection.ICustomAttributeProvider attributeProvider, System.Type type) { } } public class DefaultUrlParameterKeyFormatter : Refit.IUrlParameterKeyFormatter diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index cbe45beb8..bf8a866b8 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -119,6 +119,8 @@ namespace Refit public class DefaultUrlParameterFormatter : Refit.IUrlParameterFormatter { public DefaultUrlParameterFormatter() { } + public void AddFormat(string format) { } + public void AddFormat(string format) { } public virtual string? Format(object? parameterValue, System.Reflection.ICustomAttributeProvider attributeProvider, System.Type type) { } } public class DefaultUrlParameterKeyFormatter : Refit.IUrlParameterKeyFormatter diff --git a/Refit.Tests/DefaultUrlParameterFormatterTest.cs b/Refit.Tests/DefaultUrlParameterFormatterTest.cs new file mode 100644 index 000000000..f799aa24c --- /dev/null +++ b/Refit.Tests/DefaultUrlParameterFormatterTest.cs @@ -0,0 +1,303 @@ +using System.Globalization; +using System.Reflection; +using Xunit; + +namespace Refit.Tests; + +public class DefaultUrlParameterFormatterTests +{ + class DefaultUrlParameterFormatterTestRequest + { + [Query(Format = "yyyy")] public DateTime? DateTimeWithAttributeFormatYear { get; set; } + + public DateTime? DateTime { get; set; } + + public IEnumerable DateTimeCollection { get; set; } + + public IDictionary DateTimeDictionary { get; set; } + + public IDictionary DateTimeKeyedDictionary { get; set; } + } + + [Fact] + public void NullParameterValue_ReturnsNull() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = null + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + + var output = urlParameterFormatter.Format( + parameters.DateTime, + parameters.GetType().GetProperty(nameof(parameters.DateTime))!, + parameters.GetType()); + + Assert.Null(output); + } + + [Fact] + public void NoFormatters_UseDefaultFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + + var output = urlParameterFormatter.Format( + parameters.DateTime, + parameters.GetType().GetProperty(nameof(parameters.DateTime))!, + parameters.GetType()); + + Assert.Equal("08/21/2023 00:00:00", output); + } + + [Fact] + public void QueryAttributeFormatOnly_UseQueryAttributeFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeWithAttributeFormatYear = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + + var output = urlParameterFormatter.Format( + parameters.DateTimeWithAttributeFormatYear, + parameters.GetType().GetProperty(nameof(parameters.DateTimeWithAttributeFormatYear))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void QueryAttributeAndGeneralFormat_UseQueryAttributeFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeWithAttributeFormatYear = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy-MM-dd"); + + var output = urlParameterFormatter.Format( + parameters.DateTimeWithAttributeFormatYear, + parameters.GetType().GetProperty(nameof(parameters.DateTimeWithAttributeFormatYear))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void QueryAttributeAndSpecificFormat_UseQueryAttributeFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeWithAttributeFormatYear = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy-MM-dd"); + + var output = urlParameterFormatter.Format( + parameters.DateTimeWithAttributeFormatYear, + parameters.GetType().GetProperty(nameof(parameters.DateTimeWithAttributeFormatYear))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void AllFormats_UseQueryAttributeFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeWithAttributeFormatYear = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy-MM-dd"); + urlParameterFormatter.AddFormat("yyyy-MM-dd"); + + var output = urlParameterFormatter.Format( + parameters.DateTimeWithAttributeFormatYear, + parameters.GetType().GetProperty(nameof(parameters.DateTimeWithAttributeFormatYear))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void GeneralFormatOnly_UseGeneralFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var output = urlParameterFormatter.Format( + parameters.DateTime, + parameters.GetType().GetProperty(nameof(parameters.DateTime))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void SpecificFormatOnly_UseSpecificFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var output = urlParameterFormatter.Format( + parameters.DateTime, + parameters.GetType().GetProperty(nameof(parameters.DateTime))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void GeneralAndSpecificFormats_UseSpecificFormat() + { + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = new DateTime(2023, 8, 21) + }; + + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy-MM-dd"); + urlParameterFormatter.AddFormat("yyyy"); + + var output = urlParameterFormatter.Format( + parameters.DateTime, + parameters.GetType().GetProperty(nameof(parameters.DateTime))!, + parameters.GetType()); + + Assert.Equal("2023", output); + } + + [Fact] + public void RequestWithPlainDateTimeQueryParameter_ProducesCorrectQueryString() + { + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var refitSettings = new RefitSettings { UrlParameterFormatter = urlParameterFormatter }; + var fixture = new RequestBuilderImplementation(refitSettings); + var factory = fixture.BuildRequestFactoryForMethod( + nameof(IDummyHttpApi.PostWithComplexTypeQuery) + ); + + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTime = new DateTime(2023, 8, 21), + }; + + var output = factory([parameters]); + var uri = new Uri(new Uri("http://api"), output.RequestUri); + + Assert.Equal( + "?DateTime=2023", + uri.Query + ); + } + + [Fact] + public void RequestWithDateTimeCollectionQueryParameter_ProducesCorrectQueryString() + { + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var refitSettings = new RefitSettings { UrlParameterFormatter = urlParameterFormatter }; + var fixture = new RequestBuilderImplementation(refitSettings); + var factory = fixture.BuildRequestFactoryForMethod( + nameof(IDummyHttpApi.PostWithComplexTypeQuery) + ); + + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeCollection = [new DateTime(2023, 8, 21), new DateTime(2024, 8, 21)], + }; + + var output = factory([parameters]); + var uri = new Uri(new Uri("http://api"), output.RequestUri); + + Assert.Equal( + "?DateTimeCollection=2023%2C2024", + uri.Query + ); + } + + [Fact] + public void RequestWithDateTimeDictionaryQueryParameter_ProducesCorrectQueryString() + { + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var refitSettings = new RefitSettings { UrlParameterFormatter = urlParameterFormatter }; + var fixture = new RequestBuilderImplementation(refitSettings); + var factory = fixture.BuildRequestFactoryForMethod( + nameof(IDummyHttpApi.PostWithComplexTypeQuery) + ); + + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeDictionary = new Dictionary + { + { 1, new DateTime(2023, 8, 21) }, + { 2, new DateTime(2024, 8, 21) }, + }, + }; + + var output = factory([parameters]); + var uri = new Uri(new Uri("http://api"), output.RequestUri); + + Assert.Equal( + "?DateTimeDictionary.1=2023&DateTimeDictionary.2=2024", + uri.Query + ); + } + + [Fact] + public void RequestWithDateTimeKeyedDictionaryQueryParameter_ProducesCorrectQueryString() + { + var urlParameterFormatter = new DefaultUrlParameterFormatter(); + urlParameterFormatter.AddFormat("yyyy"); + + var refitSettings = new RefitSettings { UrlParameterFormatter = urlParameterFormatter }; + var fixture = new RequestBuilderImplementation(refitSettings); + var factory = fixture.BuildRequestFactoryForMethod( + nameof(IDummyHttpApi.PostWithComplexTypeQuery) + ); + + var parameters = new DefaultUrlParameterFormatterTestRequest + { + DateTimeKeyedDictionary = new Dictionary + { + { new DateTime(2023, 8, 21), 1 }, + { new DateTime(2024, 8, 21), 2 }, + }, + }; + + var output = factory([parameters]); + var uri = new Uri(new Uri("http://api"), output.RequestUri); + + Assert.Equal( + "?DateTimeKeyedDictionary.2023=1&DateTimeKeyedDictionary.2024=2", + uri.Query + ); + } +} diff --git a/Refit/RefitSettings.cs b/Refit/RefitSettings.cs index 1180ff177..e7da59125 100644 --- a/Refit/RefitSettings.cs +++ b/Refit/RefitSettings.cs @@ -40,7 +40,8 @@ public RefitSettings( IFormUrlEncodedParameterFormatter? formUrlEncodedParameterFormatter ) : this(contentSerializer, urlParameterFormatter, formUrlEncodedParameterFormatter, null) - { } + { + } /// /// Creates a new instance with the specified parameters @@ -184,7 +185,7 @@ public interface IUrlParameterFormatter /// /// The value. /// The attribute provider. - /// The type. + /// Container class type. /// string? Format(object? value, ICustomAttributeProvider attributeProvider, Type type); } @@ -226,12 +227,39 @@ static readonly ConcurrentDictionary< ConcurrentDictionary > EnumMemberCache = new(); + Dictionary<(Type containerType, Type parameterType), string> SpecificFormats { get; } = new(); + + Dictionary GeneralFormats { get; } = new(); + + /// + /// Add format for specified parameter type contained within container class of specified type. + /// Might be suppressed by a QueryAttribute format. + /// + /// The format string. + /// Container class type. + /// Parameter type. + public void AddFormat(string format) + { + SpecificFormats.Add((typeof(TContainer), typeof(TParameter)), format); + } + + /// + /// Add format for specified parameter type. + /// Might be suppressed by a QueryAttribute format or a container specific format. + /// + /// The format string. + /// Parameter type. + public void AddFormat(string format) + { + GeneralFormats.Add(typeof(TParameter), format); + } + /// /// Formats the specified parameter value. /// /// The parameter value. /// The attribute provider. - /// The type. + /// Container class type. /// /// attributeProvider public virtual string? Format( @@ -245,6 +273,11 @@ Type type throw new ArgumentNullException(nameof(attributeProvider)); } + if (parameterValue == null) + { + return null; + } + // See if we have a format var formatString = attributeProvider .GetCustomAttributes(typeof(QueryAttribute), true) @@ -252,34 +285,41 @@ Type type .FirstOrDefault() ?.Format; - EnumMemberAttribute? enummember = null; - if (parameterValue != null) + EnumMemberAttribute? enumMember = null; + var parameterType = parameterValue.GetType(); + if (parameterType.IsEnum) + { + var cached = EnumMemberCache.GetOrAdd( + parameterType, + t => new ConcurrentDictionary() + ); + enumMember = cached.GetOrAdd( + parameterValue.ToString()!, + val => + parameterType + .GetMember(val) + .First() + .GetCustomAttribute() + ); + } + + if (string.IsNullOrWhiteSpace(formatString) && + SpecificFormats.TryGetValue((type, parameterType), out var specificFormat)) { - var parameterType = parameterValue.GetType(); - if (parameterType.IsEnum) - { - var cached = EnumMemberCache.GetOrAdd( - parameterType, - t => new ConcurrentDictionary() - ); - enummember = cached.GetOrAdd( - parameterValue.ToString()!, - val => - parameterType - .GetMember(val) - .First() - .GetCustomAttribute() - ); - } + formatString = specificFormat; } - return parameterValue == null - ? null - : string.Format( - CultureInfo.InvariantCulture, - string.IsNullOrWhiteSpace(formatString) ? "{0}" : $"{{0:{formatString}}}", - enummember?.Value ?? parameterValue - ); + if (string.IsNullOrWhiteSpace(formatString) && + GeneralFormats.TryGetValue(parameterType, out var generalFormat)) + { + formatString = generalFormat; + } + + return string.Format( + CultureInfo.InvariantCulture, + string.IsNullOrWhiteSpace(formatString) ? "{0}" : $"{{0:{formatString}}}", + enumMember?.Value ?? parameterValue + ); } } @@ -302,18 +342,20 @@ static readonly ConcurrentDictionary< public virtual string? Format(object? parameterValue, string? formatString) { if (parameterValue == null) + { return null; + } var parameterType = parameterValue.GetType(); - EnumMemberAttribute? enummember = null; + EnumMemberAttribute? enumMember = null; if (parameterType.GetTypeInfo().IsEnum) { var cached = EnumMemberCache.GetOrAdd( parameterType, t => new ConcurrentDictionary() ); - enummember = cached.GetOrAdd( + enumMember = cached.GetOrAdd( parameterValue.ToString()!, val => parameterType @@ -326,7 +368,7 @@ static readonly ConcurrentDictionary< return string.Format( CultureInfo.InvariantCulture, string.IsNullOrWhiteSpace(formatString) ? "{0}" : $"{{0:{formatString}}}", - enummember?.Value ?? parameterValue + enumMember?.Value ?? parameterValue ); } } From 258a771f44417c6e48e103ac921fe4786f3c2a1e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:21:09 +0100 Subject: [PATCH 19/32] chore(deps): update dependency nerdbank.gitversioning to v3.6.141 (#1785) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index a74ab1597..54fff75a6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -41,7 +41,7 @@ - + From c05a59985d0be40d2d915c91ec291a409e874045 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:27:22 +0100 Subject: [PATCH 20/32] chore(deps): update dependency microsoft.net.test.sdk to 17.11.0 (#1797) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- Refit.Tests/Refit.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 74506732f..76d4f1e27 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -14,7 +14,7 @@ - + diff --git a/Refit.Tests/Refit.Tests.csproj b/Refit.Tests/Refit.Tests.csproj index 1761bed83..be87476f6 100644 --- a/Refit.Tests/Refit.Tests.csproj +++ b/Refit.Tests/Refit.Tests.csproj @@ -20,7 +20,7 @@ - + From 74f9d5e5e4a42abc6380fd8844de26f59a1bbf64 Mon Sep 17 00:00:00 2001 From: Digifais Date: Sun, 1 Sep 2024 18:19:39 +0200 Subject: [PATCH 21/32] Update README.md JSON Source Generator (#1793) JsonSerializerOptions.AddContext is obsolete. (https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions.addcontext?view=net-8.0) Co-authored-by: Chris Pulman --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d384f2c33..d96ae1e5f 100644 --- a/README.md +++ b/README.md @@ -495,8 +495,9 @@ public class Foo To apply the benefits of the new [JSON source generator](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/) for System.Text.Json added in .NET 6, you can use `SystemTextJsonContentSerializer` with a custom instance of `RefitSettings` and `JsonSerializerOptions`: ```csharp -var options = new JsonSerializerOptions(); -options.AddContext(); +var options = new JsonSerializerOptions() { + TypeInfoResolver = MyJsonSerializerContext.Default +}; var gitHubApi = RestService.For("https://api.github.com", new RefitSettings { From f77f0f39a89323a1566182e2135a0d30382a22a0 Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:39:43 +0100 Subject: [PATCH 22/32] feat: added source generator benchmarks (#1798) Co-authored-by: Chris Pulman --- Refit.Benchmarks/Program.cs | 1 + Refit.Benchmarks/Refit.Benchmarks.csproj | 1 + Refit.Benchmarks/SourceGeneratorBenchmark.cs | 121 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 Refit.Benchmarks/SourceGeneratorBenchmark.cs diff --git a/Refit.Benchmarks/Program.cs b/Refit.Benchmarks/Program.cs index 55f81ef15..02129c15f 100644 --- a/Refit.Benchmarks/Program.cs +++ b/Refit.Benchmarks/Program.cs @@ -10,4 +10,5 @@ BenchmarkRunner.Run(); // BenchmarkRunner.Run(); // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); } diff --git a/Refit.Benchmarks/Refit.Benchmarks.csproj b/Refit.Benchmarks/Refit.Benchmarks.csproj index 357353e74..5bf18d2c8 100644 --- a/Refit.Benchmarks/Refit.Benchmarks.csproj +++ b/Refit.Benchmarks/Refit.Benchmarks.csproj @@ -20,6 +20,7 @@ + diff --git a/Refit.Benchmarks/SourceGeneratorBenchmark.cs b/Refit.Benchmarks/SourceGeneratorBenchmark.cs new file mode 100644 index 000000000..d5b93ce66 --- /dev/null +++ b/Refit.Benchmarks/SourceGeneratorBenchmark.cs @@ -0,0 +1,121 @@ +using System.Reflection; + +using BenchmarkDotNet.Attributes; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; + +using Refit.Generator; + +namespace Refit.Benchmarks; + +[MemoryDiagnoser] +public class SourceGeneratorBenchmark +{ + #region SourceText + private const string SmallInterface = + """ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + namespace RefitGeneratorTest; + + public interface IReallyExcitingCrudApi where T : class + { + [Post("")] + Task Create([Body] T payload); + + [Get("")] + Task> ReadAll(); + + [Get("/{key}")] + Task ReadOne(TKey key); + + [Put("/{key}")] + Task Update(TKey key, [Body]T payload); + + [Delete("/{key}")] + Task Delete(TKey key); + } + """; + #endregion + + static readonly MetadataReference RefitAssembly = MetadataReference.CreateFromFile( + typeof(GetAttribute).Assembly.Location, + documentation: XmlDocumentationProvider.CreateFromFile( + Path.ChangeExtension(typeof(GetAttribute).Assembly.Location, ".xml") + ) + ); + static readonly Type[] ImportantAssemblies = { + typeof(Binder), + typeof(GetAttribute), + typeof(Enumerable), + typeof(Newtonsoft.Json.JsonConvert), + typeof(HttpContent), + typeof(Attribute) + }; + + static Assembly[] AssemblyReferencesForCodegen => + AppDomain.CurrentDomain + .GetAssemblies() + .Concat(ImportantAssemblies.Select(x=>x.Assembly)) + .Distinct() + .Where(a => !a.IsDynamic) + .ToArray(); + + private Compilation compilation; + private CSharpGeneratorDriver driver; + + private void Setup(string sourceText) + { + var references = new List(); + var assemblies = AssemblyReferencesForCodegen; + foreach (var assembly in assemblies) + { + if (!assembly.IsDynamic) + { + references.Add(MetadataReference.CreateFromFile(assembly.Location)); + } + } + + references.Add(RefitAssembly); + compilation = CSharpCompilation.Create( + "compilation", + [CSharpSyntaxTree.ParseText(sourceText)], + references, + new CSharpCompilationOptions(OutputKind.ConsoleApplication) + ); + + var generator = new InterfaceStubGeneratorV2().AsSourceGenerator(); + driver = CSharpGeneratorDriver.Create(generator); + } + + [GlobalSetup(Target = nameof(Compile))] + public void SetupSmall() => Setup(SmallInterface); + + [Benchmark] + public GeneratorDriver Compile() + { + return driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _); + } + + [GlobalSetup(Target = nameof(Cached))] + public void SetupCached() + { + Setup(SmallInterface); + driver = (CSharpGeneratorDriver)driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _); + compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct MyValue {}")); + } + + [Benchmark] + public GeneratorDriver Cached() + { + return driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _); + } +} From 47ce83ea8cc5e57a00d567158d983e0097e59cd9 Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:44:18 +0100 Subject: [PATCH 23/32] feat: added more snapshot `InterfaceTests` (#1802) --- Refit.GeneratorTests/Fixture.cs | 40 +++++++++ Refit.GeneratorTests/InterfaceTests.cs | 85 +++++++++++++++++++ ...ainedInterfaceTest#Generated.g.verified.cs | 24 ++++++ ...faceTest#IContainedInterface.g.verified.cs | 66 ++++++++++++++ ...erfaceTest#PreserveAttribute.g.verified.cs | 19 +++++ ...RefitInterfaceTest#Generated.g.verified.cs | 24 ++++++ ...faceTest#IGeneratedInterface.g.verified.cs | 66 ++++++++++++++ ...erfaceTest#PreserveAttribute.g.verified.cs | 19 +++++ ...RefitInterfaceTest#Generated.g.verified.cs | 24 ++++++ ...InterfaceTest#IBaseInterface.g.verified.cs | 66 ++++++++++++++ ...faceTest#IGeneratedInterface.g.verified.cs | 81 ++++++++++++++++++ ...erfaceTest#PreserveAttribute.g.verified.cs | 19 +++++ ...lobalNamespaceTest#Generated.g.verified.cs | 24 ++++++ ...paceTest#IGeneratedInterface.g.verified.cs | 66 ++++++++++++++ ...espaceTest#PreserveAttribute.g.verified.cs | 19 +++++ ...estedNamespaceTest#Generated.g.verified.cs | 24 ++++++ ...paceTest#IGeneratedInterface.g.verified.cs | 66 ++++++++++++++ ...espaceTest#PreserveAttribute.g.verified.cs | 19 +++++ 18 files changed, 751 insertions(+) create mode 100644 Refit.GeneratorTests/InterfaceTests.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs index 57f4331d7..affae8dab 100644 --- a/Refit.GeneratorTests/Fixture.cs +++ b/Refit.GeneratorTests/Fixture.cs @@ -57,6 +57,46 @@ public interface IGeneratedClient return VerifyGenerator(source); } + public static Task VerifyForType(string declarations) + { + var source = + $$""" + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + namespace RefitGeneratorTest; + + {{declarations}} + """; + + return VerifyGenerator(source); + } + + public static Task VerifyForDeclaration(string declarations) + { + var source = + $$""" + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Text; + using System.Threading; + using System.Threading.Tasks; + using Refit; + + {{declarations}} + """; + + return VerifyGenerator(source); + } + private static CSharpCompilation CreateLibrary(params string[] source) { var references = new List(); diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs new file mode 100644 index 000000000..937d7d970 --- /dev/null +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -0,0 +1,85 @@ +namespace Refit.GeneratorTests; + +public class InterfaceTests +{ + [Fact] + public Task ContainedInterfaceTest() + { + return Fixture.VerifyForType( + """ + public class ContainerType + { + public interface IContainedInterface + { + [Get("/users")] + Task Get(); + } + } + """); + } + + [Fact] + public Task DerivedRefitInterfaceTest() + { + return Fixture.VerifyForType( + """ + public interface IGeneratedInterface : IBaseInterface + { + [Get("/users")] + Task Get(); + } + + public interface IBaseInterface + { + [Get("/posts")] + Task GetPosts(); + } + """); + } + + [Fact] + public Task DerivedNonRefitInterfaceTest() + { + return Fixture.VerifyForType( + """ + public interface IGeneratedInterface : IBaseInterface + { + [Get("/users")] + Task Get(); + } + + public interface IBaseInterface + { + void NonRefitMethod(); + } + """); + } + + [Fact] + public Task NestedNamespaceTest() + { + return Fixture.VerifyForDeclaration( + """ + namespace Nested.RefitGeneratorTest; + + public interface IGeneratedInterface + { + [Get("/users")] + Task Get(); + } + """); + } + + [Fact] + public Task GlobalNamespaceTest() + { + return Fixture.VerifyForDeclaration( + """ + public interface IGeneratedInterface + { + [Get("/users")] + Task Get(); + } + """); + } +} diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs new file mode 100644 index 000000000..b15640c13 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#IContainedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IContainedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestContainerTypeIContainedInterface + : global::RefitGeneratorTest.ContainerType.IContainedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestContainerTypeIContainedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.ContainerType.IContainedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..437319341 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedInterface + : global::RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs new file mode 100644 index 000000000..1dcf928d5 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IBaseInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIBaseInterface + : global::RefitGeneratorTest.IBaseInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..c415be964 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,81 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedInterface + : global::RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.GetPosts() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("GetPosts", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..d7bc42d86 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class IGeneratedInterface + : global::IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..ae16b03e4 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedInterface.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class NestedRefitGeneratorTestIGeneratedInterface + : global::Nested.RefitGeneratorTest.IGeneratedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public NestedRefitGeneratorTestIGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::Nested.RefitGeneratorTest.IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore From 782413588c7e79380ee86bebbe36910bd0490786 Mon Sep 17 00:00:00 2001 From: Tim M <49349513+TimothyMakkison@users.noreply.github.com> Date: Fri, 6 Sep 2024 02:03:33 +0100 Subject: [PATCH 24/32] chore: ignore repeat files and add test (#1804) * chore: use `IgnoreGeneratedResult` to ignore unrelated files * feat: added test to verify generated files --- Refit.GeneratorTests/Fixture.cs | 14 ++-- Refit.GeneratorTests/GeneratedTest.cs | 14 ++++ ...houldEmitAllFiles#Generated.g.verified.cs} | 0 ...mitAllFiles#IGeneratedClient.g.verified.cs | 66 +++++++++++++++++++ ...tAllFiles#PreserveAttribute.g.verified.cs} | 0 ...e.DotNet6_0#IGeneratedClient.g.received.cs | 66 +++++++++++++++++++ ...RefitInterfaceTest#Generated.g.verified.cs | 24 ------- ...erfaceTest#PreserveAttribute.g.verified.cs | 19 ------ ...RefitInterfaceTest#Generated.g.verified.cs | 24 ------- ...erfaceTest#PreserveAttribute.g.verified.cs | 19 ------ ...lobalNamespaceTest#Generated.g.verified.cs | 24 ------- ...espaceTest#PreserveAttribute.g.verified.cs | 19 ------ ...estedNamespaceTest#Generated.g.verified.cs | 24 ------- ...espaceTest#PreserveAttribute.g.verified.cs | 19 ------ ...ericTaskShouldWork#Generated.g.verified.cs | 24 ------- ...ShouldWork#PreserveAttribute.g.verified.cs | 19 ------ ...VoidTaskShouldWork#Generated.g.verified.cs | 24 ------- ...ShouldWork#PreserveAttribute.g.verified.cs | 19 ------ 18 files changed, 156 insertions(+), 262 deletions(-) create mode 100644 Refit.GeneratorTests/GeneratedTest.cs rename Refit.GeneratorTests/_snapshots/{InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs => GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs} (100%) create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs rename Refit.GeneratorTests/_snapshots/{InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs => GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs} (100%) create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs index affae8dab..3b779981f 100644 --- a/Refit.GeneratorTests/Fixture.cs +++ b/Refit.GeneratorTests/Fixture.cs @@ -33,7 +33,7 @@ public static class Fixture .Where(a => !a.IsDynamic) .ToArray(); - public static Task VerifyForBody(string body) + public static Task VerifyForBody(string body, bool ignoreNonInterfaces = true) { var source = $$""" @@ -54,7 +54,7 @@ public interface IGeneratedClient } """; - return VerifyGenerator(source); + return VerifyGenerator(source, ignoreNonInterfaces); } public static Task VerifyForType(string declarations) @@ -120,7 +120,7 @@ private static CSharpCompilation CreateLibrary(params string[] source) return compilation; } - private static Task VerifyGenerator(string source) + private static Task VerifyGenerator(string source, bool ignoreNonInterfaces = true) { var compilation = CreateLibrary(source); @@ -129,7 +129,13 @@ private static Task VerifyGenerator(string source) var ranDriver = driver.RunGenerators(compilation); var settings = new VerifySettings(); - var verify = VerifyXunit.Verifier.Verify(ranDriver, settings); + if (ignoreNonInterfaces) + { + settings.IgnoreGeneratedResult(x => x.HintName.Contains("PreserveAttribute.g.cs", StringComparison.Ordinal)); + settings.IgnoreGeneratedResult(x => x.HintName.Contains("Generated.g.cs", StringComparison.Ordinal)); + } + + var verify = Verify(ranDriver, settings); return verify.ToTask(); } } diff --git a/Refit.GeneratorTests/GeneratedTest.cs b/Refit.GeneratorTests/GeneratedTest.cs new file mode 100644 index 000000000..b75ce1571 --- /dev/null +++ b/Refit.GeneratorTests/GeneratedTest.cs @@ -0,0 +1,14 @@ +namespace Refit.GeneratorTests; + +public class GeneratedTest +{ + [Fact] + public Task ShouldEmitAllFiles() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get(); + """, false); + } +} diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs similarity index 100% rename from Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs rename to Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..19a9fc649 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs similarity index 100% rename from Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs rename to Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs new file mode 100644 index 000000000..19a9fc649 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore From acff0a637ff260506b61bbb8ce93c297cd1aa565 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 08:08:42 +0100 Subject: [PATCH 25/32] chore(deps): update dependency nerdbank.gitversioning to 3.6.143 (#1805) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 54fff75a6..5be14eb51 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -41,7 +41,7 @@ - + From 29e0e1ce293b7cbfbb4298af86f22e7331e0d68d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 07:14:34 +0000 Subject: [PATCH 26/32] chore(deps): update dotnet monorepo (#1788) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .../InterfaceStubGenerator.Roslyn38.csproj | 2 +- .../InterfaceStubGenerator.Roslyn40.csproj | 2 +- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 4 ++-- Refit.Tests/Refit.Tests.csproj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/InterfaceStubGenerator.Roslyn38/InterfaceStubGenerator.Roslyn38.csproj b/InterfaceStubGenerator.Roslyn38/InterfaceStubGenerator.Roslyn38.csproj index 6e9ca887a..bfc4940a5 100644 --- a/InterfaceStubGenerator.Roslyn38/InterfaceStubGenerator.Roslyn38.csproj +++ b/InterfaceStubGenerator.Roslyn38/InterfaceStubGenerator.Roslyn38.csproj @@ -12,7 +12,7 @@ - + diff --git a/InterfaceStubGenerator.Roslyn40/InterfaceStubGenerator.Roslyn40.csproj b/InterfaceStubGenerator.Roslyn40/InterfaceStubGenerator.Roslyn40.csproj index ff5bcf9d7..7ee02683a 100644 --- a/InterfaceStubGenerator.Roslyn40/InterfaceStubGenerator.Roslyn40.csproj +++ b/InterfaceStubGenerator.Roslyn40/InterfaceStubGenerator.Roslyn40.csproj @@ -13,7 +13,7 @@ - + diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 76d4f1e27..35762849e 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -17,13 +17,13 @@ - + - + diff --git a/Refit.Tests/Refit.Tests.csproj b/Refit.Tests/Refit.Tests.csproj index be87476f6..65b042b01 100644 --- a/Refit.Tests/Refit.Tests.csproj +++ b/Refit.Tests/Refit.Tests.csproj @@ -25,7 +25,7 @@ - + From b86c07ad63829f5d5223dabe4e699587390a9c27 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 8 Sep 2024 17:35:53 +0100 Subject: [PATCH 27/32] chore(deps): update dependency verify.sourcegenerators to 2.4.0 (#1806) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 35762849e..c65b9c683 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -19,7 +19,7 @@ - + From 1de8b3be12d31c889d04570a5ea874216a1e7f6a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 06:33:29 +0100 Subject: [PATCH 28/32] chore(deps): update dependency verify.xunit to 26.3.0 (#1808) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index c65b9c683..dc1d6f8a5 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + From 4987ef0c287018cb26be8d44e70cbc0a05455b26 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:04:43 +0100 Subject: [PATCH 29/32] chore(deps): update dependency verify.xunit to 26.3.1 (#1811) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index dc1d6f8a5..f280b2a4f 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + From 89e0a84060ebccd7525b220c078ea254e294ecc2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:04:14 +0100 Subject: [PATCH 30/32] chore(deps): update dependency verify.xunit to 26.4.0 (#1813) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index f280b2a4f..1e9089ad2 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + From e6f075ee624bb335139b2887b3dccbb09984b894 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 15 Sep 2024 19:57:11 -0400 Subject: [PATCH 31/32] Add Version and HttpVersionPolicy support for HttpRequestMessage (#1800) * Add Version and HttpVersionPolicy support for HttpRequestMessage * Add one more #if NET6_0_OR_GREATER * Fixes a build error because of VS automatic code * Fixes test verification error * Try the test again * Fix API Tests --------- Co-authored-by: Chris Pulman --- .../ApiApprovalTests.Refit.DotNet6_0.verified.txt | 2 ++ .../ApiApprovalTests.Refit.DotNet8_0.verified.txt | 2 ++ Refit/RefitSettings.cs | 7 +++++++ Refit/RequestBuilderImplementation.cs | 12 +++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index faa5be175..e702291ea 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -335,6 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } + public System.Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder { diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index bf8a866b8..4d9b1bc27 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -335,6 +335,8 @@ namespace Refit public System.Collections.Generic.Dictionary? HttpRequestMessageOptions { get; set; } public Refit.IUrlParameterFormatter UrlParameterFormatter { get; set; } public Refit.IUrlParameterKeyFormatter UrlParameterKeyFormatter { get; set; } + public System.Version Version { get; set; } + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } } public static class RequestBuilder { diff --git a/Refit/RefitSettings.cs b/Refit/RefitSettings.cs index e7da59125..b439b731e 100644 --- a/Refit/RefitSettings.cs +++ b/Refit/RefitSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Net; using System.Net.Http; using System.Reflection; using System.Runtime.Serialization; @@ -127,6 +128,12 @@ public Func< /// Optional Key-Value pairs, which are displayed in the property . /// public Dictionary? HttpRequestMessageOptions { get; set; } + +#if NET6_0_OR_GREATER + public Version Version { get; set; } = HttpVersion.Version11; + + public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower; +#endif } /// diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 59ef3affa..807cafb79 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -737,7 +737,9 @@ bool paramsContainsCancellationToken AddHeadersToRequest(headersToAdd, ret); AddPropertiesToRequest(restMethod, ret, paramList); - +#if NET6_0_OR_GREATER + AddVersionToRequest(ret); +#endif // NB: The URI methods in .NET are dumb. Also, we do this // UriBuilder business so that we preserve any hardcoded query // parameters as well as add the parameterized ones. @@ -1032,6 +1034,14 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag #endif } + void AddVersionToRequest(HttpRequestMessage ret) + { +#if NET6_0_OR_GREATER + ret.Version = settings.Version; + ret.VersionPolicy = settings.VersionPolicy; +#endif + } + IEnumerable> ParseQueryParameter( object? param, ParameterInfo parameterInfo, From d3263f743a9fc92dd2578e72694c875dc2d77195 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 01:06:33 +0100 Subject: [PATCH 32/32] chore(deps): update dependency microsoft.net.test.sdk to 17.11.1 (#1814) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- Refit.Tests/Refit.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 1e9089ad2..7ab160f24 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -14,7 +14,7 @@ - + diff --git a/Refit.Tests/Refit.Tests.csproj b/Refit.Tests/Refit.Tests.csproj index 65b042b01..0e33aaa64 100644 --- a/Refit.Tests/Refit.Tests.csproj +++ b/Refit.Tests/Refit.Tests.csproj @@ -20,7 +20,7 @@ - +