openapi_model_generator/
models.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub enum ModelType {
5 Struct(Model),
6 Union(UnionModel), Composition(CompositionModel), Enum(EnumModel), }
10
11impl ModelType {
12 pub fn name(&self) -> &str {
13 match self {
14 ModelType::Struct(m) => &m.name,
15 ModelType::Enum(e) => &e.name,
16 ModelType::Union(u) => &u.name,
17 ModelType::Composition(c) => &c.name,
18 }
19 }
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct Model {
24 pub name: String,
25 pub fields: Vec<Field>,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct Field {
30 pub name: String,
31 pub field_type: String,
32 pub format: String,
33 pub is_required: bool,
34 pub is_nullable: bool,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct UnionModel {
39 pub name: String,
40 pub variants: Vec<UnionVariant>,
41 pub union_type: UnionType,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub enum UnionType {
46 OneOf,
47 AnyOf,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct UnionVariant {
52 pub name: String,
53 pub fields: Vec<Field>,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct CompositionModel {
58 pub name: String,
59 pub all_fields: Vec<Field>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct RequestModel {
64 pub name: String,
65 pub content_type: String,
66 pub schema: String,
67 pub is_required: bool,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ResponseModel {
72 pub name: String,
73 pub status_code: String,
74 pub content_type: String,
75 pub schema: String,
76 pub description: Option<String>,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct EnumModel {
81 pub name: String,
82 pub variants: Vec<String>,
83 pub description: Option<String>,
84}