api_index - OmniCloudOrg/OmniOrchestrator GitHub Wiki

index (src/api)

Path: src/api/index.rs

Table of Contents

Public Items

struct RouteInfo

Definition

pub struct RouteInfo {
    /// Path of the route
    path: String,
    /// HTTP methods supported by the route
    methods: Vec<String>,
}

Documentation

Route information structure for API documentation

struct RoutesResponse

Definition

pub struct RoutesResponse {
    /// List of all available routes and their methods
    routes: Vec<RouteInfo>,
}

Documentation

Response structure for routes listing endpoint

struct RoutesCollection

Definition

pub struct RoutesCollection {
    routes: Vec<RouteInfo>,
}

Documentation

Routes collection that will be populated during startup

fn new

Definition

    pub fn new() -> Self {
        Self { routes: Vec::new() }
    }

    pub fn add_route(&mut self, path: String, method: String) {
        // Check if the route already exists
        if let Some(route) = self.routes.iter_mut().find(|r| r.path == path) {
            // Add method if it doesn't exist
            if !route.methods.contains(&method) {
                route.methods.push(method);
            }
        } else {
            // Add new route info
            self.routes.push(RouteInfo {
                path,
                methods: vec![method],
            });
        }
    }

    pub fn get_routes(&self) -> Vec<RouteInfo> {
    // ... function body
}

fn add_route

Definition

    pub fn add_route(&mut self, path: String, method: String) {
        // Check if the route already exists
        if let Some(route) = self.routes.iter_mut().find(|r| r.path == path) {
            // Add method if it doesn't exist
            if !route.methods.contains(&method) {
                route.methods.push(method);
            }
        } else {
            // Add new route info
            self.routes.push(RouteInfo {
                path,
                methods: vec![method],
            });
        }
    }

    pub fn get_routes(&self) -> Vec<RouteInfo> {
        self.routes.clone()
    }
}

    // ... function definition continues
    // ... function body
}

fn get_routes

Definition

    pub fn get_routes(&self) -> Vec<RouteInfo> {
        self.routes.clone()
    }
}

/// Global singleton instance of the routes collection
/// Stores information about all registered API routes
lazy_static! {
    static ref ROUTES_COLLECTION: Arc<Mutex<RoutesCollection>> = Arc::new(Mutex::new(RoutesCollection::new()));
}

/// Decodes any encoded characters in route paths and preserves parameter notation
fn decode_route_path(path: &str) -> String {
    let mut result = path.to_string();
    
    // Handle common Unicode escape sequences
    let replacements = [
        ("\\u003C", "<"), ("\\u003E", ">"),
        ("\\u003c", "<"), ("\\u003e", ">"),
        ("\\u0026", "&"), ("\\u0027", "'"),
        ("\\u0022", "\""), ("\\u003D", "="),
    // ... function definition continues
    // ... function body
}

fn collect_routes

Definition

pub fn collect_routes(rocket: &Rocket<Build>) {
    let mut routes_collection = ROUTES_COLLECTION.lock().unwrap();
    
    for route in rocket.routes() {
        // Get the path and decode any escaped characters
        let path = decode_route_path(&route.uri.to_string());
        
        routes_collection.add_route(
            path,
            route.method.to_string(),
        );
    }
}

/// Routes listing endpoint providing HTML representation of routes
#[get("/")]
pub fn routes_ui() -> content::RawHtml<String> {
    let routes_collection = ROUTES_COLLECTION.lock().unwrap();
    let routes = routes_collection.get_routes();

    // Collect unique versions dynamically
    // ... function definition continues
    // ... function body
}

fn routes_ui

Definition

pub fn routes_ui() -> content::RawHtml<String> {
    let routes_collection = ROUTES_COLLECTION.lock().unwrap();
    let routes = routes_collection.get_routes();

    // Collect unique versions dynamically
    let mut versions: Vec<String> = routes
        .iter()
        .filter_map(|route| {
            let path = &route.path;
            if let Some(start) = path.find("/api/v") {
                let rest = &path[start + 6..];
                let end = rest.find('/').unwrap_or(rest.len());
                let version = &rest[..end];
                if version.chars().all(|c| c.is_numeric()) {
                    Some(format!("v{}", version))
                } else {
                    None
                }
            } else {
                None
            }
    // ... function definition continues
    // ... function body
}

Documentation

Routes listing endpoint providing HTML representation of routes

⚠️ **GitHub.com Fallback** ⚠️