dynami 0.1.0

Automatic Axum router generation from directory structure with file-system based routing
Documentation
pub fn generate_default_handler(state_name: Option<&str>) -> String {
    if let Some(state) = state_name {
        format!(
            r#"use axum::extract::State;
use axum::response::IntoResponse;

pub async fn handler(State(state): State<{}>) -> impl IntoResponse {{
    "OK"
}}
"#,
            state
        )
    } else {
        r#"use axum::response::IntoResponse;

pub async fn handler() -> impl IntoResponse {
    "OK"
}
"#
        .to_string()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_generate_handler_without_state() {
        let handler = generate_default_handler(None);
        assert!(handler.contains("pub async fn handler() -> impl IntoResponse"));
        assert!(handler.contains("\"OK\""));
        assert!(!handler.contains("State"));
    }

    #[test]
    fn test_generate_handler_with_state() {
        let handler = generate_default_handler(Some("AppState"));
        assert!(handler.contains("State(state): State<AppState>"));
        assert!(handler.contains("use axum::extract::State"));
        assert!(handler.contains("\"OK\""));
    }

    #[test]
    fn test_generate_handler_with_custom_state() {
        let handler = generate_default_handler(Some("MyCustomState"));
        assert!(handler.contains("State(state): State<MyCustomState>"));
    }
}