pub mod native;
#[cfg(feature = "openapi")]
pub mod openapi;
use apcore_toolkit::ScannedModule;
use async_trait::async_trait;
#[async_trait]
pub trait AxumScanner: Send + Sync {
async fn scan(
&self,
app: &axum::Router,
include: Option<&str>,
exclude: Option<&str>,
) -> Result<Vec<ScannedModule>, crate::errors::AxumApcoreError>;
fn source_name(&self) -> &str;
}
pub fn get_scanner(source: &str) -> Result<Box<dyn AxumScanner>, crate::errors::AxumApcoreError> {
match source {
"native" => Ok(Box::new(native::NativeAxumScanner::new())),
#[cfg(feature = "openapi")]
"openapi" => Ok(Box::new(openapi::OpenAPIScanner::new())),
other => Err(crate::errors::AxumApcoreError::Scanner(format!(
"Unknown scanner source: '{}'. Available: native{}",
other,
if cfg!(feature = "openapi") {
", openapi"
} else {
""
}
))),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_scanner_native() {
let scanner = get_scanner("native").unwrap();
assert_eq!(scanner.source_name(), "native");
}
#[test]
fn test_get_scanner_unknown() {
let result = get_scanner("unknown");
assert!(result.is_err());
}
}