-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the possibility to generate all the Apizr goodness #428
Conversation
…UseApizr settings option
…UseApizr settings option
Wow! This is some great stuff @JeremyBP ! I would like to take my time to review this thoroughly as this is a bit of a large pull request and I'm not supposed to be in front of the computer during my summer vacation 🌞🍹 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #428 +/- ##
==========================================
- Coverage 97.46% 95.45% -2.01%
==========================================
Files 64 70 +6
Lines 2564 3389 +825
==========================================
+ Hits 2499 3235 +736
- Misses 40 114 +74
- Partials 25 40 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The changelog is machine-generated based on issues and pull requests closed between tags. We can update the README another time. Several documentation files are almost copies of each other, whereas some are a bit trimmed down. Refitter also has a DocFX-generated documentation site hosted at https://refitter.github.io |
@JeremyBP The build seems to fail
Looks like |
Oops! it seems I forgot to change the former UseApizr to the new ApizrSettings. |
Ok so now the solution builds as expected and I adjusted some parts of code to improve sonar quality score. |
You don't need to worry about improving on cognitive complexity for now. There is really not much to gain from that. I tend to keep these SonarCloud improvements in separate pull requests |
I tried out your branch locally with the following {
"openApiPath": "https://petstore3.swagger.io/api/v3/openapi.json",
"namespace": "Petstore.Apizr",
"outputFolder": "GeneratedCode",
"outputFilename": "SwaggerPetstoreApizr.cs",
"naming": {
"useOpenApiTitle": false,
"interfaceName": "SwaggerPetstoreApizr"
},
"dependencyInjectionSettings": {
"baseUrl": "https://petstore3.swagger.io/api/v3",
"transientErrorHandler": "HttpResilience",
"maxRetryCount": 3,
"firstBackoffRetryInSeconds": 0.5
},
"apizrSettings": {
"withRequestOptions": true,
"withRegistrationHelper": true,
"withCacheProvider": "InMemory",
"withPriority": true,
"withMediation": true,
"withOptionalMediation": true,
"withMappingProvider": "AutoMapper",
"withFileTransfer": true
}
} and a <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Apizr.Extensions.Microsoft.Caching" Version="6.0.0-preview.6" />
<PackageReference Include="Apizr.Integrations.AutoMapper" Version="6.0.0-preview.6" />
<PackageReference Include="Apizr.Integrations.FileTransfer.Optional" Version="6.0.0-preview.6" />
<PackageReference Include="Apizr.Integrations.Fusillade" Version="6.0.0-preview.6" />
</ItemGroup>
</Project> and as expected the build fails due to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good, all-in-all. I only found one thing that I think needs changing, and that's suggesting dotnet add package
instead of Install-Package
for non-Windows users.
I'd like to wait with merging this in until it can produce code that can build, and I guess that depends on an upcoming Apizr release you mentioned in the description
Quality Gate passedIssues Measures |
Hey, I just pushed Apizr-v6.0.0-preview.7 and pushed a little commit to Refitter too.
public static class ProjectFileContents
{
public const string Net70App = @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net70</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include=""Newtonsoft.Json"" Version=""13.0.1"" />
<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.4"" />
<PackageReference Include=""Microsoft.Extensions.Options.ConfigurationExtensions"" Version=""8.0.0"" />
<PackageReference Include=""Microsoft.Extensions.Http.Resilience"" Version=""8.0.0"" />
<PackageReference Include=""Polly.Contrib.WaitAndRetry"" Version=""1.1.1"" />
<PackageReference Include=""Polly.Extensions.Http"" Version=""3.0.0"" />
<PackageReference Include=""System.Reactive"" Version=""6.0.0"" />
<PackageReference Include=""Apizr.Extensions.Microsoft.Caching"" Version=""6.0.0-preview.7"" />
<PackageReference Include=""Apizr.Integrations.AutoMapper"" Version=""6.0.0-preview.7"" />
<PackageReference Include=""Apizr.Integrations.FileTransfer.Optional"" Version=""6.0.0-preview.7"" />
<PackageReference Include=""Apizr.Integrations.Fusillade"" Version=""6.0.0-preview.7"" />
</ItemGroup>
</Project>";
} And ApizrTests.cs to: private static async Task<string> GenerateCode()
{
var swaggerFile = await CreateSwaggerFile(OpenApiSpec);
var settings = new RefitGeneratorSettings
{
OpenApiPath = swaggerFile,
UseCancellationTokens = true,
OptionalParameters = true,
Naming = new NamingSettings
{
UseOpenApiTitle = false,
InterfaceName = "JobDetails"
},
DependencyInjectionSettings = new DependencyInjectionSettings
{
BaseUrl = "https://petstore3.swagger.io/api/v3",
TransientErrorHandler = TransientErrorHandler.HttpResilience
},
ApizrSettings = new ApizrSettings
{
WithRequestOptions = true,
WithRegistrationHelper = true,
WithCacheProvider = CacheProviderType.InMemory,
WithPriority = true,
WithMediation = true,
WithOptionalMediation = true,
WithMappingProvider = MappingProviderType.AutoMapper,
WithFileTransfer = true
}
};
var sut = await RefitGenerator.CreateAsync(settings);
var generateCode = sut.Generate();
return generateCode;
} Then, calling the following test create the right code and builds the project like a charm: [Fact]
public async Task Can_Build_Generated_Code()
{
string generateCode = await GenerateCode();
BuildHelper
.BuildCSharp(generateCode)
.Should()
.BeTrue();
}
{
"openApiPath": "https://petstore3.swagger.io/api/v3/openapi.json",
"namespace": "Petstore",
"outputFolder": "Test",
"outputFilename": "Generated.cs",
"naming": {
"useOpenApiTitle": false,
"interfaceName": "PetstoreApi"
},
"dependencyInjectionSettings": {
"baseUrl": "https://petstore3.swagger.io/api/v3",
"transientErrorHandler": "HttpResilience",
"maxRetryCount": 3,
"firstBackoffRetryInSeconds": 0.5
},
"apizrSettings": {
"withRequestOptions": true,
"withRegistrationHelper": true,
"withCacheProvider": "InMemory",
"withPriority": true,
"withMediation": true,
"withOptionalMediation": true,
"withMappingProvider": "AutoMapper",
"withFileTransfer": true
}
} And a Project.csproj in a Test sub folder looking like: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net70</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<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.4" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="Apizr.Extensions.Microsoft.Caching" Version="6.0.0-preview.7" />
<PackageReference Include="Apizr.Integrations.AutoMapper" Version="6.0.0-preview.7" />
<PackageReference Include="Apizr.Integrations.FileTransfer.Optional" Version="6.0.0-preview.7" />
<PackageReference Include="Apizr.Integrations.Fusillade" Version="6.0.0-preview.7" />
</ItemGroup>
</Project> It builds without any issue. Actually, I wonder if your issue could be due to your ".Apizr" into your namespace and project name... |
You were right! I never knew that you couldn't have your |
Thanks for this amazing contribution @JeremyBP !! |
As discussed in #404, here is the PR giving the aibility to generate all the Apizr goodness with Refitter.
First of all, I introduced an ApizrSettings into the .refitter definition so that we could say if we want to generate it if it's set, or not if it's left to null.
From here, only if we get some ApizrSettings set:
[RequestOptions] IApizrRequestOptions options
if asked toAll 400+ tests passed, including the ones added to cover Apizr things.
So now if we provide the following configuration (taken from an included Test):
And ask Refitter to generate from it:
It will generate the following registration helper:
I still have to publish an Apizr v6.0.0-preview.7 to Nuget to be fully compatible with such new Refitter capabilities.
I'll do it tomorrow morning.
I did not update your Changelog neither your Readme as I thought it was more about what you want to say and how :)
Let me know.
Jérémy