Skip to main content

QueryParams

Derive Macro QueryParams 

Source
#[derive(QueryParams)]
Expand description

#[derive(QueryParams)] — mark a struct as a REST query parameter.

Generates impl QueryParams, whose openapi_params() describes each field for the OpenAPI document. The generated route registers those parameters, so the spec is derived from the same declaration that determines the wire format instead of being inferred separately.

Field rules, both enforced at compile time:

  • every field’s leaf type must implement QueryScalar — scalars, Option<scalar>, and Vec<scalar>. Nested structs are rejected: a query string is a flat key/value list and cannot represent them unambiguously.
  • a Vec<..> field must carry #[serde(default)], since an empty vector emits no key and would otherwise fail to deserialize.

#[serde(rename = "...")] and #[serde(skip)] are honoured so the spec matches what serde actually puts on the wire.