Skip to content

Align Rust models with OpenAPI schema and remove dead code suppressions#13

Merged
tayyebi merged 4 commits intomainfrom
copilot/align-openapi-schema
Jan 22, 2026
Merged

Align Rust models with OpenAPI schema and remove dead code suppressions#13
tayyebi merged 4 commits intomainfrom
copilot/align-openapi-schema

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 22, 2026

Rust struct definitions diverged from the OpenAPI specification, causing potential API parsing errors and missing fields. Multiple #[allow(dead_code)] suppressions masked actually-used code.

Model Updates

Region - Complete rewrite

  • Added 12 missing fields: abbr, image, is_active, is_out_of_stock, overall_activeness, ddos_activeness, is_premium, is_hidden, has_offset_price, max_discount_percent, position, config
  • Introduced RegionConfig struct for nested configuration object

Product - Restructured to match API hierarchy

  • Created Plan, PlanSpecification, PriceItem structs
  • Added: region_id, plan_id, network_max_rate, network_max_rate95, discount_percent, stock fields
  • Preserved display helpers with #[serde(skip)] for template compatibility

Instance - Expanded from 11 to 30+ fields

  • Added: vcpu_count, ram, disk, inserted_at, os_id, iso_id, from_image, user_id, app_id, product_id, network_status, discount_percent, attach_iso, extra_resource, class, oca_data, is_ddos_protected, customer_note, admin_note
  • Created ExtraResource struct for resource overrides

Application - Added 8 missing fields

  • price, pricing_type, is_active, tag, is_experimental, os_family, os_list
  • Mapped osListos_list, kept category as derived helper

OS - Added is_active boolean field

Code Cleanup

Removed 15+ dead code suppressions from:

  • API modules: applications, floating_ips, images, iso, snapshots, backups
  • Update module: github, platform, error, asset

All removed suppressions were for code verified to be in active use.

Example

Before:

pub struct Region {
    pub id: String,
    pub name: String,
    pub slug: String,        // Not in OpenAPI
    pub country: String,     // Not in OpenAPI
    pub city: String,        // Not in OpenAPI
    pub latitude: Option<f64>,  // Not in OpenAPI
    pub longitude: Option<f64>, // Not in OpenAPI
}

After:

pub struct Region {
    pub id: String,
    pub name: String,
    pub abbr: String,
    pub image: String,
    pub is_active: bool,
    pub is_out_of_stock: bool,
    pub overall_activeness: bool,
    pub ddos_activeness: Option<bool>,
    pub is_premium: bool,
    pub is_hidden: bool,
    pub has_offset_price: bool,
    pub max_discount_percent: Option<i32>,
    pub position: serde_json::Value,
    pub config: RegionConfig,
}

All parsing logic updated to populate new fields from API responses. Display helpers maintained where needed for template compatibility using #[serde(skip)].

Original prompt

Comprehensive OpenAPI Schema Alignment and Code Cleanup

Objective

Ensure ALL struct definitions, API parsing logic, and data flows match the provided OpenAPI schema in openapi.json. Remove dead code suppressions and fix schema misalignments.


1. Region Schema Issues

Current Rust Struct (src/models/region.rs)

pub struct Region {
    pub id: String,
    pub name: String,
    pub slug: String,        // ❌ NOT IN OPENAPI
    pub country: String,     // ❌ NOT IN OPENAPI
    pub city: String,        // ❌ NOT IN OPENAPI
    pub latitude: Option<f64>,  // ❌ NOT IN OPENAPI
    pub longitude: Option<f64>, // ❌ NOT IN OPENAPI
}

OpenAPI Schema (RegionSchema)

{
  "id": "string",
  "name": "string",
  "abbr": "string",
  "image": "string",
  "isActive": "boolean",
  "isOutOfStock": "boolean",
  "overallActiveness": "boolean",
  "ddosActiveness": "boolean",
  "isPremium": "boolean",
  "isHidden": "boolean",
  "hasOffsetPrice": "boolean",
  "maxDiscountPercent": "integer",
  "position": "object",
  "config": "RegionConfigDetailSchema"
}

Fix Required

