Skip to content

Commit

Permalink
Merge pull request #539 from Respawnsive/apizr
Browse files Browse the repository at this point in the history
[Apizr] Deprecated Optional package removed from code & doc
  • Loading branch information
christianhelle authored Nov 25, 2024
2 parents 156375d + 2f951c1 commit 9e5b009
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 84 deletions.
33 changes: 5 additions & 28 deletions src/Refitter.Core/ApizrRegistrationGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
using System.Text;
using Refitter.Core.Settings;

Expand Down Expand Up @@ -235,20 +235,7 @@ public static string Generate(
""");
}

if (settings.ApizrSettings.WithOptionalMediation && isDependencyInjectionExtension)
{
apizrPackages.Add(ApizrPackages.Apizr_Integrations_Optional);
usingsCodeBuilder.AppendLine(
$$"""
using MediatR;
""");
optionsCodeBuilder.AppendLine();
optionsCodeBuilder.Append(
$$"""
.WithOptionalMediation()
""");
}
else if (settings.ApizrSettings.WithMediation && isDependencyInjectionExtension)
if (settings.ApizrSettings.WithMediation && isDependencyInjectionExtension)
{
apizrPackages.Add(ApizrPackages.Apizr_Integrations_MediatR);
usingsCodeBuilder.AppendLine(
Expand All @@ -266,16 +253,7 @@ public static string Generate(
{
if (isDependencyInjectionExtension)
{
if (settings.ApizrSettings.WithOptionalMediation)
{
apizrPackages.Add(ApizrPackages.Apizr_Integrations_FileTransfer_Optional);
optionsCodeBuilder.AppendLine();
optionsCodeBuilder.Append(
$$"""
.WithFileTransferOptionalMediation()
""");
}
else if (settings.ApizrSettings.WithMediation)
if (settings.ApizrSettings.WithMediation)
{
apizrPackages.Add(ApizrPackages.Apizr_Integrations_FileTransfer_MediatR);
optionsCodeBuilder.AppendLine();
Expand Down Expand Up @@ -310,8 +288,7 @@ public static string Generate(
var packages = apizrPackages.OrderByDescending(p => p).ToList();
if (packages.Count > 0)
{
if (!isDependencyInjectionExtension && (settings.ApizrSettings.WithOptionalMediation ||
settings.ApizrSettings.WithMediation ||
if (!isDependencyInjectionExtension && (settings.ApizrSettings.WithMediation ||
settings.ApizrSettings.WithCacheProvider == CacheProviderType.InMemory ||
settings.ApizrSettings.WithCacheProvider == CacheProviderType.DistributedAsString ||
settings.ApizrSettings.WithCacheProvider == CacheProviderType.DistributedAsByteArray))
Expand Down Expand Up @@ -660,4 +637,4 @@ public static partial class ApizrRegistration
code.AppendLine();
return code.ToString();
}
}
}
10 changes: 2 additions & 8 deletions src/Refitter.Core/Settings/ApizrPackages.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel;
using System.ComponentModel;

namespace Refitter.Core.Settings
{
Expand Down Expand Up @@ -38,12 +38,6 @@ public enum ApizrPackages
Apizr_Integrations_MediatR = 1024 | Apizr_Extensions_Microsoft_DependencyInjection,

[Description("dotnet add package Apizr.Integrations.FileTransfer.MediatR, then register MediatR")]
Apizr_Integrations_FileTransfer_MediatR = 2048 | Apizr_Integrations_MediatR | Apizr_Extensions_Microsoft_FileTransfer,

[Description("dotnet add package Apizr.Integrations.Optional, then register MediatR")]
Apizr_Integrations_Optional = 4096 | Apizr_Integrations_MediatR,

[Description("dotnet add package Apizr.Integrations.FileTransfer.Optional, then register MediatR")]
Apizr_Integrations_FileTransfer_Optional = 8192 | Apizr_Integrations_Optional | Apizr_Integrations_FileTransfer_MediatR,
Apizr_Integrations_FileTransfer_MediatR = 2048 | Apizr_Integrations_MediatR | Apizr_Extensions_Microsoft_FileTransfer
}
}
7 changes: 1 addition & 6 deletions src/Refitter.Core/Settings/ApizrSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Refitter.Core
{
Expand Down Expand Up @@ -52,11 +52,6 @@ public class ApizrSettings
/// </summary>
public bool WithMediation { get; set; } = false;

/// <summary>
/// Set it to true to handle request with MediatR and Optional result (default: false)
/// </summary>
public bool WithOptionalMediation { get; set; } = false;

/// <summary>
/// Set it to true to manage file transfers (default: false)
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions src/Refitter.SourceGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ The following is an example `.refitter` file
"withCacheProvider": "InMemory", // Optional. Values=None|Akavache|MonkeyCache|InMemory|DistributedAsString|DistributedAsByteArray. Default=None
"withPriority": true, // Optional. Default=false
"withMediation": true, // Optional. Default=false
"withOptionalMediation": true, // Optional. Default=false
"withMappingProvider": "AutoMapper", // Optional. Values=None|AutoMapper|Mapster. Default=None
"withFileTransfer": true // Optional. Default=false
},
Expand Down Expand Up @@ -160,7 +159,6 @@ The following is an example `.refitter` file
- `withCacheProvider` - Set the cache provider to be used
- `withPriority` - Tells if Apizr should handle request priority
- `withMediation` - Tells if Apizr should handle request mediation (extended only)
- `withOptionalMediation` - Tells if Apizr should handle optional request mediation (extended only)
- `withMappingProvider` - Set the mapping provider to be used
- `withFileTransfer` - Tells if Apizr should handle file transfer
- `codeGeneratorSettings` - Setting this allows customization of the NSwag generated types and contracts
Expand Down Expand Up @@ -192,4 +190,4 @@ The following is an example `.refitter` file
- `generateNativeRecords` - Default is false
- `generateDefaultValues` - Default is true
- `inlineNamedAny` - Default is false
- `excludedTypeNames` - Default is empty
- `excludedTypeNames` - Default is empty
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using Refitter.Core;
using Xunit;

Expand All @@ -25,7 +25,6 @@ public class ApizrGeneratorWithMicrosoftHttpResilienceTests
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand All @@ -41,7 +40,6 @@ public class ApizrGeneratorWithMicrosoftHttpResilienceTests
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand Down Expand Up @@ -168,4 +166,4 @@ public void Can_Generate_Static_Registration_For_Multiple_Interfaces()
code.Should().Contain("AddManagerFor<IStoreApi>()");
}
#endregion
}
}
5 changes: 2 additions & 3 deletions src/Refitter.Tests/ApizrGeneratorWithPollyTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using Refitter.Core;
using Xunit;

Expand Down Expand Up @@ -27,7 +27,6 @@ public class ApizrGeneratorWithPollyTests
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand Down Expand Up @@ -124,4 +123,4 @@ public void Can_Generate_Without_BaseUrl()

code.Should().Contain("> optionsBuilder)");
}
}
}
26 changes: 13 additions & 13 deletions src/Refitter.Tests/Build/ProjectFileContents.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Refitter.Tests.Build;
namespace Refitter.Tests.Build;

public static class ProjectFileContents
{
Expand All @@ -8,22 +8,22 @@ public static class ProjectFileContents
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include=""System.Text.Json"" Version=""8.0.4"" />
<PackageReference Include=""System.Text.Json"" Version=""8.0.5"" />
<PackageReference Include=""System.ComponentModel.Annotations"" Version=""4.5.0"" />
<PackageReference Include=""System.Runtime.Serialization.Primitives"" Version=""4.3.0"" />
<PackageReference Include=""Microsoft.Extensions.DependencyInjection"" Version=""8.0.0"" />
<PackageReference Include=""Microsoft.Extensions.Http.Polly"" Version=""8.0.7"" />
<PackageReference Include=""Microsoft.Extensions.Http.Resilience"" Version=""8.9.1"" />
<PackageReference Include=""Microsoft.Extensions.DependencyInjection"" Version=""8.0.1"" />
<PackageReference Include=""Microsoft.Extensions.Http.Polly"" Version=""8.0.11"" />
<PackageReference Include=""Microsoft.Extensions.Http.Resilience"" Version=""8.10.0"" />
<PackageReference Include=""Microsoft.Extensions.Options.ConfigurationExtensions"" Version=""8.0.0"" />
<PackageReference Include=""Polly.Contrib.WaitAndRetry"" Version=""1.1.1"" />
<PackageReference Include=""System.Reactive"" Version=""6.0.1"" />
<PackageReference Include=""Apizr.Integrations.FileTransfer.Optional"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.Mapster"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.AutoMapper"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.Akavache"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.MonkeyCache"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Extensions.Microsoft.Caching"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.Fusillade"" Version=""6.1.0"" />
<PackageReference Include=""Apizr.Integrations.FileTransfer.MediatR"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Integrations.Mapster"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Integrations.AutoMapper"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Integrations.Akavache"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Integrations.MonkeyCache"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Extensions.Microsoft.Caching"" Version=""6.4.0"" />
<PackageReference Include=""Apizr.Integrations.Fusillade"" Version=""6.4.0"" />
</ItemGroup>
</Project>";
}
}
5 changes: 2 additions & 3 deletions src/Refitter.Tests/SwaggerPetstoreApizrTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using Refitter.Core;
using Refitter.Tests.Build;
using Refitter.Tests.Resources;
Expand All @@ -24,7 +24,6 @@ public ApizrGeneratorSettings()
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
};
Expand Down Expand Up @@ -658,4 +657,4 @@ private static async Task<string> GenerateCode(
var sut = await RefitGenerator.CreateAsync(settings);
return sut.Generate();
}
}
}
7 changes: 2 additions & 5 deletions src/Refitter.Tests/SwaggerPetstoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using Refitter.Core;
using Refitter.Tests.Build;
using Refitter.Tests.Resources;
Expand Down Expand Up @@ -372,7 +372,6 @@ public async Task Can_Generate_Code_Apizr_Setup(SampleOpenSpecifications version
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand Down Expand Up @@ -402,7 +401,6 @@ public async Task Can_Generate_Code_Apizr_Setup_With_Polly(SampleOpenSpecificati
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand Down Expand Up @@ -432,7 +430,6 @@ public async Task Can_Generate_Code_Apizr_Setup_Without_Polly(SampleOpenSpecific
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
Expand Down Expand Up @@ -743,4 +740,4 @@ public async Task Can_Generate_Code_With_DynamicQuerystringParameters(SampleOpen
generateCode.Should().Contain("[Query] LoginUserQueryParams queryParams);")
.And.Contain("public class LoginUserQueryParams");
}
}
}
17 changes: 6 additions & 11 deletions src/Refitter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ The following is an example `.refitter` file
"withCacheProvider": "InMemory", // Optional. Values=None|Akavache|MonkeyCache|InMemory|DistributedAsString|DistributedAsByteArray. Default=None
"withPriority": true, // Optional. Default=false
"withMediation": true, // Optional. Default=false
"withOptionalMediation": true, // Optional. Default=false
"withMappingProvider": "AutoMapper", // Optional. Values=None|AutoMapper|Mapster. Default=None
"withFileTransfer": true // Optional. Default=false
},
Expand Down Expand Up @@ -258,7 +257,6 @@ The following is an example `.refitter` file
- `withCacheProvider` - Set the cache provider to be used
- `withPriority` - Tells if Apizr should handle request priority
- `withMediation` - Tells if Apizr should handle request mediation (extended only)
- `withOptionalMediation` - Tells if Apizr should handle optional request mediation (extended only)
- `withMappingProvider` - Set the mapping provider to be used
- `withFileTransfer` - Tells if Apizr should handle file transfer
- `codeGeneratorSettings` - Setting this allows customization of the NSwag generated types and contracts
Expand Down Expand Up @@ -1832,7 +1830,6 @@ This is what the `.refitter` settings file may look like, depending on you confi
"withCacheProvider": "InMemory", // Optional, default is None
"withPriority": true, // Optional, default is false
"withMediation": true, // Optional, default is false
"withOptionalMediation": true, // Optional, default is false
"withMappingProvider": "AutoMapper", // Optional, default is None
"withFileTransfer": true // Optional, default is false
}
Expand Down Expand Up @@ -1863,8 +1860,7 @@ public static IServiceCollection ConfigurePetstoreApiApizrManager(
.WithInMemoryCacheHandler()
.WithAutoMapperMappingHandler()
.WithPriority()
.WithOptionalMediation()
.WithFileTransferOptionalMediation();
.WithFileTransferMediation();

return services.AddApizrManagerFor<IPetstoreApi>(optionsBuilder);
}
Expand Down Expand Up @@ -1895,7 +1891,6 @@ This comes in handy especially when generating multiple interfaces, by tag or en
"withCacheProvider": "InMemory", // Optional, default is None
"withPriority": true, // Optional, default is false
"withMediation": true, // Optional, default is false
"withOptionalMediation": true, // Optional, default is false
"withMappingProvider": "AutoMapper", // Optional, default is None
"withFileTransfer": true // Optional, default is false
}
Expand Down Expand Up @@ -1926,8 +1921,7 @@ public static IServiceCollection ConfigurePetstoreApizrManagers(
.WithInMemoryCacheHandler()
.WithAutoMapperMappingHandler()
.WithPriority()
.WithOptionalMediation()
.WithFileTransferOptionalMediation();
.WithFileTransferMediation();

return services.AddApizr(
registry => registry
Expand Down Expand Up @@ -1971,7 +1965,8 @@ public static IApizrManager<ISwaggerPetstoreOpenAPI30> BuildPetstore30ApizrManag
optionsBuilder += options => options
.WithAkavacheCacheHandler()
.WithAutoMapperMappingHandler(new MapperConfiguration(config => { /* YOUR_MAPPINGS_HERE */ }))
.WithPriority();
.WithPriority()
.WithFileTransfer();

return ApizrBuilder.Current.CreateManagerFor<ISwaggerPetstoreOpenAPI30>(optionsBuilder);
}
Expand Down Expand Up @@ -2002,7 +1997,6 @@ This comes in handy especially when generating multiple interfaces, by tag or en
"withCacheProvider": "InMemory", // Optional, default is None
"withPriority": true, // Optional, default is false
"withMediation": true, // Optional, default is false
"withOptionalMediation": true, // Optional, default is false
"withMappingProvider": "AutoMapper", // Optional, default is None
"withFileTransfer": true // Optional, default is false
}
Expand All @@ -2018,7 +2012,8 @@ public static IApizrRegistry BuildPetstoreApizrManagers(Action<IApizrCommonOptio
optionsBuilder += options => options
.WithAkavacheCacheHandler()
.WithAutoMapperMappingHandler(new MapperConfiguration(config => { /* YOUR_MAPPINGS_HERE */ }))
.WithPriority();
.WithPriority()
.WithFileTransferMediation();

return ApizrBuilder.Current.CreateRegistry(
registry => registry
Expand Down

0 comments on commit 9e5b009

Please sign in to comment.