apple_bloom/v3/
components.rs

1use crate::v3::{
2    Callback, Example, Extensions, Header, Link, Parameter, RequestBody, Response, Schema,
3    SecurityScheme,
4};
5use serde::{Deserialize, Serialize};
6use std::collections::BTreeMap;
7
8#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
9#[serde(untagged)]
10pub enum ObjectOrReference<T> {
11    // Instead of an object, the object can reference another object.
12    // It looks something like `#/components/schemas/pet` which means
13    // we need to start from the root, get the `components` object,
14    //  then `schemas` and finally `pet` is the object.
15    Ref {
16        #[serde(rename = "$ref")]
17        ref_path: String,
18    },
19    Object(T),
20}
21
22#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
23#[serde(untagged)]
24pub enum BooleanObjectOrReference<T> {
25    Boolean(bool),
26    Object(T),
27    Ref {
28        #[serde(rename = "$ref")]
29        ref_path: String,
30    },
31}
32
33/// Holds a set of reusable objects for different aspects of the OAS.
34///
35/// All objects defined within the components object will have no effect on the API unless
36/// they are explicitly referenced from properties outside the components object.
37///
38/// See <https://github.com/OAI/OpenAPI-Specification/blob/aa91a19c43f8a12c02efa42d64794e396473f3b1/versions/3.0.1.md#componentsObject>.
39#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)]
40pub struct Components {
41    /// An object to hold reusable Schema Objects.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub schemas: Option<BTreeMap<String, ObjectOrReference<Schema>>>,
44
45    /// An object to hold reusable Response Objects.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub responses: Option<BTreeMap<String, ObjectOrReference<Response>>>,
48
49    /// An object to hold reusable Parameter Objects.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub parameters: Option<BTreeMap<String, ObjectOrReference<Parameter>>>,
52
53    /// An object to hold reusable Example
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub examples: Option<BTreeMap<String, ObjectOrReference<Example>>>,
56
57    /// An object to hold reusable Request Body Objects.
58    #[serde(skip_serializing_if = "Option::is_none", rename = "requestBodies")]
59    pub request_bodies: Option<BTreeMap<String, ObjectOrReference<RequestBody>>>,
60
61    /// An object to hold reusable Header Objects.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub headers: Option<BTreeMap<String, ObjectOrReference<Header>>>,
64
65    /// An object to hold reusable Security Scheme Objects.
66    #[serde(skip_serializing_if = "Option::is_none", rename = "securitySchemes")]
67    pub security_schemes: Option<BTreeMap<String, ObjectOrReference<SecurityScheme>>>,
68
69    /// An object to hold reusable Link Objects.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub links: Option<BTreeMap<String, ObjectOrReference<Link>>>,
72
73    /// An object to hold reusable Callback Objects.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub callbacks: Option<BTreeMap<String, ObjectOrReference<Callback>>>,
76
77    #[serde(flatten)]
78    pub extensions: Extensions,
79}