irelia_cli/rest/
types.rs

1use hashlink::LinkedHashMap;
2use serde_derive::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5#[serde(deny_unknown_fields)]
6pub struct Schema {
7    pub openapi: String,
8    pub info: Info,
9    pub paths: LinkedHashMap<String, LinkedHashMap<String, Operation>>,
10    pub components: Components,
11    pub tags: Vec<Tag>,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15#[serde(deny_unknown_fields)]
16pub struct Components {
17    pub schemas: LinkedHashMap<String, SchemaValue>,
18}
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22#[serde(deny_unknown_fields)]
23pub struct SchemaValue {
24    #[serde(rename = "type")]
25    pub schema_type: Option<Type>,
26    pub description: Option<String>,
27    #[serde(rename = "enum")]
28    pub schema_enum: Option<Vec<String>>,
29    pub additional_properties: Option<PropertyAdditionalProperties>,
30    pub properties: Option<LinkedHashMap<String, Property>>,
31    pub required: Option<Vec<String>>,
32}
33
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36#[serde(deny_unknown_fields)]
37pub struct Property {
38    #[serde(rename = "type")]
39    pub property_type: Option<Type>,
40    pub format: Option<Format>,
41    pub minimum: Option<i64>,
42    #[serde(rename = "$ref")]
43    pub property_ref: Option<String>,
44    pub additional_properties: Option<PropertyAdditionalProperties>,
45    pub items: Option<AdditionalProperties>,
46    pub required: Option<bool>,
47}
48
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
50#[serde(untagged)]
51#[serde(deny_unknown_fields)]
52pub enum PropertyAdditionalProperties {
53    Bool(bool),
54    ItemsAdditionalProperties(AdditionalProperties),
55}
56
57// Avoid an alloc
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60#[serde(deny_unknown_fields)]
61pub struct AdditionalProperties {
62    #[serde(rename = "type")]
63    pub property_type: Option<Type>,
64    pub format: Option<Format>,
65    pub minimum: Option<i64>,
66    #[serde(rename = "$ref")]
67    pub property_ref: Option<String>,
68    pub additional_properties: Option<Box<PropertyAdditionalProperties>>,
69    pub items: Option<Box<PropertyAdditionalProperties>>,
70    pub required: Option<bool>,
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74#[serde(rename_all = "snake_case")]
75#[serde(deny_unknown_fields)]
76pub enum Format {
77    Double,
78    Float,
79    Int16,
80    Int32,
81    Int64,
82    Int8,
83    Uint16,
84    Uint32,
85    Uint64,
86    Uint8,
87}
88
89#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
90#[serde(rename_all = "snake_case")]
91#[serde(deny_unknown_fields)]
92pub enum Type {
93    Array,
94    Boolean,
95    Integer,
96    Number,
97    Object,
98    String,
99}
100
101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
102#[serde(deny_unknown_fields)]
103pub struct Info {
104    pub title: String,
105    pub description: String,
106    pub version: String,
107}
108
109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
110#[serde(rename_all = "camelCase")]
111#[serde(deny_unknown_fields)]
112pub struct Operation {
113    pub description: String,
114    pub operation_id: String,
115    pub parameters: Vec<Parameter>,
116    pub responses: Option<LinkedHashMap<String, Responses>>,
117    pub summary: Option<String>,
118    pub tags: Vec<String>,
119    pub request_body: Option<RequestBody>,
120}
121
122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
123#[serde(deny_unknown_fields)]
124pub struct Parameter {
125    #[serde(rename = "in")]
126    pub parameter_in: In,
127    pub name: String,
128    pub required: Option<bool>,
129    pub schema: Option<AdditionalProperties>,
130}
131
132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
133#[serde(rename_all = "snake_case")]
134#[serde(deny_unknown_fields)]
135pub enum In {
136    Path,
137    Query,
138}
139
140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
141#[serde(deny_unknown_fields)]
142pub struct RequestBody {
143    pub content: Content,
144}
145
146#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
147#[serde(deny_unknown_fields)]
148pub struct Content {
149    #[serde(rename = "application/json")]
150    pub application_json: ApplicationJson,
151}
152
153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
154#[serde(deny_unknown_fields)]
155pub struct ApplicationJson {
156    pub schema: Option<Property>,
157}
158
159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
160#[serde(deny_unknown_fields)]
161pub struct Responses {
162    pub content: Option<Content>,
163    pub description: String,
164}
165
166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
167#[serde(deny_unknown_fields)]
168pub struct Tag {
169    pub name: String,
170}