Repository navigation
feat(analyzers): explain why a method cannot generate and flag unbound route placeholders - #2340
Merged
Merged
Conversation
- Setting RefitRequireGeneratedRequests to true promotes RF006 to an error. - Runs as a target because the consumer's project body is evaluated after refit.props. - Off by default so builds that use Refit.Reflection on purpose are unaffected.
…d route placeholders - The shared classifier now records the first reason a request is not generated and the parameter responsible. - RF006 reports at that parameter, return type or attribute, names the reason and remedy, and only suggests Refit.Reflection when it can run the method. - RF006 carries Reason and ParameterOrdinal properties for tooling. - Add RF015 for a route placeholder no parameter binds; the runtime check stays as a backstop. - Add classifier-backed fixtures for every reason and for the published support table.
- Any declared class or struct part is serialized, not only sealed ones.
- IObservable replies are now generated, so ObserveLegacy no longer exercised the fallback. - SearchLegacyAsync(object) falls back for real, so the trim check for #2200 covers it again.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2340 +/- ##
========================================
Coverage 99.97% 99.97%
========================================
Files 217 219 +2
Lines 11528 11784 +256
Branches 2221 2262 +41
========================================
+ Hits 11525 11781 +256
Misses 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Remove IsUrlBindingSupported, which has no callers now that FindUnsupportedUrlBinding reports the ordinal. - An RF015 placeholder always comes from a source attribute's first argument, so its location lookup needs no null guard. - Cover method-level fallbacks located on the method, including one with no source declaration.
|
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



Summary
RF006 now says exactly why a method falls back to the reflection request builder, where, and what to change; a new RF015 flags route placeholders no parameter binds.
Refit.Reflectiononly when it can actually run the method; for declarations both builders reject it says the declaration must change.Reason(for exampleUnsupportedQueryType) and, when a parameter is responsible,ParameterOrdinal.[Get("/users/{id}")]with noidparameter is reported on the{id}text, with the parameter name to add or alias. The runtimeArgumentExceptionstays as the backstop, andRefitSettings.AllowUnmatchedRouteParametersremains the way to keep a placeholder on purpose.<RefitRequireGeneratedRequests>true</RefitRequireGeneratedRequests>turns RF006 into an error for Native AOT or generated-only projects. It is off by default;dotnet_diagnostic.RF006.severity = erroris the per-folder alternative.IObservablereplies are now generated, soObserveLegacywas replaced by a member that genuinely falls back.Why
A fallback warning that did not say which feature triggered it left users reading generated files or guessing.
Breaking changes
None.
How this was verified
Fixtures cover every fallback reason with its exact source span and advice, plus a classifier-backed support table (request generated, JSON metadata needed, Native AOT smoke coverage).
Notes for the reviewer
Start at
InlineFallbackReason.csandClassifyInlineRequestinParser.Request.cs, thenFallbackExplanation.cs.LocationsoRequestModelstays value-equatable for incremental caching.GeneratedRequestSupportTableTestsholds the fixtures that back it.Checklist