feat: improve generated clients for AOT#2151
Merged
Merged
Conversation
- Add generated URL-encoded body handling that preserves declared form types for AOT. - Compile generated source against repository analyzer rules and older C# syntax expectations. - Share enum, property, and string helpers across runtime request paths. - Extend native AOT and runtime tests for generated request construction.
- Keep the substring fallback for targets without the span URI escaping overload. - Limit the suppression to the helper method that selects the target-specific path.
ChrisPulman
approved these changes
Jun 20, 2026
- Make generated infrastructure field names unique against interface members. - Cover collisions with generated request-builder, settings, and type-parameter fields.
- Add problem-details coverage for validation errors and extension values. - Cover enum backing-type helpers and generated-only RestService overloads.
- Add focused coverage for generator helpers, analyzer exits, and code-fix paths. - Cover the new generic enum and request-builder fallbacks without reflection-only tests.
- Use JsonElement parsing APIs where modern targets support them. - Reject duplicate JSON properties in default System.Text.Json options on .NET 10+. - Include the generator test accessors required by the coverage tests.
- Track the attribute state directly when parsing authorization and body parameters. - This keeps the same validation behavior while satisfying constant-condition analysis.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changed
RestService.ForGenerated(...)for applications that want to require a source-generated Refit client.HttpClientandRefitSettingswithout creating the reflection request builder.CancellationTokenparameters[HeaderCollection]parameter types[HeaderCollection]parameter types toIDictionary<string, string>Compatibility
RestService.For<T>(...)andAddRefitClient<T>()remain the normal entry points.RestService.ForGenerated<T>(...)is the stricter entry point for applications that require generated clients.Issues
Closes #1345.
Closes #1142.
Closes #1475.
Validation
dotnet build "Refit/Refit.csproj" -f net8.0 -v:minimal --no-restore /p:NuGetAudit=false /m:1dotnet build "Refit/Refit.csproj" -f net462 -v:minimal --no-restore /p:NuGetAudit=false /m:1dotnet build "Refit/Refit.csproj" -f net10.0 -v:minimal --no-restore /p:NuGetAudit=false /m:1dotnet build "Refit/Refit.csproj" -f net11.0 -v:minimal --no-restore /p:NuGetAudit=false /m:1dotnet test "tests/Refit.Tests/Refit.Tests.csproj" -f net8.0 -v:minimal --no-restore /p:NuGetAudit=falsedotnet build "tests/Refit.GeneratorTests/Refit.GeneratorTests.csproj" -f net8.0 -v:minimal --no-restore /p:NuGetAudit=false /m:1dotnet run --project "tests/Refit.GeneratorTests/Refit.GeneratorTests.csproj" -f net8.0 --no-restore --no-builddotnet publish "Refit.NativeAotSmoke/Refit.NativeAotSmoke.csproj" -c Release -r linux-x64 --self-contained true /p:NuGetAudit=false /p:ContinuousIntegrationBuild=true./Refit.NativeAotSmoke/bin/Release/net8.0/linux-x64/publish/Refit.NativeAotSmokegit diff --checkChecklist
mainbranch