use std::collections::HashMap;
use super::http_method_name;
use crate::rest_hir::{HttpOperation, RestHirResult};
pub(crate) fn validate_unique_route_bindings(
interface_name: &str,
operations: &[HttpOperation],
) -> RestHirResult<()> {
let mut bindings = HashMap::<String, String>::new();
for operation in operations {
for route in &operation.meta.routes {
let key = format!("{} {}", http_method_name(operation.meta.method), route.path);
if let Some(previous) = bindings.insert(key.clone(), operation.meta.name.clone()) {
return Err(format!(
"duplicate HTTP route binding in interface '{interface_name}': {key} \
(operations: {previous}, {}); give each operation a distinct path, or use \
an @http union for content negotiation on one route",
operation.meta.name
));
}
}
}
Ok(())
}
#[cfg(test)]
mod tests;