paperclip_core/v3/models/
request_body.rs

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
use super::{invalid_referenceor, non_body_parameter_to_v3_parameter, v2, Either};

impl From<v2::DefaultParameterRaw>
    for Either<openapiv3::Parameter, Either<openapiv3::RequestBody, Option<openapiv3::Schema>>>
{
    fn from(v2: v2::DefaultParameterRaw) -> Self {
        let parameter_data = |schema: Option<openapiv3::Schema>| openapiv3::ParameterData {
            name: v2.name.clone(),
            description: v2.description.clone(),
            required: v2.required,
            deprecated: None,
            format: match &schema {
                Some(schema) => openapiv3::ParameterSchemaOrContent::Schema(
                    openapiv3::ReferenceOr::Item(schema.clone()),
                ),
                None => openapiv3::ParameterSchemaOrContent::Schema(invalid_referenceor(format!(
                    "No Schema found: {:?}",
                    v2
                ))),
            },
            example: None,
            examples: Default::default(),
            explode: None,
            extensions: Default::default(),
        };

        match v2.in_ {
            v2::ParameterIn::Query => Either::Left(openapiv3::Parameter::Query {
                parameter_data: parameter_data(non_body_parameter_to_v3_parameter(false, &v2)),
                allow_reserved: false,
                style: Default::default(),
                allow_empty_value: None,
            }),
            v2::ParameterIn::Header => Either::Left(openapiv3::Parameter::Header {
                parameter_data: parameter_data(non_body_parameter_to_v3_parameter(false, &v2)),
                style: Default::default(),
            }),
            v2::ParameterIn::Path => Either::Left(openapiv3::Parameter::Path {
                parameter_data: parameter_data(non_body_parameter_to_v3_parameter(false, &v2)),
                style: Default::default(),
            }),
            v2::ParameterIn::FormData => {
                Either::Right(Either::Right(non_body_parameter_to_v3_parameter(true, &v2)))
            }
            v2::ParameterIn::Body => Either::Right(Either::Left(openapiv3::RequestBody {
                description: v2.description,
                content: {
                    let media = openapiv3::MediaType {
                        schema: v2.schema.map(|s| s.into()),
                        ..Default::default()
                    };
                    let mut map = openapiv3::RequestBody::default().content;
                    map.insert(v2::SpecFormat::Json.mime().0.to_string(), media);
                    map
                },
                required: v2.required,
                extensions: Default::default(),
            })),
        }
    }
}