openapiv3_1/encoding.rs
1//! Implements encoding object for content.
2
3use indexmap::IndexMap;
4
5use super::Header;
6use super::extensions::Extensions;
7use super::path::ParameterStyle;
8
9/// A single encoding definition applied to a single schema [`Object
10/// property`](crate::schema::Object::properties).
11#[derive(serde_derive::Serialize, serde_derive::Deserialize, Default, Clone, PartialEq, bon::Builder)]
12#[cfg_attr(feature = "debug", derive(Debug))]
13#[serde(rename_all = "camelCase")]
14#[non_exhaustive]
15pub struct Encoding {
16 /// The Content-Type for encoding a specific property. Default value depends on the property
17 /// type: for string with format being binary – `application/octet-stream`; for other primitive
18 /// types – `text/plain`; for object - `application/json`; for array – the default is defined
19 /// based on the inner type. The value can be a specific media type (e.g. `application/json`),
20 /// a wildcard media type (e.g. `image/*`), or a comma-separated list of the two types.
21 #[serde(skip_serializing_if = "Option::is_none", default)]
22 pub content_type: Option<String>,
23
24 /// A map allowing additional information to be provided as headers, for example
25 /// Content-Disposition. Content-Type is described separately and SHALL be ignored in this
26 /// section. This property SHALL be ignored if the request body media type is not a multipart.
27 #[serde(skip_serializing_if = "IndexMap::is_empty", default)]
28 #[builder(default)]
29 pub headers: IndexMap<String, Header>,
30
31 /// Describes how a specific property value will be serialized depending on its type. See
32 /// Parameter Object for details on the style property. The behavior follows the same values as
33 /// query parameters, including default values. This property SHALL be ignored if the request
34 /// body media type is not `application/x-www-form-urlencoded`.
35 #[serde(skip_serializing_if = "Option::is_none", default)]
36 pub style: Option<ParameterStyle>,
37
38 /// When this is true, property values of type array or object generate separate parameters for
39 /// each value of the array, or key-value-pair of the map. For other types of properties this
40 /// property has no effect. When style is form, the default value is true. For all other
41 /// styles, the default value is false. This property SHALL be ignored if the request body
42 /// media type is not `application/x-www-form-urlencoded`.
43 #[serde(skip_serializing_if = "Option::is_none", default)]
44 pub explode: Option<bool>,
45
46 /// Determines whether the parameter value SHOULD allow reserved characters, as defined by
47 /// RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is
48 /// false. This property SHALL be ignored if the request body media type is not
49 /// `application/x-www-form-urlencoded`.
50 #[serde(skip_serializing_if = "Option::is_none", default)]
51 pub allow_reserved: Option<bool>,
52
53 /// Optional extensions "x-something".
54 #[serde(skip_serializing_if = "Option::is_none", default, flatten)]
55 pub extensions: Option<Extensions>,
56}
57
58impl<S: encoding_builder::IsComplete> From<EncodingBuilder<S>> for Encoding {
59 fn from(builder: EncodingBuilder<S>) -> Self {
60 builder.build()
61 }
62}