Files
harmony/opnsense-api/examples/list_vlan.rs
Jean-Gabriel Gill-Couture 4af5e7ac19 feat(opnsense): generate types for all 7 modules with codegen fixes
Generate typed API models for HAProxy, Caddy, Firewall, VLAN, LAGG,
WireGuard (client/server/general), and regenerate Dnsmasq. All core
modules validated against a live OPNsense 26.1.2 instance.

Codegen improvements:
- Add --module-name and --api-key CLI flags for controlling output
  filenames and API response envelope keys
- Fix enum variant names starting with digits (prefix with V)
- Use value="" XML attribute for wire values instead of element names
- Handle unknown *Field types as opn_string (select widget safe)
- Forgiving enum deserialization (warn instead of error on unknown)
- Handle empty arrays in opn_string deserializer

Add per-module examples (list_haproxy, list_caddy, list_vlan, etc.)
and utility examples (raw_get, check_package, install_and_wait).
Extract shared client setup into examples/common/mod.rs.

Fix post_typed sending empty JSON body ({}) instead of no body,
which was causing 400 errors on firmware endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 18:11:02 -04:00

22 lines
478 B
Rust

//! Example: fetch and display OPNsense VLAN settings.
//!
//! ```text
//! cargo run --example list_vlan
//! ```
mod common;
use opnsense_api::generated::vlan::VlansResponse;
#[tokio::main]
async fn main() {
let client = common::client_from_env();
let response: VlansResponse = client
.get_typed("interfaces", "vlan_settings", "get")
.await
.expect("API call failed");
println!("{}", serde_json::to_string_pretty(&response).unwrap());
}