Skip to main content

oas3/spec/
components.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::spec::{
6    schema::ObjectSchema, spec_extensions, Callback, Example, Header, Link, ObjectOrReference,
7    Parameter, PathItem, RequestBody, Response, SecurityScheme,
8};
9
10/// Holds a set of reusable objects for different aspects of the OAS.
11///
12/// All objects defined within the components object will have no effect on the API unless
13/// they are explicitly referenced from properties outside the components object.
14///
15/// See <https://spec.openapis.org/oas/v3.1.1#components-object>.
16#[derive(Debug, Clone, Default, PartialEq, Deserialize, Serialize)]
17pub struct Components {
18    /// An object to hold reusable [Schema Objects](ObjectSchema).
19    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
20    pub schemas: BTreeMap<String, ObjectOrReference<ObjectSchema>>,
21
22    /// An object to hold reusable [Response Objects](Response).
23    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
24    pub responses: BTreeMap<String, ObjectOrReference<Response>>,
25
26    /// An object to hold reusable [Parameter Objects](Parameter).
27    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
28    pub parameters: BTreeMap<String, ObjectOrReference<Parameter>>,
29
30    /// An object to hold reusable [Example Objects](Example).
31    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
32    pub examples: BTreeMap<String, ObjectOrReference<Example>>,
33
34    /// An object to hold reusable [Request Body Objects](RequestBody).
35    #[serde(
36        rename = "requestBodies",
37        default,
38        skip_serializing_if = "BTreeMap::is_empty"
39    )]
40    pub request_bodies: BTreeMap<String, ObjectOrReference<RequestBody>>,
41
42    /// An object to hold reusable [Header Objects](Header).
43    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
44    pub headers: BTreeMap<String, ObjectOrReference<Header>>,
45
46    /// An object to hold reusable [Path Item Objects](PathItem).
47    #[serde(
48        rename = "pathItems",
49        default,
50        skip_serializing_if = "BTreeMap::is_empty"
51    )]
52    pub path_items: BTreeMap<String, ObjectOrReference<PathItem>>,
53
54    /// An object to hold reusable [Security Scheme Objects](SecurityScheme).
55    #[serde(
56        rename = "securitySchemes",
57        default,
58        skip_serializing_if = "BTreeMap::is_empty"
59    )]
60    pub security_schemes: BTreeMap<String, ObjectOrReference<SecurityScheme>>,
61
62    /// An object to hold reusable [Link Objects](crate::spec::Link).
63    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
64    pub links: BTreeMap<String, ObjectOrReference<Link>>,
65
66    /// An object to hold reusable [Callback Objects](crate::spec::Callback).
67    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
68    pub callbacks: BTreeMap<String, ObjectOrReference<Callback>>,
69
70    /// Specification extensions.
71    ///
72    /// Only "x-" prefixed keys are collected, and the prefix is stripped.
73    ///
74    /// See <https://spec.openapis.org/oas/v3.1.1#specification-extensions>.
75    #[serde(flatten, with = "spec_extensions")]
76    pub extensions: BTreeMap<String, serde_json::Value>,
77}