apistos_models/paths.rs
1use crate::reference_or::ReferenceOr;
2use crate::security::SecurityRequirement;
3use crate::server::Server;
4use indexmap::IndexMap;
5use schemars::schema::Schema;
6use serde::Serialize;
7use serde_json::Value;
8use std::collections::BTreeMap;
9
10#[derive(Serialize, Clone, Debug, Default)]
11#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
12#[serde(rename_all = "camelCase")]
13pub struct Paths {
14  #[serde(flatten)]
15  pub paths: IndexMap<String, PathItem>,
16  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
17  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
18  pub extensions: IndexMap<String, Value>,
19}
20
21/// Describes the operations available on a single path. A Path Item MAY be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-filtering). The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.
22#[derive(Serialize, Clone, Debug, Default)]
23#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
24#[serde(rename_all = "camelCase")]
25pub struct PathItem {
26  /// An optional, string summary, intended to apply to all operations in this path.
27  #[serde(skip_serializing_if = "Option::is_none")]
28  pub summary: Option<String>,
29  /// An optional, string description, intended to apply to all operations in this path. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
30  #[serde(skip_serializing_if = "Option::is_none")]
31  pub description: Option<String>,
32  #[serde(flatten)]
33  pub operations: IndexMap<OperationType, Operation>,
34  /// An alternative `server` array to service all operations in this path.
35  #[serde(skip_serializing_if = "Vec::is_empty", default)]
36  pub server: Vec<Server>,
37  /// A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsParameters).
38  #[serde(skip_serializing_if = "Vec::is_empty", default)]
39  pub parameters: Vec<ReferenceOr<Parameter>>,
40  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
41  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
42  pub extensions: IndexMap<String, Value>,
43}
44
45#[derive(Serialize, Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
46#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize))]
47#[serde(rename_all = "lowercase")]
48pub enum OperationType {
49  /// A definition of a GET operation on this path.
50  Get,
51  /// A definition of a PUT operation on this path.
52  Put,
53  /// A definition of a POST operation on this path.
54  Post,
55  /// A definition of a DELETE operation on this path.
56  Delete,
57  /// A definition of a OPTIONS operation on this path.
58  Options,
59  /// A definition of a HEAD operation on this path.
60  Head,
61  /// A definition of a PATCH operation on this path.
62  Patch,
63  /// A definition of a TRACE operation on this path.
64  Trace,
65}
66
67/// Describes a single API operation on a path.
68#[derive(Serialize, Clone, Debug, Default)]
69#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
70#[serde(rename_all = "camelCase")]
71pub struct Operation {
72  /// A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.
73  #[serde(skip_serializing_if = "Vec::is_empty", default)]
74  pub tags: Vec<String>,
75  /// A short summary of what the operation does.
76  #[serde(skip_serializing_if = "Option::is_none")]
77  pub summary: Option<String>,
78  /// A verbose explanation of the operation behavior. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
79  #[serde(skip_serializing_if = "Option::is_none")]
80  pub description: Option<String>,
81  /// Additional external documentation for this operation.
82  #[serde(skip_serializing_if = "Option::is_none")]
83  pub external_docs: Option<ExternalDocumentation>,
84  /// Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
85  #[serde(skip_serializing_if = "Option::is_none")]
86  pub operation_id: Option<String>,
87  /// A list of parameters that are applicable for this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemParameters), the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object) to link to parameters that are defined at the [OpenAPI Object's components/parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsParameters).
88  #[serde(skip_serializing_if = "Vec::is_empty", default)]
89  pub parameters: Vec<ReferenceOr<Parameter>>,
90  /// The request body applicable for this operation. The `requestBody` is only supported in HTTP methods where the HTTP 1.1 specification [RFC7231](https://datatracker.ietf.org/doc/html/rfc7231#section-4.3.1) has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague, `requestBody` SHALL be ignored by consumers.
91  #[serde(skip_serializing_if = "Option::is_none")]
92  pub request_body: Option<ReferenceOr<RequestBody>>,
93  /// The list of possible responses as they are returned from executing this operation.
94  pub responses: Responses,
95  /// A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object). Each value in the map is a Callback Object that describes a request that may be initiated by the API provider and the expected responses.
96  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
97  pub callbacks: BTreeMap<String, ReferenceOr<Callback>>,
98  /// Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.
99  #[serde(skip_serializing_if = "Option::is_none")]
100  pub deprecated: Option<bool>,
101  /// A declaration of which security mechanisms can be used for this operation. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. To make security optional, an empty security requirement (`{}`) can be included in the array. This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasSecurity). To remove a top-level security declaration, an empty array can be used.
102  #[serde(skip_serializing_if = "Vec::is_empty", default)]
103  pub security: Vec<SecurityRequirement>,
104  /// An alternative `server` array to service this operation. If an alternative `server` object is specified at the Path Item Object or Root level, it will be overridden by this value.
105  #[serde(skip_serializing_if = "Vec::is_empty", default)]
106  pub servers: Vec<Server>,
107  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
108  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
109  pub extensions: IndexMap<String, Value>,
110}
111
112/// Allows referencing an external resource for extended documentation.
113#[derive(Serialize, Clone, Debug, Default)]
114#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
115#[serde(rename_all = "camelCase")]
116pub struct ExternalDocumentation {
117  /// A short description of the target documentation. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
118  #[serde(skip_serializing_if = "Option::is_none")]
119  pub description: Option<String>,
120  /// The URL for the target documentation. Value MUST be in the format of a URL.
121  pub url: String,
122  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
123  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
124  pub extensions: IndexMap<String, Value>,
125}
126
127/// Describes a single operation parameter.
128/// A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn).
129/// Parameter Locations
130/// # There are four possible parameter locations specified by the in field:
131///
132/// - path - Used together with [Path Templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-templating), where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
133/// - query - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
134/// - header - Custom headers that are expected as part of the request. Note that [RFC7230](https://datatracker.ietf.org/doc/html/rfc7230#page-22) states header names are case insensitive.
135/// - cookie - Used to pass a specific cookie value to the API.
136#[derive(Serialize, Clone, Debug, Default)]
137#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
138#[serde(rename_all = "camelCase")]
139pub struct Parameter {
140  /// The name of the parameter. Parameter names are case sensitive.
141  /// - If [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) is `"path"`, the `name` field MUST correspond to a template expression occurring within the [path](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathsPath) field in the [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object). See [Path Templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-templating) for further information.
142  /// - If [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) is `"header"` and the `name` field is `"Accept"`, `"Content-Type"` or `"Authorization"`, the parameter definition SHALL be ignored.
143  /// - For all other cases, the `name` corresponds to the parameter name used by the [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) property.
144  pub name: String,
145  /// The location of the parameter. Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
146  #[serde(rename = "in")]
147  pub _in: ParameterIn,
148  /// A brief description of the parameter. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
149  #[serde(skip_serializing_if = "Option::is_none")]
150  pub description: Option<String>,
151  /// Determines whether this parameter is mandatory. If the [parameter location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) is `"path"`, this property is **REQUIRED** and its value MUST be `true`. Otherwise, the property MAY be included and its default value is `false`.
152  #[serde(skip_serializing_if = "Option::is_none")]
153  pub required: Option<bool>,
154  /// Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is `false`.
155  #[serde(skip_serializing_if = "Option::is_none")]
156  pub deprecated: Option<bool>,
157  /// 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`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.
158  #[serde(skip_serializing_if = "Option::is_none")]
159  pub allow_empty_value: Option<bool>,
160  /// 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`.
161  #[serde(skip_serializing_if = "Option::is_none")]
162  pub style: Option<ParameterStyle>,
163  /// When this is true, parameter 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 parameters this property has no effect. When [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) is `form`, the default value is `true`. For all other styles, the default value is `false`.
164  #[serde(skip_serializing_if = "Option::is_none")]
165  pub explode: Option<bool>,
166  /// Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2) `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. This property only applies to parameters with an `in` value of `query`. The default value is `false`.
167  #[serde(skip_serializing_if = "Option::is_none")]
168  pub allow_reserved: Option<bool>,
169  #[serde(flatten, skip_serializing_if = "Option::is_none")]
170  pub definition: Option<ParameterDefinition>,
171  #[serde(flatten, skip_serializing_if = "Option::is_none")]
172  pub example: Option<Examples>,
173  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
174  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
175  pub extensions: IndexMap<String, Value>,
176}
177
178#[derive(Serialize, Clone, Debug)]
179#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
180#[serde(rename_all = "lowercase")]
181pub enum ParameterDefinition {
182  /// The schema defining the type used for the parameter.
183  Schema(ReferenceOr<Schema>),
184  /// 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.
185  Content(BTreeMap<String, MediaType>),
186}
187
188/// Each Media Type Object provides schema and examples for the media type identified by its key.
189#[derive(Serialize, Clone, Debug, Default)]
190#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
191#[serde(rename_all = "camelCase")]
192pub struct MediaType {
193  /// The schema defining the content of the request, response, or parameter.
194  #[serde(skip_serializing_if = "Option::is_none")]
195  pub schema: Option<ReferenceOr<Schema>>,
196  #[serde(flatten)]
197  #[serde(skip_serializing_if = "Option::is_none")]
198  pub example: Option<Examples>,
199  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
200  pub encoding: BTreeMap<String, Encoding>,
201  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
202  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
203  pub extensions: IndexMap<String, Value>,
204}
205
206/// A single encoding definition applied to a single schema property.
207#[derive(Serialize, Clone, Debug, Default)]
208#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
209#[serde(rename_all = "camelCase")]
210pub struct Encoding {
211  /// 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.
212  #[serde(skip_serializing_if = "Option::is_none")]
213  pub content_type: Option<String>,
214  /// 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`.
215  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
216  pub headers: BTreeMap<String, ReferenceOr<Header>>,
217  /// Describes how a specific property value will be serialized depending on its type. See [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object) for details on the [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) 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`.
218  #[serde(skip_serializing_if = "Option::is_none")]
219  pub style: Option<ParameterStyle>,
220  /// 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`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) 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`.
221  #[serde(skip_serializing_if = "Option::is_none")]
222  pub explode: Option<bool>,
223  /// Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2) `:/?#[]@!$&'()*+,;=` 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`.
224  #[serde(skip_serializing_if = "Option::is_none")]
225  pub allow_reserved: Option<bool>,
226  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
227  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
228  pub extensions: IndexMap<String, Value>,
229}
230
231/// The Header Object follows the structure of the [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object) with the following changes:
232///
233/// 1. `name` MUST NOT be specified, it is given in the corresponding `headers` map.
234/// 2. `in` MUST NOT be specified, it is implicitly in header.
235/// 3. All traits that are affected by the location MUST be applicable to a location of `header` (for example, [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle)).
236#[derive(Serialize, Clone, Debug, Default)]
237#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
238#[serde(rename_all = "camelCase")]
239pub struct Header {
240  /// Determines whether this parameter is mandatory. If the [parameter location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) is `"path"`, this property is **REQUIRED** and its value MUST be `true`. Otherwise, the property MAY be included and its default value is `false`.
241  #[serde(skip_serializing_if = "Option::is_none")]
242  pub required: Option<bool>,
243  /// Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is `false`.
244  #[serde(skip_serializing_if = "Option::is_none")]
245  pub deprecated: Option<bool>,
246  /// A brief description of the parameter. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
247  #[serde(skip_serializing_if = "Option::is_none")]
248  pub description: Option<String>,
249  #[serde(flatten, skip_serializing_if = "Option::is_none")]
250  pub definition: Option<ParameterDefinition>,
251  /// 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`.
252  #[serde(skip_serializing_if = "Option::is_none")]
253  pub style: Option<ParameterStyle>,
254}
255
256#[derive(Serialize, Clone, Debug, Eq, PartialEq)]
257#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize))]
258#[serde(rename_all = "lowercase")]
259pub enum ParameterIn {
260  Query,
261  Header,
262  Path,
263  Cookie,
264}
265
266impl Default for ParameterIn {
267  fn default() -> Self {
268    Self::Path
269  }
270}
271
272#[derive(Serialize, Clone, Debug)]
273#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
274#[serde(rename_all = "camelCase")]
275pub enum ParameterStyle {
276  /// Path-style parameters defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.7)
277  Matrix,
278  /// Label style parameters defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.5)
279  Label,
280  /// Form style parameters defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.8). This option replaces `collecztionFormat` with a `csv` (when `explode` is false) or `multi` (when `explode` is true) value from OpenAPI 2.0.
281  Form,
282  /// Simple style parameters defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.2). This option replaces `collectionFormat` with a `csv` value from OpenAPI 2.0.
283  Simple,
284  /// Space separated array values. This option replaces `collectionFormat` equal to `ssv` from OpenAPI 2.0.
285  SpaceDelimited,
286  /// Pipe separated array values. This option replaces `collectionFormat` equal to `pipes` from OpenAPI 2.0.
287  PipeDelimited,
288  /// Provides a simple way of rendering nested objects using form parameters.
289  DeepObject,
290}
291
292#[derive(Serialize, Clone, Debug)]
293#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
294#[serde(rename_all = "camelCase")]
295pub enum Examples {
296  /// Example of the parameter's potential value. The example SHOULD match the specified schema and encoding properties if present. The `example` field is mutually exclusive of the `examples` field. Furthermore, if referencing a `schema` that contains an example, the example value SHALL override the example provided by the schema. To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.
297  Example(Value),
298  /// Examples of the parameter's potential value. Each example SHOULD contain a value in the correct format as specified in the parameter encoding. The `examples` field is mutually exclusive of the `example` field. Furthermore, if referencing a `schema` that contains an example, the examples value SHALL override the `example` provided by the schema.
299  Examples(BTreeMap<String, ReferenceOr<Example>>),
300}
301
302#[derive(Serialize, Clone, Debug)]
303#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
304#[serde(rename_all = "camelCase")]
305pub struct Example {
306  /// Short description for the example.
307  #[serde(skip_serializing_if = "Option::is_none")]
308  pub summary: Option<String>,
309  /// Long description for the example. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
310  #[serde(skip_serializing_if = "Option::is_none")]
311  pub description: Option<String>,
312  /// Embedded literal example. The `value` field and `externalValue` field are mutually exclusive. To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary.
313  #[serde(flatten)]
314  pub value: ExampleValue,
315  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
316  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
317  pub extensions: IndexMap<String, Value>,
318}
319
320#[derive(Serialize, Clone, Debug)]
321#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
322#[serde(rename_all = "camelCase")]
323pub enum ExampleValue {
324  /// Embedded literal example. The `value` field and `externalValue` field are mutually exclusive. To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary.
325  Value(Value),
326  /// A URL that points to the literal example. This provides the capability to reference examples that cannot easily be included in JSON or YAML documents. The `value` field and `externalValue` field are mutually exclusive.
327  ExternalValue(String),
328}
329
330/// Describes a single request body.
331#[derive(Serialize, Clone, Debug, Default)]
332#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
333#[serde(rename_all = "camelCase")]
334pub struct RequestBody {
335  /// A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
336  #[serde(skip_serializing_if = "Option::is_none")]
337  pub description: Option<String>,
338  /// The content of the request body. The key is a media type or [media type range](https://datatracker.ietf.org/doc/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
339  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
340  pub content: BTreeMap<String, MediaType>,
341  /// Determines if the request body is required in the request. Defaults to `false`.
342  #[serde(skip_serializing_if = "Option::is_none")]
343  pub required: Option<bool>,
344  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
345  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
346  pub extensions: IndexMap<String, Value>,
347}
348
349/// A container for the expected responses of an operation. The container maps a HTTP response code to the expected response.
350///
351/// The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance. However, documentation is expected to cover a successful operation response and any known errors.
352///
353/// The `default` MAY be used as a default response object for all HTTP codes that are not covered individually by the specification.
354///
355/// The `Responses Object` MUST contain at least one response code, and it SHOULD be the response for a successful operation call.
356#[derive(Serialize, Clone, Debug, Default)]
357#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
358#[serde(rename_all = "camelCase")]
359pub struct Responses {
360  /// The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses. A [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object) can link to a response that the [OpenAPI Object's components/responses](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsResponses) section defines.
361  #[serde(skip_serializing_if = "Option::is_none")]
362  pub default: Option<ReferenceOr<Response>>,
363  #[serde(flatten, skip_serializing_if = "BTreeMap::is_empty")]
364  pub responses: BTreeMap<String, ReferenceOr<Response>>,
365  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
366  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
367  pub extensions: IndexMap<String, Value>,
368}
369
370/// Describes a single response from an API Operation, including design-time, static `links` to operations based on the response.
371#[derive(Serialize, Clone, Debug, Default)]
372#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
373#[serde(rename_all = "camelCase")]
374pub struct Response {
375  /// A short description of the response. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
376  pub description: String,
377  /// Maps a header name to its definition. [RFC7230](https://datatracker.ietf.org/doc/html/rfc7230#page-22) states header names are case insensitive. If a response header is defined with the name `"Content-Type"`, it SHALL be ignored.
378  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
379  pub headers: BTreeMap<String, ReferenceOr<Header>>,
380
381  /// A map containing descriptions of potential response payloads. The key is a media type or [media type range](https://datatracker.ietf.org/doc/html/rfc7231#appendix-D) and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
382  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
383  pub content: BTreeMap<String, MediaType>,
384  /// A map of operations links that can be followed from the response. The key of the map is a short name for the link, following the naming constraints of the names for [Component Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object).
385  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
386  pub links: BTreeMap<String, ReferenceOr<Link>>,
387  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
388  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
389  pub extensions: IndexMap<String, Value>,
390}
391
392/// The `Link object` represents a possible design-time link for a response. The presence of a link does not guarantee the caller's ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.
393///
394/// Unlike dynamic links (i.e. links provided in the response payload), the OAS linking mechanism does not require link information in the runtime response.
395///
396/// For computing links, and providing instructions to execute them, a [runtime expression](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#runtime-expressions) is used for accessing values in an operation and using them as parameters while invoking the linked operation.
397#[derive(Serialize, Clone, Debug, Default)]
398#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
399#[serde(rename_all = "camelCase")]
400pub struct Link {
401  #[serde(flatten, skip_serializing_if = "Option::is_none")]
402  pub operation_identifier: Option<OperationIdentifier>,
403  /// A map representing parameters to pass to an operation as specified with `operationId` or identified via `operationRef`. The key is the parameter name to be used, whereas the value can be a constant or an expression to be evaluated and passed to the linked operation. The parameter name can be qualified using the [parameter location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterIn) `[{in}.]{name}` for operations that use the same parameter name in different locations (e.g. path.id).
404  #[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
405  pub parameters: BTreeMap<String, AnyOrExpression>,
406  /// A literal value or [{expression}](/https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#runtime-expressions) to use as a request body when calling the target operation.
407  #[serde(skip_serializing_if = "Option::is_none")]
408  pub request_body: Option<AnyOrExpression>,
409  /// A description of the link. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
410  #[serde(skip_serializing_if = "Option::is_none")]
411  pub description: Option<String>,
412  /// A server object to be used by the target operation.
413  #[serde(skip_serializing_if = "Option::is_none")]
414  pub server: Option<Server>,
415  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
416  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
417  pub extensions: IndexMap<String, Value>,
418}
419
420/// A map of possible out-of band callbacks related to the parent operation. Each value in the map is a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object) that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
421#[derive(Serialize, Clone, Debug, Default)]
422#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
423#[serde(rename_all = "camelCase")]
424pub struct Callback {
425  /// A Path Item Object used to define a callback request and expected responses. A [complete example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/callback-example.yaml) is available.
426  #[serde(flatten, skip_serializing_if = "BTreeMap::is_empty")]
427  pub callbacks: BTreeMap<String, PathItem>,
428  /// This object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions).
429  #[serde(flatten, skip_serializing_if = "IndexMap::is_empty", skip_deserializing)]
430  pub extensions: IndexMap<String, Value>,
431}
432
433#[derive(Serialize, Clone, Debug)]
434#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
435#[serde(untagged)]
436pub enum AnyOrExpression {
437  Any(Value),
438  /// [{expression}](/https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#runtime-expressions)
439  Expression(String),
440}
441
442#[derive(Serialize, Clone, Debug)]
443#[cfg_attr(any(test, feature = "deserialize"), derive(serde::Deserialize, PartialEq))]
444#[serde(rename_all = "camelCase")]
445pub enum OperationIdentifier {
446  /// A relative or absolute URI reference to an OAS operation. This field is mutually exclusive of the `operationId` field, and MUST point to an [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object). Relative `operationRef` values MAY be used to locate an existing [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object) in the OpenAPI definition.
447  OperationRef(String),
448  /// The name of an existing, resolvable OAS operation, as defined with a unique `operationId`. This field is mutually exclusive of the `operationRef` field.
449  OperationId(String),
450}