Skip to content

feature (minor): Valueless query flags via [QueryName] (Retrofit @QueryName equivalent) #2168

Description

@glennawatson

Summary

Refit's [Query] always emits key=value. There's no way to emit a valueless query flag — a bare ?filter with no = — which some APIs use for presence-style switches.

Prior art: Retrofit @QueryName

Retrofit has @QueryName: the parameter value becomes the query parameter name with no value. A List/array produces multiple bare flags (?a&b&c). encoded=true disables encoding of the name.

Proposal

Add an equivalent — most naturally a small attribute (e.g. [QueryName]) or an option on [Query] — that renders the parameter's string value as a valueless query segment. Collections render as repeated bare names. Honour the existing query encoding/URI-format settings.

Considerations

  • Interaction with UrlResolutionMode and QueryUriFormatAttribute.
  • Null handling: omit on null (consistent with [Query]).
  • Must be implemented in both the reflection and source-generator paths.
  • Decide attribute-vs-[Query]-option; a separate attribute reads clearer and matches Retrofit.

Acceptance criteria

  • A parameter renders as a bare ?name flag; collections render as repeated names.
  • Works in reflection + generated paths.
  • TUnit tests for scalar and collection cases; README/docs entry.

Pointers

  • Query building: src/Refit/RequestBuilderImplementation.QueryAndHeaders.cs and .Helpers.cs.
  • Attribute examples to mirror: src/Refit/QueryAttribute.cs.
  • Generator: src/InterfaceStubGenerator.Shared/*.
  • Retrofit reference: ~/square/retrofit/retrofit/src/main/java/retrofit2/http/QueryName.java.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions