(
endpoint_prefix: &str,
base_input_path: &Path,
input_path: &Path,
attributes: &Vec<syn::Attribute>,
hook: &mut Hook,
)
| 236 | } |
| 237 | |
| 238 | fn extract_endpoint_information( |
| 239 | endpoint_prefix: &str, |
| 240 | base_input_path: &Path, |
| 241 | input_path: &Path, |
| 242 | attributes: &Vec<syn::Attribute>, |
| 243 | hook: &mut Hook, |
| 244 | ) { |
| 245 | let mut verb = HttpVerb::Unknown; |
| 246 | let mut path = String::new(); |
| 247 | |
| 248 | for attr in attributes { |
| 249 | let last_segment = attr.path.segments.last(); |
| 250 | if let Some(potential_verb) = last_segment { |
| 251 | let potential_verb = potential_verb.ident.to_string(); |
| 252 | |
| 253 | if potential_verb.eq_ignore_ascii_case("get") { |
| 254 | verb = HttpVerb::Get; |
| 255 | } else if potential_verb.eq_ignore_ascii_case("post") { |
| 256 | verb = HttpVerb::Post; |
| 257 | } else if potential_verb.eq_ignore_ascii_case("put") { |
| 258 | verb = HttpVerb::Put; |
| 259 | } else if potential_verb.eq_ignore_ascii_case("delete") { |
| 260 | verb = HttpVerb::Delete; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if !matches!(verb, HttpVerb::Unknown) { |
| 265 | for token in attr.clone().tokens { |
| 266 | if let proc_macro2::TokenTree::Group(g) = token { |
| 267 | for x in g.stream() { |
| 268 | if let proc_macro2::TokenTree::Literal(lit) = x { |
| 269 | path = lit.to_string().trim_matches('"').to_string(); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | let endpoint_base = input_path |
| 278 | .parent() |
| 279 | .unwrap() |
| 280 | .strip_prefix(base_input_path) |
| 281 | .unwrap() |
| 282 | .to_str() |
| 283 | .unwrap() |
| 284 | .trim_start_matches('/') |
| 285 | .trim_end_matches('/'); |
| 286 | |
| 287 | // the part extracted from the attribute, for example: `#[post("/{id}"]` |
| 288 | let handler_path = path.trim_start_matches('/').trim_end_matches('/'); |
| 289 | |
| 290 | hook.endpoint_url = format!("{endpoint_prefix}/{endpoint_base}/{handler_path}") |
| 291 | .trim_end_matches('/') |
| 292 | .to_string(); |
| 293 | |
| 294 | hook.endpoint_verb = verb; |
| 295 | } |
no test coverage detected