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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
use crate::*;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
/// Describes a single operation parameter.
///
/// A unique parameter is defined by a combination of a name and location.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ParameterData {
/// REQUIRED. The name of the parameter. Parameter names are case sensitive.
/// If in is "path", the name field MUST correspond to the associated path
/// segment from the path field in the Paths Object. See Path Templating for
/// further information.
///
/// If in is "header" and the name field is "Accept", "Content-Type" or
/// "Authorization", the parameter definition SHALL be ignored.
///
/// For all other cases, the name corresponds to the parameter name
/// used by the in property.
pub name: String,
/// A brief description of the parameter. This could
/// contain examples of use. CommonMark syntax MAY be
/// used for rich text representation.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Determines whether this parameter is mandatory.
/// If the parameter location is "path", this property
/// is REQUIRED and its value MUST be true. Otherwise,
/// the property MAY be included and its default value
/// is false.
#[serde(default, skip_serializing_if = "is_false")]
pub required: bool,
/// Specifies that a parameter is deprecated and SHOULD
/// be transitioned out of usage.
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
#[serde(flatten)]
pub format: ParameterSchemaOrContent,
#[serde(skip_serializing_if = "Option::is_none")]
pub example: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub examples: IndexMap<String, ReferenceOr<Example>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub explode: Option<bool>,
/// Inline extensions to this object.
#[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
pub extensions: IndexMap<String, serde_json::Value>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum ParameterSchemaOrContent {
/// The schema defining the type used for the parameter.
Schema(ReferenceOr<Schema>),
/// A map containing the representations for the parameter. The key is the
/// media type and the value describes it. The map MUST only contain one
/// entry.
Content(Content),
}
pub type Content = IndexMap<String, MediaType>;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "in", rename_all = "camelCase")]
pub enum Parameter {
#[serde(rename_all = "camelCase")]
Query {
#[serde(flatten)]
parameter_data: ParameterData,
/// Determines whether the parameter value SHOULD allow reserved
/// characters, as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included
/// without percent-encoding. This property only applies to parameters
/// with an in value of query. The default value is false.
#[serde(default, skip_serializing_if = "is_false")]
allow_reserved: bool,
/// Describes how the parameter value will be serialized depending on
/// the type of the parameter value. Default values (based on value of
/// in): for query - form; for path - simple; for header - simple; for
/// cookie - form.
#[serde(default, skip_serializing_if = "SkipSerializeIfDefault::skip")]
style: QueryStyle,
/// Sets the ability to pass empty-valued parameters. This is
/// valid only for query parameters and allows sending a parameter
/// with an empty value. Default value is false. If style is used,
/// and if behavior is n/a (cannot be serialized), the value of
/// allowEmptyValue SHALL be ignored.
#[serde(skip_serializing_if = "Option::is_none")]
allow_empty_value: Option<bool>,
},
Header {
#[serde(flatten)]
parameter_data: ParameterData,
/// Describes how the parameter value will be serialized depending on
/// the type of the parameter value. Default values (based on value of
/// in): for query - form; for path - simple; for header - simple; for
/// cookie - form.
#[serde(default, skip_serializing_if = "SkipSerializeIfDefault::skip")]
style: HeaderStyle,
},
Path {
#[serde(flatten)]
parameter_data: ParameterData,
/// Describes how the parameter value will be serialized depending on
/// the type of the parameter value. Default values (based on value of
/// in): for query - form; for path - simple; for header - simple; for
/// cookie - form.
#[serde(default, skip_serializing_if = "SkipSerializeIfDefault::skip")]
style: PathStyle,
},
Cookie {
#[serde(flatten)]
parameter_data: ParameterData,
/// Describes how the parameter value will be serialized depending on
/// the type of the parameter value. Default values (based on value of
/// in): for query - form; for path - simple; for header - simple; for
/// cookie - form.
#[serde(default, skip_serializing_if = "SkipSerializeIfDefault::skip")]
style: CookieStyle,
},
}
impl Parameter {
/// Returns the `parameter_data` field of this [ParameterData].
pub fn parameter_data(self) -> ParameterData {
match self {
Parameter::Query {
parameter_data,
allow_reserved: _,
style: _,
allow_empty_value: _,
} => parameter_data,
Parameter::Header {
parameter_data,
style: _,
} => parameter_data,
Parameter::Path {
parameter_data,
style: _,
} => parameter_data,
Parameter::Cookie {
parameter_data,
style: _,
} => parameter_data,
}
}
/// Returns the `parameter_data` field of this [ParameterData] by reference.
pub fn parameter_data_ref(&self) -> &ParameterData {
match self {
Parameter::Query {
parameter_data,
allow_reserved: _,
style: _,
allow_empty_value: _,
} => parameter_data,
Parameter::Header {
parameter_data,
style: _,
} => parameter_data,
Parameter::Path {
parameter_data,
style: _,
} => parameter_data,
Parameter::Cookie {
parameter_data,
style: _,
} => parameter_data,
}
}
}
struct SkipSerializeIfDefault;
impl SkipSerializeIfDefault {
#[cfg(feature = "skip_serializing_defaults")]
fn skip<D: Default + std::cmp::PartialEq>(value: &D) -> bool {
value == &Default::default()
}
#[cfg(not(feature = "skip_serializing_defaults"))]
fn skip<D: Default + std::cmp::PartialEq>(_value: &D) -> bool {
false
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum PathStyle {
Matrix,
Label,
Simple,
}
impl Default for PathStyle {
fn default() -> Self {
PathStyle::Simple
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum QueryStyle {
Form,
SpaceDelimited,
PipeDelimited,
DeepObject,
}
impl Default for QueryStyle {
fn default() -> Self {
QueryStyle::Form
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum CookieStyle {
Form,
}
impl Default for CookieStyle {
fn default() -> CookieStyle {
CookieStyle::Form
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum HeaderStyle {
Simple,
}
impl Default for HeaderStyle {
fn default() -> HeaderStyle {
HeaderStyle::Simple
}
}