# Struct Generation
The `structgen.rs` module handles generating Rust structs from OpenAPI schema components. Here's how it works:
```plantuml
@startuml
:OpenAPI Schema Component;
:Check schema_kind;
:Map types via type_to_string();
:Apply patch_prefix logic;
:Apply workaround mode;
:Generated Rust Struct;
@enduml
```
## Object Schemas
For each schema of `type: object`, a struct is generated with:
```rust
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct SchemaName {
pub field_one: String,
pub field_two: i64,
pub field_three: Option<BriefRelatedObject>,
}
```
### Type Mapping
OpenAPI types are mapped to Rust types via `bindgen::type_to_string()`:
| `string` | `String` |
| `integer` (signed, maximum <= i8::MAX) | `i8` |
| `integer` (signed, maximum <= i16::MAX) | `i16` |
| `integer` (signed, maximum <= i32::MAX) | `i32` |
| `integer` (signed, larger or no maximum) | `i64` |
| `integer` (unsigned, maximum <= u8::MAX) | `u8` |
| `integer` (unsigned, maximum <= u16::MAX) | `u16` |
| `integer` (unsigned, maximum <= u32::MAX) | `u32` |
| `integer` (unsigned, larger or no maximum) | `u64` |
| `number` | `f64` |
| `boolean` | `bool` |
| `array` | `Vec<T>` |
| `object` | `Option<HashMap<String, Value>>` |
| `$ref` | Referenced struct name |
| `nullable` | Wrapped in `Option<T>` |
| No schema | `serde_json::Value` |
## PATCH Schema Handling
Schemas whose name starts with the configured `--patch-prefix` (default: `Patched`) get special treatment:
1. All fields are wrapped in `Option<T>`
2. A `#[serde(skip_serializing_if = "Option::is_none")]` attribute is added
3. This allows partial updates where only changed fields are sent
## Workaround Mode
When `--workaround` is enabled, all non-`Request` struct fields (except `id`) are wrapped in `Option<T>` to prevent deserialization crashes from unexpected null values in API responses.