Skip to main content

ParamMeta

Struct ParamMeta 

Source
pub struct ParamMeta {
Show 16 fields pub title: Option<String>, pub description: Option<String>, pub deprecated: bool, pub include_in_schema: bool, pub example: Option<Value>, pub examples: HashMap<String, Example>, pub ge: Option<f64>, pub le: Option<f64>, pub gt: Option<f64>, pub lt: Option<f64>, pub min_length: Option<usize>, pub max_length: Option<usize>, pub pattern: Option<String>, pub alias: Option<String>, pub validation_alias: Option<String>, pub serialization_alias: Option<String>,
}
Expand description

Parameter metadata for OpenAPI documentation.

This struct captures metadata attributes that can be specified on struct fields using #[param(...)] attributes.

§Example

#[derive(FromRequest)]
struct MyQuery {
    #[param(description = "Search term", deprecated)]
    q: Option<String>,

    #[param(title = "Page Number", ge = 1)]
    page: i32,
}

Fields§

§title: Option<String>

Display title for the parameter.

§description: Option<String>

Description of the parameter.

§deprecated: bool

Whether the parameter is deprecated.

§include_in_schema: bool

Whether to include in OpenAPI schema.

§example: Option<Value>

Example value.

§examples: HashMap<String, Example>

Named examples.

§ge: Option<f64>

Minimum value constraint (for numbers).

§le: Option<f64>

Maximum value constraint (for numbers).

§gt: Option<f64>

Exclusive minimum (for numbers).

§lt: Option<f64>

Exclusive maximum (for numbers).

§min_length: Option<usize>

Minimum length (for strings).

§max_length: Option<usize>

Maximum length (for strings).

§pattern: Option<String>

Pattern constraint (regex).

§alias: Option<String>

Alternative name used in request (query/header/form). If set and validation_alias is None, this is also used for validation. If set and serialization_alias is None, this is used for OpenAPI schema.

§validation_alias: Option<String>

Name used specifically for validation (overrides alias for validation).

§serialization_alias: Option<String>

Name used specifically for serialization/OpenAPI (overrides alias for serialization).

Implementations§

Source§

impl ParamMeta

Source

pub fn new() -> Self

Create a new parameter metadata with default values.

Source

pub fn title(self, title: impl Into<String>) -> Self

Set the title.

Source

pub fn description(self, description: impl Into<String>) -> Self

Set the description.

Source

pub fn deprecated(self) -> Self

Mark as deprecated.

Source

pub fn exclude_from_schema(self) -> Self

Exclude from OpenAPI schema.

Source

pub fn example(self, example: Value) -> Self

Set an example value.

Source

pub fn ge(self, value: f64) -> Self

Set minimum value constraint (>=).

Source

pub fn le(self, value: f64) -> Self

Set maximum value constraint (<=).

Source

pub fn gt(self, value: f64) -> Self

Set exclusive minimum constraint (>).

Source

pub fn lt(self, value: f64) -> Self

Set exclusive maximum constraint (<).

Source

pub fn min_length(self, len: usize) -> Self

Set minimum length for strings.

Source

pub fn max_length(self, len: usize) -> Self

Set maximum length for strings.

Source

pub fn pattern(self, pattern: impl Into<String>) -> Self

Set a regex pattern constraint.

Source

pub fn alias(self, alias: impl Into<String>) -> Self

Set an alias for this parameter.

The alias is the alternative name used in the request (query string, header, etc.). If validation_alias is not set, this value is also used for validation. If serialization_alias is not set, this value is used in OpenAPI schema.

§Example
#[param(alias = "q")]
query: String,  // Accepts ?q=value instead of ?query=value
Source

pub fn validation_alias(self, alias: impl Into<String>) -> Self

Set a validation-specific alias.

This name is used when validating/extracting the parameter from the request. Overrides the general alias for validation purposes.

Source

pub fn serialization_alias(self, alias: impl Into<String>) -> Self

Set a serialization-specific alias.

This name is used in the OpenAPI schema for this parameter. Overrides the general alias for serialization/OpenAPI purposes.

Source

pub fn effective_validation_name(&self) -> Option<&str>

Get the effective name for extraction/validation.

Returns validation_alias if set, otherwise alias if set, otherwise None.

Source

pub fn effective_serialization_name(&self) -> Option<&str>

Get the effective name for OpenAPI/serialization.

Returns serialization_alias if set, otherwise alias if set, otherwise None.

Source

pub fn to_parameter( &self, name: impl Into<String>, location: ParameterLocation, required: bool, schema: Option<Schema>, ) -> Parameter

Convert to an OpenAPI Parameter.

If a serialization alias is configured (via serialization_alias or alias), it will be used as the parameter name in the OpenAPI schema.

Trait Implementations§

Source§

impl Clone for ParamMeta

Source§

fn clone(&self) -> ParamMeta

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParamMeta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParamMeta

Source§

fn default() -> ParamMeta

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ResponseProduces<T> for T