openapi_model_generator/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub enum ModelType {
5    Struct(Model),
6    Union(UnionModel),             // oneOf/anyOf -> enum
7    Composition(CompositionModel), // allOf
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Model {
12    pub name: String,
13    pub fields: Vec<Field>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct Field {
18    pub name: String,
19    pub field_type: String,
20    pub format: String,
21    pub is_required: bool,
22    pub is_nullable: bool,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct UnionModel {
27    pub name: String,
28    pub variants: Vec<UnionVariant>,
29    pub union_type: UnionType,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub enum UnionType {
34    OneOf,
35    AnyOf,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct UnionVariant {
40    pub name: String,
41    pub fields: Vec<Field>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct CompositionModel {
46    pub name: String,
47    pub all_fields: Vec<Field>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct RequestModel {
52    pub name: String,
53    pub content_type: String,
54    pub schema: String,
55    pub is_required: bool,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct ResponseModel {
60    pub name: String,
61    pub status_code: String,
62    pub content_type: String,
63    pub schema: String,
64    pub description: Option<String>,
65}