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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Implements encoding object for content.
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use super::extensions::Extensions;
use super::{builder, path::ParameterStyle, set_value, Header, Ref, RefOr};
builder! {
EncodingBuilder;
/// A single encoding definition applied to a single schema [`Object
/// property`](crate::openapi::schema::Object::properties).
#[derive(Serialize, Deserialize, Default, Clone, PartialEq)]
#[cfg_attr(feature = "debug", derive(Debug))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Encoding {
/// The Content-Type for encoding a specific property. Default value depends on the property
/// type: for string with format being binary – `application/octet-stream`; for other primitive
/// types – `text/plain`; for object - `application/json`; for array – the default is defined
/// based on the inner type. The value can be a specific media type (e.g. `application/json`),
/// a wildcard media type (e.g. `image/*`), or a comma-separated list of the two types.
#[serde(skip_serializing_if = "Option::is_none")]
pub content_type: Option<String>,
/// A map allowing additional information to be provided as headers, for example
/// Content-Disposition. Content-Type is described separately and SHALL be ignored in this
/// section. This property SHALL be ignored if the request body media type is not a multipart.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub headers: BTreeMap<String, RefOr<Header>>,
/// Describes how a specific property value will be serialized depending on its type. See
/// Parameter Object for details on the style property. The behavior follows the same values as
/// query parameters, including default values. This property SHALL be ignored if the request
/// body media type is not `application/x-www-form-urlencoded`.
#[serde(skip_serializing_if = "Option::is_none")]
pub style: Option<ParameterStyle>,
/// When this is true, property values of type array or object generate separate parameters for
/// each value of the array, or key-value-pair of the map. For other types of properties this
/// property has no effect. When style is form, the default value is true. For all other
/// styles, the default value is false. This property SHALL be ignored if the request body
/// media type is not `application/x-www-form-urlencoded`.
#[serde(skip_serializing_if = "Option::is_none")]
pub explode: Option<bool>,
/// Determines whether the parameter value SHOULD allow reserved characters, as defined by
/// RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is
/// false. This property SHALL be ignored if the request body media type is not
/// `application/x-www-form-urlencoded`.
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_reserved: Option<bool>,
/// Encoding information for nested object properties.
#[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
pub encoding: BTreeMap<String, Encoding>,
/// Encoding information for tuple-like nested array items.
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub prefix_encoding: Vec<Encoding>,
/// Encoding information for each nested array item.
#[serde(skip_serializing_if = "Option::is_none")]
pub item_encoding: Option<Box<Encoding>>,
/// Optional extensions "x-something".
#[serde(skip_serializing_if = "Option::is_none", flatten)]
pub extensions: Option<Extensions>,
}
}
impl EncodingBuilder {
/// Set the content type. See [`Encoding::content_type`].
pub fn content_type<S: Into<String>>(mut self, content_type: Option<S>) -> Self {
set_value!(self content_type content_type.map(Into::into))
}
/// Add a [`Header`]. See [`Encoding::headers`].
pub fn header<S: Into<String>, H: Into<Header>>(mut self, header_name: S, header: H) -> Self {
self.headers
.insert(header_name.into(), header.into().into());
self
}
/// Add a [`Header`] reference. See [`Encoding::headers`].
pub fn header_ref<S: Into<String>>(mut self, header_name: S, header: Ref) -> Self {
self.headers.insert(header_name.into(), RefOr::Ref(header));
self
}
/// Set the style [`ParameterStyle`]. See [`Encoding::style`].
pub fn style(mut self, style: Option<ParameterStyle>) -> Self {
set_value!(self style style)
}
/// Set the explode. See [`Encoding::explode`].
pub fn explode(mut self, explode: Option<bool>) -> Self {
set_value!(self explode explode)
}
/// Set the allow reserved. See [`Encoding::allow_reserved`].
pub fn allow_reserved(mut self, allow_reserved: Option<bool>) -> Self {
set_value!(self allow_reserved allow_reserved)
}
/// Add nested encoding information for an object property.
pub fn encoding<S: Into<String>, E: Into<Encoding>>(
mut self,
property_name: S,
encoding: E,
) -> Self {
self.encoding.insert(property_name.into(), encoding.into());
self
}
/// Add nested encoding information for tuple-like array items.
pub fn prefix_encoding<I: IntoIterator<Item = E>, E: Into<Encoding>>(
mut self,
prefix_encoding: I,
) -> Self {
set_value!(self prefix_encoding prefix_encoding.into_iter().map(Into::into).collect())
}
/// Add nested encoding information for each array item.
pub fn item_encoding<E: Into<Encoding>>(mut self, item_encoding: Option<E>) -> Self {
set_value!(self item_encoding item_encoding.map(|encoding| Box::new(encoding.into())))
}
/// Add openapi extensions (x-something) of the API.
pub fn extensions(mut self, extensions: Option<Extensions>) -> Self {
set_value!(self extensions extensions)
}
}