openapi_schema/v2/
schema.rs

1use crate::extension::Extensions;
2use serde::{Deserialize, Serialize};
3use serde_json::{Number, Value};
4use std::collections::BTreeMap;
5
6/// # Swagger
7///
8/// The Top Level Struct of swagger
9///
10/// Swagger document specification [here](https://swagger.io/specification/v2/)
11///
12/// see https://swagger.io/specification/v2/#swagger-object
13#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
14pub struct Swagger {
15    /// 2.0
16    pub swagger: String,
17    /// Provides metadata about the API. The metadata can be used by the clients if needed.
18    pub info: Info,
19    /// The host (name or ip) serving the API.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub host: Option<String>,
22    /// The base path on which the API is served, which is relative to the host.
23    #[serde(skip_serializing_if = "Option::is_none", rename = "basePath")]
24    pub base_path: Option<String>,
25    /// The transfer protocol of the API.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub schemas: Option<Vec<TransferProtocol>>,
28    /// A list of MIME types the APIs can consume.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub consumes: Option<String>,
31    /// A list of MIME types the APIs can produce.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub produces: Option<String>,
34
35    /// The available paths and operations for the API.
36    pub paths: BTreeMap<String, PathItem>,
37
38    /// An object to hold data types produced and consumed by operations.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub definitions: Option<BTreeMap<String, Schema>>,
41
42    /// An object to hold parameters that can be used across operations. This property does not define global parameters for all operations.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub parameters: Option<BTreeMap<String, Parameter>>,
45
46    /// An object to hold responses that can be used across operations. This property does not define global responses for all operations.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub responses: Option<BTreeMap<String, Response>>,
49
50    /// Security scheme definitions that can be used across the specification.
51    #[serde(
52        skip_serializing_if = "Option::is_none",
53        rename = "securityDefinitions"
54    )]
55    pub security_definitions: Option<BTreeMap<String, SecurityScheme>>,
56
57    /// A declaration of which security schemes are applied for the API as a whole.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub security: Option<Vec<SecurityRequirementObject>>,
60
61    /// A list of tags used by the specification with additional metadata.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub tags: Option<Vec<Tag>>,
64
65    /// Additional external documentation.
66    #[serde(skip_serializing_if = "Option::is_none", rename = "externalDocs")]
67    pub external_docs: Option<ExternalDoc>,
68
69    /// Allows extensions to the Swagger Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be null, a primitive, an array or an object.
70    #[serde(flatten)]
71    pub extensions: Extensions,
72}
73
74/// ## Info
75///
76/// The object provides metadata about the API. The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience.
77#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
78pub struct Info {
79    ///  The title of the application.
80    pub title: String,
81    /// A short description of the application.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub description: Option<String>,
84    /// The Terms of Service for the API.
85    #[serde(rename = "termsOfService", skip_serializing_if = "Option::is_none")]
86    pub terms_of_service: Option<String>,
87    /// The contact information for the exposed API.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub contact: Option<Contact>,
90    /// The license information for the exposed API.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub license: Option<License>,
93    /// Provides the version of the application API (not to be confused with the specification version).
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub version: Option<String>,
96    #[serde(flatten)]
97    pub extensions: Extensions,
98}
99
100/// ### Contact
101///
102/// Contact information for the exposed API.
103#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
104pub struct Contact {
105    /// The identifying name of the contact person/organization.
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub name: Option<String>,
108    /// The URL pointing to the contact information. MUST be in the format of a URL.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub url: Option<String>,
111    /// The email address of the contact person/organization. MUST be in the format of an email address.
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub email: Option<String>,
114    #[serde(flatten)]
115    pub extensions: Extensions,
116}
117
118/// ### License
119///
120/// License information for the exposed API.
121#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
122pub struct License {
123    /// The license name used for the API.
124    pub name: String,
125    /// A URL to the license used for the API. MUST be in the format of a URL.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub url: Option<String>,
128    #[serde(flatten)]
129    pub extensions: Extensions,
130}
131
132/// ### TransferProtocol
133///
134/// A list of protocol
135#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
136#[serde(rename_all = "lowercase")]
137pub enum TransferProtocol {
138    #[default]
139    Http,
140    Https,
141    Ws,
142    Wss,
143}
144
145/// ### ExternalDoc
146///
147/// Allows referencing an external resource for extended documentation.
148#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
149pub struct ExternalDoc {
150    /// A short description of the target documentation.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub description: Option<String>,
153    /// The URL for the target documentation.
154    pub url: String,
155}
156
157/// ### Tag
158///
159/// Allows adding meta data to a single tag that is used by the Operation Object.
160///
161/// It is not mandatory to have a Tag Object per tag used there.
162#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
163pub struct Tag {
164    /// The name of the tag
165    pub name: String,
166    /// A short description for the tag.
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub description: Option<String>,
169    /// Additional external documentation for this tag.
170    #[serde(skip_serializing_if = "Option::is_none", rename = "externalDoc")]
171    pub external_doc: Option<ExternalDoc>,
172}
173
174#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
175#[serde(rename_all = "lowercase")]
176pub enum InEnum {
177    Query,
178    Header,
179}
180
181#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
182#[serde(rename_all = "lowercase")]
183pub enum Flow {
184    Implicit,
185    Password,
186    Application,
187    AccessCode,
188}
189
190#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
191#[serde(rename_all = "lowercase")]
192pub enum Scopes {
193    Implicit,
194    Password,
195    Application,
196    AccessCode,
197}
198
199#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
200#[serde(rename_all = "lowercase")]
201pub enum AuthorizationUrl {
202    Implicit,
203    AccessCode,
204}
205/// ### SecuritySchemeType
206///
207/// The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
208#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
209#[serde(rename_all = "camelCase")]
210pub enum SecuritySchemeType {
211    Basic,
212    ApiKey,
213    Oauth2,
214}
215
216/// ### TokenUrl
217///
218///  The token URL to be used for this flow.
219#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
220#[serde(rename_all = "camelCase")]
221pub enum TokenUrl {
222    Password,
223    Application,
224    AccessCode,
225}
226/// ## SecurityScheme
227///
228/// A declaration of the security schemes available to be used in the specification.
229///
230/// This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme.
231#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
232pub struct SecurityScheme {
233    /// The type of the security scheme. Valid values are `"basic"`, `"apiKey"` or `"oauth2"`.
234    pub r#type: SecuritySchemeType,
235    /// A short description for security scheme.
236    #[serde(skip_serializing_if = "Option::is_none")]
237    pub description: Option<String>,
238    /// The name of the header or query parameter to be used.
239    pub name: String,
240    /// The location of the API key. Valid values are `"query"` or `"header"`.
241    pub r#in: InEnum,
242    /// The flow used by the OAuth2 security scheme. Valid values are `"implicit"`,`"password"`,`"application"` or `"accessCode"`.
243    pub flow: Option<Flow>,
244    /// The authorization URL to be used for this flow. This SHOULD be in the form of a URL.
245    #[serde(rename = "authorizationUrl", skip_serializing_if = "Option::is_none")]
246    pub authorization_url: Option<AuthorizationUrl>,
247    /// The token URL to be used for this flow. This SHOULD be in the form of a URL.
248    #[serde(rename = "tokenUrl", skip_serializing_if = "Option::is_none")]
249    pub token_url: Option<TokenUrl>,
250    /// The available scopes for the OAuth2 security scheme.
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub scopes: Option<BTreeMap<String, String>>,
253    /// Allows extensions to the Swagger Schema.
254    #[serde(flatten)]
255    pub extensions: Extensions,
256}
257
258/// ### SecurityRequirementObject
259///
260/// Lists the required security schemes to execute this operation.
261/// The object can have multiple security schemes declared in it which are all required (that is, there is a logical AND between the schemes).
262///
263/// The name used for each property MUST correspond to a security scheme declared in the Security Definitions.
264/// see https://swagger.io/specification/v2/#securityRequirementObject
265#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
266pub struct SecurityRequirementObject(BTreeMap<String, Vec<String>>);
267
268/// ### Path Item
269/// Describes the operations available on a single path.
270/// A Path Item may be empty, due to [ACL constraints](https://swagger.io/specification/v2/#securityFiltering).
271/// The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.
272#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
273pub struct PathItem {
274    /// Allows for an external definition of this path item. The referenced structure MUST be in the format of a Path Item Object.
275    /// If there are conflicts between the referenced definition and this Path Item's definition, the behavior is undefined.
276    #[serde(rename = "$ref", skip_serializing_if = "Option::is_none")]
277    pub reference: Option<String>,
278    /// A definition of a GET operation on this path.
279    #[serde(skip_serializing_if = "Option::is_none")]
280    pub get: Option<Operation>,
281    /// A definition of a GET operation on this path.
282    #[serde(skip_serializing_if = "Option::is_none")]
283    pub put: Option<Operation>,
284    /// A definition of a GET operation on this path.
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub post: Option<Operation>,
287    /// A definition of a GET operation on this path.
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub delete: Option<Operation>,
290    /// A definition of a GET operation on this path.
291    #[serde(skip_serializing_if = "Option::is_none")]
292    pub options: Option<Operation>,
293    /// A definition of a GET operation on this path.
294    #[serde(skip_serializing_if = "Option::is_none")]
295    pub head: Option<Operation>,
296    /// A definition of a GET operation on this path.
297    #[serde(skip_serializing_if = "Option::is_none")]
298    pub patch: Option<Operation>,
299    /// A list of parameters that are applicable for all the operations described under this path.
300    #[serde(skip_serializing_if = "Option::is_none")]
301    pub parameters: Option<Vec<ParameterOrRef>>,
302}
303
304/// ### Operation
305/// Describes a single API operation on a path.
306#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
307pub struct Operation {
308    /// A list of tags for API documentation control.
309    /// Tags can be used for logical grouping of operations by resources or any other qualifier.
310    #[serde(skip_serializing_if = "Option::is_none")]
311    pub tags: Option<Vec<String>>,
312    /// A short summary of what the operation does.
313    #[serde(skip_serializing_if = "Option::is_none")]
314    pub summary: Option<String>,
315    /// A verbose explanation of the operation behavior.
316    #[serde(skip_serializing_if = "Option::is_none")]
317    pub description: Option<String>,
318    /// Additional external documentation for this operation.
319    #[serde(skip_serializing_if = "Option::is_none", rename = "externalDocs")]
320    pub external_docs: Option<ExternalDoc>,
321    /// Unique string used to identify the operation.
322    #[serde(skip_serializing_if = "Option::is_none", rename = "operationId")]
323    pub operation_id: Option<String>,
324    /// A list of MIME types the operation can consume.
325    #[serde(skip_serializing_if = "Option::is_none")]
326    pub consumes: Option<Vec<String>>,
327    /// A list of MIME types the operation can produce.
328    #[serde(skip_serializing_if = "Option::is_none")]
329    pub produces: Option<Vec<String>>,
330    /// A list of parameters that are applicable for this operation.
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub parameters: Option<Vec<ParameterOrRef>>,
333    /// The list of possible responses as they are returned from executing this operation.
334    pub responses: Responses,
335    /// The transfer protocol for the operation.
336    #[serde(skip_serializing_if = "Option::is_none")]
337    pub schemas: Option<TransferProtocol>,
338    /// Declares this operation to be deprecated.
339    #[serde(skip_serializing_if = "Option::is_none")]
340    pub deprecated: Option<String>,
341    /// A declaration of which security schemes are applied for this operation.
342    #[serde(skip_serializing_if = "Option::is_none")]
343    pub security: Option<Vec<SecurityRequirementObject>>,
344    #[serde(flatten)]
345    pub extensions: Extensions,
346}
347
348#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
349#[serde(rename_all = "camelCase")]
350pub enum ParamInEnum {
351    Query,
352    Header,
353    Path,
354    FormData,
355    Body,
356}
357
358#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
359#[serde(untagged)]
360pub enum ParameterOrRef {
361    Ref(Reference),
362    Parameter(Parameter),
363}
364#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
365pub struct Reference {
366    #[serde(rename = "$ref")]
367    pub reference: String,
368}
369
370/// ### Parameter
371///
372/// Describes a single operation parameter. see https://swagger.io/specification/v2/#parameter-object.
373#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
374pub struct Parameter {
375    /// The name of the parameter.
376    pub name: String,
377    /// The location of the parameter. Possible values are "query", "header", "path", "formData" or "body".
378    pub r#in: ParamInEnum,
379    /// A brief description of the parameter.
380    #[serde(skip_serializing_if = "Option::is_none")]
381    pub description: Option<String>,
382    /// Determines whether this parameter is mandatory.
383    /// If the parameter is in "path", this property is **required** and its value MUST be `true`. Otherwise, the property MAY be included and its default value is `false`.
384    #[serde(skip_serializing_if = "Option::is_none")]
385    pub required: Option<bool>,
386    /// The schema defining the type used for the body parameter.
387    /// If the parameter is in "body", this property is **required**
388    #[serde(skip_serializing_if = "Option::is_none")]
389    pub schema: Option<Schema>,
390    /// The type of the parameter. Since the parameter is not located at the request body, it is limited to simple types (that is, not an object).
391    #[serde(skip_serializing_if = "Option::is_none")]
392    pub r#type: Option<ParameterType>,
393    /// The extending format for the previously mentioned type. See [Data Type Formats](https://swagger.io/specification/v2/#dataTypeFormat) for further details.
394    #[serde(skip_serializing_if = "Option::is_none")]
395    pub format: Option<String>,
396    /// Sets the ability to pass empty-valued parameters.
397    #[serde(skip_serializing_if = "Option::is_none", rename = "allowEmptyValue")]
398    pub allow_empty_value: Option<bool>,
399
400    /// **Required if `type` is "array"**. Describes the type of items in the array.
401    #[serde(skip_serializing_if = "Option::is_none")]
402    pub items: Option<Items>,
403    /// Determines the format of the array if type array is used.
404    #[serde(skip_serializing_if = "Option::is_none", rename = "collectionFormat")]
405    pub collection_format: Option<String>,
406
407    /// Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request.
408    /// (Note: "default" has no meaning for required parameters.)
409    #[serde(skip_serializing_if = "Option::is_none")]
410    pub default: Option<Value>,
411    #[serde(skip_serializing_if = "Option::is_none")]
412    pub maximum: Option<Number>,
413    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
414    pub exclusive_maximum: Option<bool>,
415    #[serde(skip_serializing_if = "Option::is_none")]
416    pub minimum: Option<Number>,
417    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
418    pub exclusive_minimum: Option<bool>,
419    #[serde(skip_serializing_if = "Option::is_none", rename = "maxLength")]
420    pub max_length: Option<Number>,
421    #[serde(skip_serializing_if = "Option::is_none", rename = "minLength")]
422    pub min_length: Option<Number>,
423    #[serde(skip_serializing_if = "Option::is_none")]
424    pub pattern: Option<String>,
425    #[serde(skip_serializing_if = "Option::is_none", rename = "maxItems")]
426    pub max_items: Option<Number>,
427    #[serde(skip_serializing_if = "Option::is_none", rename = "minItems")]
428    pub min_items: Option<Number>,
429    #[serde(skip_serializing_if = "Option::is_none", rename = "uniqueItems")]
430    pub unique_items: Option<bool>,
431    #[serde(skip_serializing_if = "Option::is_none")]
432    pub r#enum: Option<Vec<Value>>,
433    #[serde(skip_serializing_if = "Option::is_none", rename = "multipleOf")]
434    pub multiple_of: Option<Number>,
435    #[serde(flatten)]
436    pub extensions: Extensions,
437}
438
439/// ### Schema Object
440#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
441pub struct Schema {
442    #[serde(skip_serializing_if = "Option::is_none")]
443    /// [JSON reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)
444    /// path to another defintion
445    #[serde(rename = "$ref")]
446    pub reference: Option<String>,
447    #[serde(skip_serializing_if = "Option::is_none")]
448    #[serde(rename = "originalRef")]
449    pub original_ref: Option<String>,
450    #[serde(skip_serializing_if = "Option::is_none")]
451    pub title: Option<String>,
452    #[serde(skip_serializing_if = "Option::is_none")]
453    pub description: Option<String>,
454    #[serde(skip_serializing_if = "Option::is_none")]
455    #[serde(rename = "type")]
456    pub r#type: Option<String>,
457    #[serde(skip_serializing_if = "Option::is_none")]
458    pub format: Option<String>,
459    #[serde(skip_serializing_if = "Option::is_none")]
460    #[serde(rename = "enum")]
461    pub r#enum: Option<Vec<String>>,
462    #[serde(skip_serializing_if = "Option::is_none")]
463    pub required: Option<Vec<String>>,
464
465    #[serde(skip_serializing_if = "Option::is_none")]
466    pub default: Option<Value>,
467    #[serde(skip_serializing_if = "Option::is_none")]
468    pub maximum: Option<Number>,
469    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
470    pub exclusive_maximum: Option<bool>,
471    #[serde(skip_serializing_if = "Option::is_none")]
472    pub minimum: Option<Number>,
473    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
474    pub exclusive_minimum: Option<bool>,
475    #[serde(skip_serializing_if = "Option::is_none", rename = "maxLength")]
476    pub max_length: Option<Number>,
477    #[serde(skip_serializing_if = "Option::is_none", rename = "minLength")]
478    pub min_length: Option<Number>,
479    #[serde(skip_serializing_if = "Option::is_none")]
480    pub pattern: Option<String>,
481    #[serde(skip_serializing_if = "Option::is_none", rename = "maxItems")]
482    pub max_items: Option<Number>,
483    #[serde(skip_serializing_if = "Option::is_none", rename = "minItems")]
484    pub min_items: Option<Number>,
485    #[serde(skip_serializing_if = "Option::is_none", rename = "uniqueItems")]
486    pub unique_items: Option<bool>,
487    #[serde(skip_serializing_if = "Option::is_none", rename = "multipleOf")]
488    pub multiple_of: Option<Number>,
489    #[serde(skip_serializing_if = "Option::is_none")]
490    pub items: Option<Box<Schema>>,
491    // implies object
492    #[serde(skip_serializing_if = "Option::is_none")]
493    pub properties: Option<BTreeMap<String, Schema>>,
494
495    #[serde(
496        skip_serializing_if = "Option::is_none",
497        rename = "additionalProperties"
498    )]
499    pub additional_properties: Option<Value>,
500
501    /// Adds support for polymorphism.
502    #[serde(skip_serializing_if = "Option::is_none")]
503    pub discriminator: Option<Discriminator>,
504
505    /// Relevant only for Schema "properties" definitions.
506    #[serde(skip_serializing_if = "Option::is_none", rename = "readOnly")]
507    pub read_only: Option<bool>,
508    /// This MAY be used only on properties schemas.
509    #[serde(skip_serializing_if = "Option::is_none")]
510    pub xml: Option<XML>,
511    /// Additional external documentation for this schema.
512    #[serde(skip_serializing_if = "Option::is_none", rename = "externalDocs")]
513    pub external_docs: Option<ExternalDoc>,
514    /// A free-form property to include an example of an instance for this schema.
515    #[serde(skip_serializing_if = "Option::is_none")]
516    pub example: Option<Value>,
517    // composition
518    #[serde(skip_serializing_if = "Option::is_none")]
519    #[serde(rename = "allOf")]
520    pub all_of: Option<Vec<Box<Schema>>>,
521    // TODO: we need a validation step that we only collect x-* properties here.
522    #[serde(flatten)]
523    pub extensions: BTreeMap<String, serde_json::Value>,
524}
525
526/// ### ParameterType
527#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
528#[serde(rename_all = "lowercase")]
529pub enum ParameterType {
530    String,
531    Number,
532    Integer,
533    Boolean,
534    Array,
535    File,
536}
537/// ### XML
538/// A metadata object that allows for more fine-tuned XML model definitions.
539#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
540pub struct XML {
541    /// Replaces the name of the element/attribute used for the described schema property.
542    #[serde(skip_serializing_if = "Option::is_none")]
543    pub name: Option<String>,
544    /// The URI of the namespace definition.
545    #[serde(skip_serializing_if = "Option::is_none")]
546    pub namespace: Option<String>,
547    /// The prefix to be used for the name.
548    #[serde(skip_serializing_if = "Option::is_none")]
549    pub prefix: Option<String>,
550    /// Declares whether the property definition translates to an attribute instead of an element.
551    #[serde(skip_serializing_if = "Option::is_none")]
552    pub attribute: Option<bool>,
553    /// MAY be used only for an array definition.
554    #[serde(skip_serializing_if = "Option::is_none")]
555    pub wrapped: Option<bool>,
556}
557#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
558#[serde(rename_all = "lowercase")]
559pub enum ItemsType {
560    String,
561    Number,
562    Integer,
563    Boolean,
564    Array,
565}
566/// ### Items Object
567/// A limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body".
568#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
569pub struct Items {
570    /// The internal type of the array. The value MUST be one of "string", "number", "integer", "boolean", or "array". Files and models are not allowed.
571    pub r#type: ItemsType,
572
573    /// The extending format for the previously mentioned `type`. See [Data Type Formats](https://swagger.io/specification/v2/#dataTypeFormat) for further details.
574    #[serde(skip_serializing_if = "Option::is_none")]
575    pub format: Option<String>,
576
577    /// **Required if `type` is "array"**. Describes the type of items in the array.
578    #[serde(skip_serializing_if = "Option::is_none")]
579    pub items: Option<Box<Items>>,
580
581    /// Determines the format of the array if type array is used.
582    #[serde(skip_serializing_if = "Option::is_none", rename = "collectionFormat")]
583    pub collection_format: Option<String>,
584
585    /// Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request.
586    /// (Note: "default" has no meaning for required parameters.)
587    #[serde(skip_serializing_if = "Option::is_none")]
588    pub default: Option<Value>,
589    #[serde(skip_serializing_if = "Option::is_none")]
590    pub maximum: Option<Number>,
591    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
592    pub exclusive_maximum: Option<bool>,
593    #[serde(skip_serializing_if = "Option::is_none")]
594    pub minimum: Option<Number>,
595    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
596    pub exclusive_minimum: Option<bool>,
597    #[serde(skip_serializing_if = "Option::is_none", rename = "maxLength")]
598    pub max_length: Option<Number>,
599    #[serde(skip_serializing_if = "Option::is_none", rename = "minLength")]
600    pub min_length: Option<Number>,
601    #[serde(skip_serializing_if = "Option::is_none")]
602    pub pattern: Option<String>,
603    #[serde(skip_serializing_if = "Option::is_none", rename = "maxItems")]
604    pub max_items: Option<Number>,
605    #[serde(skip_serializing_if = "Option::is_none", rename = "minItems")]
606    pub min_items: Option<Number>,
607    #[serde(skip_serializing_if = "Option::is_none", rename = "uniqueItems")]
608    pub unique_items: Option<bool>,
609    #[serde(skip_serializing_if = "Option::is_none")]
610    pub r#enum: Option<Vec<Value>>,
611    #[serde(skip_serializing_if = "Option::is_none", rename = "multipleOf")]
612    pub multiple_of: Option<Number>,
613    #[serde(flatten)]
614    pub extensions: Extensions,
615}
616
617/// ### Responses
618/// A container for the expected responses of an operation.
619// #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
620pub type Responses = BTreeMap<String, ResponseOrRef>;
621
622/// ### Response
623/// Describes a single response from an API Operation.
624#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
625pub struct Response {
626    ///  A short description of the response.
627    pub description: String,
628    /// A definition of the response structure.
629    #[serde(skip_serializing_if = "Option::is_none")]
630    pub schema: Option<Schema>,
631    /// A list of headers that are sent with the response.
632    #[serde(skip_serializing_if = "Option::is_none")]
633    pub headers: Option<BTreeMap<String, Header>>,
634    /// An example of the response message.
635    #[serde(skip_serializing_if = "Option::is_none")]
636    pub examples: Option<BTreeMap<String, Value>>,
637    #[serde(flatten)]
638    pub extensions: Extensions,
639}
640
641/// ### Header
642#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
643pub struct Header {
644    /// A short description of the header.
645    #[serde(skip_serializing_if = "Option::is_none")]
646    pub description: Option<String>,
647    /// The internal type of the array. The value MUST be one of "string", "number", "integer", "boolean", or "array". Files and models are not allowed.
648    pub r#type: ItemsType,
649
650    /// The extending format for the previously mentioned `type`. See [Data Type Formats](https://swagger.io/specification/v2/#dataTypeFormat) for further details.
651    #[serde(skip_serializing_if = "Option::is_none")]
652    pub format: Option<String>,
653
654    /// **Required if `type` is "array"**. Describes the type of items in the array.
655    #[serde(skip_serializing_if = "Option::is_none")]
656    pub items: Option<Box<Items>>,
657
658    /// Determines the format of the array if type array is used.
659    #[serde(skip_serializing_if = "Option::is_none", rename = "collectionFormat")]
660    pub collection_format: Option<String>,
661
662    /// Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request.
663    /// (Note: "default" has no meaning for required parameters.)
664    #[serde(skip_serializing_if = "Option::is_none")]
665    pub default: Option<Value>,
666    #[serde(skip_serializing_if = "Option::is_none")]
667    pub maximum: Option<Number>,
668    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
669    pub exclusive_maximum: Option<bool>,
670    #[serde(skip_serializing_if = "Option::is_none")]
671    pub minimum: Option<Number>,
672    #[serde(skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
673    pub exclusive_minimum: Option<bool>,
674    #[serde(skip_serializing_if = "Option::is_none", rename = "maxLength")]
675    pub max_length: Option<Value>,
676    #[serde(skip_serializing_if = "Option::is_none", rename = "minLength")]
677    pub min_length: Option<Number>,
678    #[serde(skip_serializing_if = "Option::is_none")]
679    pub pattern: Option<String>,
680    #[serde(skip_serializing_if = "Option::is_none", rename = "maxItems")]
681    pub max_items: Option<Number>,
682    #[serde(skip_serializing_if = "Option::is_none", rename = "minItems")]
683    pub min_items: Option<Number>,
684    #[serde(skip_serializing_if = "Option::is_none", rename = "uniqueItems")]
685    pub unique_items: Option<bool>,
686    #[serde(skip_serializing_if = "Option::is_none")]
687    pub r#enum: Option<Vec<Value>>,
688    #[serde(skip_serializing_if = "Option::is_none", rename = "multipleOf")]
689    pub multiple_of: Option<Number>,
690    #[serde(flatten)]
691    pub extensions: Extensions,
692}
693
694#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
695#[serde(untagged)]
696pub enum ResponseOrRef {
697    Response {
698        description: String,
699        schema: Option<Schema>,
700        headers: Option<BTreeMap<String, Header>>,
701        examples: Option<BTreeMap<String, Value>>,
702        #[serde(flatten)]
703        extensions: Extensions,
704    },
705    Ref {
706        #[serde(rename = "$ref")]
707        reference: String,
708    },
709}
710
711/// ### Discriminator
712/// When request bodies or response payloads may be one of a number of different schemas, a discriminator object can be used to aid in serialization, deserialization, and validation.
713#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
714pub struct Discriminator {
715    /// The name of the property in the payload that will hold the discriminator value.
716    #[serde(rename = "propertyName")]
717    pub property_name: String,
718    /// An object to hold mappings between payload values and schema names or references.
719    #[serde(skip_serializing_if = "Option::is_none")]
720    pub mapping: Option<BTreeMap<String, String>>,
721}
722
723#[cfg(test)]
724mod test {
725    use super::*;
726    use serde_json;
727    #[test]
728    fn parameter_or_ref_dese() {
729        let json_str = r#"{
730            "$ref":"/some/path"
731        }"#;
732
733        assert_eq!(
734            serde_json::from_str::<ParameterOrRef>(&json_str).unwrap(),
735            ParameterOrRef::Ref(Reference {
736                reference: "/some/path".to_string()
737            })
738        )
739    }
740}