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}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct UnionModel {
26    pub name: String,
27    pub variants: Vec<UnionVariant>,
28    pub union_type: UnionType,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub enum UnionType {
33    OneOf,
34    AnyOf,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct UnionVariant {
39    pub name: String,
40    pub fields: Vec<Field>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct CompositionModel {
45    pub name: String,
46    pub all_fields: Vec<Field>,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct RequestModel {
51    pub name: String,
52    pub content_type: String,
53    pub schema: String,
54    pub is_required: bool,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct ResponseModel {
59    pub name: String,
60    pub status_code: String,
61    pub content_type: String,
62    pub schema: String,
63    pub description: Option<String>,
64}