[][src]Function rocket_okapi::request::get_nested_query_parameters

pub fn get_nested_query_parameters<T>(
    gen: &mut OpenApiGenerator,
    _name: String,
    required: bool
) -> Vec<Parameter> where
    T: JsonSchema

Given an object that implements the JsonSchema generate all the Parameter that are used to create documentation. Use when manually implementing a Query Guard. Example:

use rocket::request::{Query, FromQuery};
use serde::{Serialize, Deserialize};
use schemars::JsonSchema;
use rocket_okapi::{
    gen::OpenApiGenerator,
    request::OpenApiFromQuery,
    request::get_nested_query_parameters
};

#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema)]
pub struct ApiPagination{
    page: Option<u32>,
    per_page: Option<u32>,
}

impl<'q> FromQuery<'q> for ApiPagination {
    type Error = String;// Some kind of error

    fn from_query(_query: Query<'q>) -> Result<Self, Self::Error> {
        Ok(ApiPagination::default())
    }
}

impl<'r> OpenApiFromQuery<'r> for ApiPagination {
    fn query_multi_parameter(gen: &mut OpenApiGenerator, name: String, required: bool)
    -> rocket_okapi::Result<Vec<okapi::openapi3::Parameter>> {
        Ok(get_nested_query_parameters::<ApiPagination>(gen, name, required))
    }
}