pub trait IntoParams {
// Required method
fn into_params(
parameter_in_provider: impl Fn() -> Option<ParameterIn>,
) -> Vec<Parameter>;
}
Expand description
Trait used to convert implementing type to OpenAPI parameters.
This trait is derivable for structs which are used to describe path
or query
parameters.
For more details of #[derive(IntoParams)]
refer to derive documentation.
§Examples
Derive IntoParams
implementation. This example will fail to compile because IntoParams
cannot
be used alone and it need to be used together with endpoint using the params as well. See
derive documentation for more details.
use utoipa::{IntoParams};
#[derive(IntoParams)]
struct PetParams {
/// Id of pet
id: i64,
/// Name of pet
name: String,
}
Roughly equal manual implementation of IntoParams
trait.
impl utoipa::IntoParams for PetParams {
fn into_params(
parameter_in_provider: impl Fn() -> Option<utoipa::openapi::path::ParameterIn>
) -> Vec<utoipa::openapi::path::Parameter> {
vec![
utoipa::openapi::path::ParameterBuilder::new()
.name("id")
.required(utoipa::openapi::Required::True)
.parameter_in(parameter_in_provider().unwrap_or_default())
.description(Some("Id of pet"))
.schema(Some(
utoipa::openapi::ObjectBuilder::new()
.schema_type(utoipa::openapi::SchemaType::Integer)
.format(Some(utoipa::openapi::SchemaFormat::KnownFormat(utoipa::openapi::KnownFormat::Int64))),
))
.build(),
utoipa::openapi::path::ParameterBuilder::new()
.name("name")
.required(utoipa::openapi::Required::True)
.parameter_in(parameter_in_provider().unwrap_or_default())
.description(Some("Name of pet"))
.schema(Some(
utoipa::openapi::ObjectBuilder::new()
.schema_type(utoipa::openapi::SchemaType::String),
))
.build(),
]
}
}
Required Methods§
sourcefn into_params(
parameter_in_provider: impl Fn() -> Option<ParameterIn>,
) -> Vec<Parameter>
fn into_params( parameter_in_provider: impl Fn() -> Option<ParameterIn>, ) -> Vec<Parameter>
Provide Vec
of openapi::path::Parameter
s to caller. The result is used in utoipa-gen
library to
provide OpenAPI parameter information for the endpoint using the parameters.
Object Safety§
This trait is not object safe.