kynos_openapi/model/body/
encoding.rs1use serde::{Deserialize, Serialize};
4
5use crate::{
6 Map,
7 model::{
8 extensions::Extensions,
9 parameter::{header::Header, style::EncodingStyle},
10 reference::RefOr,
11 },
12};
13
14#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
16pub struct Encoding {
17 #[serde(
19 rename = "contentType",
20 default,
21 skip_serializing_if = "Option::is_none"
22 )]
23 pub content_type: Option<String>,
24
25 #[serde(default, skip_serializing_if = "Map::is_empty")]
30 pub headers: Map<RefOr<Header>>,
31
32 #[serde(default, skip_serializing_if = "Option::is_none")]
37 pub style: Option<EncodingStyle>,
38
39 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub explode: Option<bool>,
42
43 #[serde(
45 rename = "allowReserved",
46 default,
47 skip_serializing_if = "Option::is_none"
48 )]
49 pub allow_reserved: Option<bool>,
50
51 #[cfg(feature = "openapi32")]
55 #[serde(default, skip_serializing_if = "Map::is_empty")]
56 pub encoding: Map<Encoding>,
57
58 #[cfg(feature = "openapi32")]
62 #[serde(
63 rename = "prefixEncoding",
64 default,
65 skip_serializing_if = "Option::is_none"
66 )]
67 pub prefix_encoding: Option<Vec<Encoding>>,
68
69 #[cfg(feature = "openapi32")]
73 #[serde(
74 rename = "itemEncoding",
75 default,
76 skip_serializing_if = "Option::is_none"
77 )]
78 pub item_encoding: Option<Box<Encoding>>,
79
80 #[serde(flatten)]
82 pub extensions: Extensions,
83}
84
85impl Encoding {
86 pub fn new(content_type: impl Into<String>) -> Self {
88 Self {
89 content_type: Some(content_type.into()),
90 ..Self::default()
91 }
92 }
93
94 #[must_use]
96 pub fn with_header(mut self, name: impl Into<String>, header: Header) -> Self {
97 self.headers.insert(name.into(), RefOr::Item(header));
98 self
99 }
100}