Skip to main content

gws_builder/ir/
types.rs

1//! Intermediate representation types for codegen.
2
3/// Resolved or built-in type in the IR.
4#[allow(dead_code)]
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum IrType {
7    String,
8    I32,
9    I64,
10    U32,
11    U64,
12    F32,
13    F64,
14    Bool,
15    Bytes,
16    DateTime,
17    Date,
18    Any,
19    Array(Box<IrType>),
20    Map(Box<IrType>),
21    /// Named schema reference (top-level `schemas` key).
22    Ref(String),
23    Struct(IrStruct),
24    Enum(IrEnum),
25}
26
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct IrStruct {
29    pub name: String,
30    pub doc: Option<String>,
31    pub fields: Vec<IrField>,
32    pub is_recursive: bool,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct IrField {
37    pub original_name: String,
38    pub rust_name: String,
39    pub doc: Option<String>,
40    pub field_type: IrType,
41    pub required: bool,
42    pub read_only: bool,
43    pub deprecated: bool,
44    pub default_value: Option<String>,
45    /// Set by `resolve` when breaking a cyclic `$ref`.
46    pub needs_box: bool,
47    /// `#[serde(flatten)]` for `additionalProperties` alongside fixed `properties`.
48    pub serde_flatten: bool,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct IrEnum {
53    pub name: String,
54    pub doc: Option<String>,
55    pub variants: Vec<IrEnumVariant>,
56}
57
58#[derive(Debug, Clone, PartialEq, Eq)]
59pub struct IrEnumVariant {
60    pub original_value: String,
61    pub rust_name: String,
62    pub doc: Option<String>,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub struct IrMethod {
67    pub id: String,
68    pub rust_name: String,
69    pub doc: Option<String>,
70    pub http_method: String,
71    pub path_template: String,
72    pub path_params: Vec<IrField>,
73    pub query_params: Vec<IrField>,
74    pub request_type: Option<IrType>,
75    pub response_type: Option<IrType>,
76    pub scopes: Vec<String>,
77    pub supports_pagination: bool,
78    pub supports_media_upload: bool,
79    pub supports_media_download: bool,
80    pub deprecated: bool,
81}
82
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct IrService {
85    pub name: String,
86    pub version: String,
87    pub doc: Option<String>,
88    pub base_url: String,
89    pub structs: Vec<IrStruct>,
90    pub enums: Vec<IrEnum>,
91    pub resources: Vec<IrResource>,
92}
93
94#[derive(Debug, Clone, PartialEq, Eq)]
95pub struct IrResource {
96    pub name: String,
97    pub rust_name: String,
98    pub methods: Vec<IrMethod>,
99    pub sub_resources: Vec<IrResource>,
100}