Skip to content

[Feature]: generate inline (reflection-free) request building for query parameters #2191

Closed

Description

@glennawatson

Follow-up from #2174 (v13.0.0).

Is your feature request related to a problem?

#2174 made path/route-template parameters generate inline (reflection-free). Query parameters still fall back to the reflection request builder:

  • auto-appended query params: [Get("/users")] Task<T> Search(string q) -> /users?q=...
  • [Query] (including [Query(Format=...)], nested/collection expansion, custom delimiters)
  • [AliasAs] on a query parameter

A method with any of these is emitted against BuildRestResultFuncForMethod (the reflection tail), so it throws at runtime under AddRefitGeneratedClient (generated-only) or NativeAOT. Query params are the most common Refit shape, so the generated-only/AOT path is still unusable for typical query APIs. The runtime symptom is #2185.

Describe the solution you'd like

Generate inline request building for methods whose only otherwise-unsupported parameters are query params. The generated query string must match the reflection path's escaping and formatting so the RequestUri is identical between the two.

Describe alternatives you've considered

Describe suggestions on how to achieve the feature

Generator (src/InterfaceStubGenerator.Shared/):

  • Parser.Request.cs: ParseRequestParameter returns UnsupportedRequestParameter (~line 357) for a parameter with no {...} placeholder. Add a RequestParameterKind.Query, classify plain / [Query] / [AliasAs] params into it, and relax canGenerateInline in ParseRequest.
  • Reuse the existing [Query] parsing (ParseQueryAttribute*, ~lines 580-625) and IsSimpleType (Parser.Request.Helpers.cs).

Runtime (src/Refit/):

  • Add a query-append helper modeled on GeneratedRequestRunner.BuildRequestPath: linear scan, ValueStringBuilder, StringHelpers.EscapeDataString per value, handling collection expansion and delimiters. The reflection version is in RequestBuilderImplementation.RequestBuilding.cs.

Guardrails:

  • Value formatting still goes through IUrlParameterFormatter; keep that boundary, the separate value-formatting issue covers it.
  • Keep the RF006 fallback analyzer and GeneratedRequestBuildingFallbackContractTests in sync: as these shapes become inline, their expectedFallback cases flip.

Tests: emit-load-invoke asserting the final RequestUri (single param, multiple, [AliasAs], [Query(Format=...)], collection, null/empty, and a value that needs escaping such as "a b/c") plus Verify snapshots.

Additional context

Deferred from the #2174 review. Related: #2185, #2168, #2169, #2182. Dotted ({request.Prop}) and round-trip ({**param}) placeholders stay on the reflection fallback (#2046) and are already covered by tests.

Activity

  1. added
    🔴 priority: high
    🧬 area: source-gen
    🔗 area: url-routing
    🪶 area: aot-trimming
    on Jul 2, 2026
  2. glennawatson commented on Jul 15, 2026

    @glennawatson
    ContributorAuthor

    This is addressed in the Refit 14 beta, now available on NuGet: https://www.nuget.org/packages/Refit/14.0.0-beta.1

    Please give it a try - feedback ahead of the stable 14.0.0 release is very welcome.

    Type-safe REST API clients for .NET, generated from annotated interfaces with build-time source generation, direct request construction, System.Text.Json defaults, and support for trimming and AOT.
  3. github-actions commented on Jul 30, 2026

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  4. locked as resolved and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Featureup-for-grabs🔗 area: url-routing🔴 priority: high🧬 area: source-gen🪶 area: aot-trimming

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions