1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::OpenApiFromParam;
use crate::gen::OpenApiGenerator;
use okapi::openapi3::*;
use std::result::Result as StdResult;
type Result = crate::Result<Parameter>;
macro_rules! impl_from_param {
($ty: path) => {
impl<'r> OpenApiFromParam<'r> for $ty {
fn path_parameter(gen: &mut OpenApiGenerator, name: String) -> Result {
let schema = gen.json_schema::<$ty>();
Ok(Parameter {
name,
location: "path".to_owned(),
description: None,
required: true,
deprecated: false,
allow_empty_value: false,
value: ParameterValue::Schema {
style: None,
explode: None,
allow_reserved: false,
schema,
example: None,
examples: None,
},
extensions: Default::default(),
})
}
}
};
}
impl_from_param!(f32);
impl_from_param!(f64);
impl_from_param!(isize);
impl_from_param!(i8);
impl_from_param!(i16);
impl_from_param!(i32);
impl_from_param!(i64);
impl_from_param!(i128);
impl_from_param!(usize);
impl_from_param!(u8);
impl_from_param!(u16);
impl_from_param!(u32);
impl_from_param!(u64);
impl_from_param!(u128);
impl_from_param!(bool);
impl_from_param!(String);
impl_from_param!(std::borrow::Cow<'r, str>);
impl<'r, T: OpenApiFromParam<'r>> OpenApiFromParam<'r> for StdResult<T, T::Error> {
fn path_parameter(gen: &mut OpenApiGenerator, name: String) -> Result {
T::path_parameter(gen, name)
}
}
impl<'r, T: OpenApiFromParam<'r>> OpenApiFromParam<'r> for Option<T> {
fn path_parameter(gen: &mut OpenApiGenerator, name: String) -> Result {
T::path_parameter(gen, name)
}
}