pub trait IntoParams {
    fn into_params() -> Vec<Parameter>;
}
Expand description

Trait used to convert implementing type to OpenAPI parameters for actix-web framework.

This trait is deriveable 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() -> Vec<utoipa::openapi::path::Parameter> {
        vec![
            utoipa::openapi::path::ParameterBuilder::new()
                .name("id")
                .required(utoipa::openapi::Required::True)
                .parameter_in(utoipa::openapi::path::ParameterIn::Path)
                .description(Some("Id of pet"))
                .schema(Some(
                    utoipa::openapi::PropertyBuilder::new()
                        .component_type(utoipa::openapi::ComponentType::Integer)
                        .format(Some(utoipa::openapi::ComponentFormat::Int64)),
                ))
                .build(),
            utoipa::openapi::path::ParameterBuilder::new()
                .name("name")
                .required(utoipa::openapi::Required::True)
                .parameter_in(utoipa::openapi::path::ParameterIn::Path)
                .description(Some("Name of pet"))
                .schema(Some(
                    utoipa::openapi::PropertyBuilder::new()
                        .component_type(utoipa::openapi::ComponentType::String),
                ))
                .build(),
        ]
    }
}

Required Methods

Provide Vec of openapi::path::Parameters to caller. The result is used in utoipa-gen library to provide OpenAPI parameter information for the endpoint using the parameters.

Implementors