COMPLETELY REWRITE src/models/region.rs to match OpenAPI:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RegionConfig {
    pub support_ipv6: bool,
    pub support_regular_cpu: bool,
    pub support_high_frequency_cpu: bool,
    pub support_monitoring: bool,
    pub support_gpu: bool,
    pub support_custom_plan: bool,
    pub ram_threshold_in_gb: i32,
    pub ip_threshold: i32,
    pub disk_threshold_in_gb: i32,
    pub support_ddos_ipv4: Option<bool>,
    pub ddos_ipv4_threshold: Option<i32>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Region {
    pub id: String,
    pub name: String,
    pub abbr: String,
    pub image: String,
    pub is_active: bool,
    pub is_out_of_stock: bool,
    pub overall_activeness: bool,
    pub ddos_activeness: Option<bool>,
    pub is_premium: bool,
    pub is_hidden: bool,
    pub has_offset_price: bool,
    pub max_discount_percent: Option<i32>,
    pub position: serde_json::Value, // HashMap<String, i32> in practice
    pub config: RegionConfig,
}

UPDATE src/api/regions.rs parsing logic to match:

let region = Region {
    id: obj.get("id").and_then(|v| v.as_str()).unwrap_or("").to_string(),
    name: obj.get("name").and_then(|v| v.as_str()).unwrap_or("").to_string(),
    abbr: obj.get("abbr").and_then(|v| v.as_str()).unwrap_or("").to_string(),
    image: obj.get("image").and_then(|v| v.as_str()).unwrap_or("").to_string(),
    is_active: obj.get("isActive").and_then(|v| v.as_bool()).unwrap_or(false),
    is_out_of_stock: obj.get("isOutOfStock").and_then(|v| v.as_bool()).unwrap_or(false),
    overall_activeness: obj.get("overallActiveness").and_then(|v| v.as_bool()).unwrap_or(false),
    ddos_activeness: obj.get("ddosActiveness").and_then(|v| v.as_bool()),
    is_premium: obj.get("isPremium").and_then(|v| v.as_bool()).unwrap_or(false),
    is_hidden: obj.get("isHidden").and_then(|v| v.as_bool()).unwrap_or(false),
    has_offset_price: obj.get("hasOffsetPrice").and_then(|v| v.as_bool()).unwrap_or(false),
    max_discount_percent: obj.get("maxDiscountPercent").and_then(|v| v.as_i64()).map(|i| i as i32),
    position: obj.get("position").cloned().unwrap_or(serde_json::json!({})),
    config: parse_region_config(obj.get("config")),
};

2. Product Schema Issues

Current Rust Struct (src/models/product_view.rs)

pub struct ProductView {
    pub id: String,
    pub name: String,
    pub display_name: String,  // ❌ NOT IN OPENAPI
    pub description: String,   // ❌ NOT IN OPENAPI
    pub tags: String,          // ❌ NOT IN OPENAPI
    pub spec_entries: Vec<ProductEntry>,  // ❌ CUSTOM, NOT IN OPENAPI
    pub price_entries: Vec<ProductEntry>, // ❌ CUSTOM, NOT IN OPENAPI
    pub cpu: Option<String>,    // ❌ WRONG TYPE (should be from plan.specification.cpu)
    pub ram: Option<String>,    // ❌ WRONG TYPE
    pub storage: Option<String>, // ❌ WRONG TYPE
    pub bandwidth: Option<String>, // ❌ WRONG TYPE
}

OpenAPI Schema (DetailedProductSchema)

{
  "regionId": "string",
  "planId": "string",
  "isActive": "boolean",
  "networkMaxRate": "number",
  "networkMaxRate95": "number",
  "discountPercent": "integer",
  "remainingActualStock": "integer",
  "remainingPreorderCapacity": "integer",
  "id": "string",
  "plan": "PlanSchema",
  "overallActiveness": "boolean",
  "ddosActiveness": "boolean",
  "priceItems": ["PriceItem"],
  "oses": ["OsActiveness"],
  "features": ["AddonActiveness"],
  "apps": ["AddonActiveness"]
}

Fix Required

REWRITE src/models/product_view.rs:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct PlanSpecification {
    pub cpu: f64,
    pub ram: f64,
    pub ram_in_mb: f64,
    pub storage: f64,
    pub bandwidth_in_tb: f64,
}

#[derive(Serialize, Deserialize, Clone, D...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/CloudzyVPS/cli/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 22, 2026 12:48
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Copilot AI changed the title [WIP] Align Rust structs with OpenAPI schema and cleanup Align Rust models with OpenAPI schema and remove dead code suppressions Jan 22, 2026
Copilot AI requested a review from tayyebi January 22, 2026 13:01
@tayyebi tayyebi marked this pull request as ready for review January 22, 2026 13:03
@tayyebi tayyebi merged commit d30916f into main Jan 22, 2026
@tayyebi tayyebi deleted the copilot/align-openapi-schema branch January 22, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants