reinhardt-urls 0.3.0

URL routing and proxy utilities for Reinhardt framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
//! Route introspection for debugging and analysis
//!
//! This module provides tools for inspecting registered routes at runtime.
//! It's useful for debugging, documentation generation, and route analysis.
//!
//! # Examples
//!
//! ```
//! use reinhardt_urls::routers::introspection::{RouteInspector, RouteInfo};
//! use hyper::Method;
//!
//! let mut inspector = RouteInspector::new();
//!
//! // Register routes
//! inspector.add_route(
//!     "/api/v1/users/",
//!     vec![Method::GET, Method::POST],
//!     Some("api:v1:users:list"),
//!     None,
//! );
//!
//! // Query routes
//! let routes = inspector.all_routes();
//! assert_eq!(routes.len(), 1);
//!
//! // Find routes by pattern
//! let api_routes = inspector.find_by_path_prefix("/api/v1");
//! assert_eq!(api_routes.len(), 1);
//! ```

use crate::routers::namespace::Namespace;
use hyper::Method;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};

/// Metadata about a registered route
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteInfo {
	/// URL path pattern
	pub path: String,

	/// HTTP methods supported by this route (stored as strings for serialization)
	pub methods: Vec<String>,

	/// Full route name including namespace (e.g., "api:v1:users:detail")
	pub name: Option<String>,

	/// Namespace component
	pub namespace: Option<String>,

	/// Route name component (without namespace)
	pub route_name: Option<String>,

	/// Parameter names extracted from the path
	pub params: Vec<String>,

	/// Additional metadata
	pub metadata: HashMap<String, String>,
}

impl RouteInfo {
	/// Create a new RouteInfo
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInfo;
	/// use hyper::Method;
	///
	/// let info = RouteInfo::new(
	///     "/api/users/{id}/",
	///     vec![Method::GET, Method::PUT],
	///     Some("api:users:detail"),
	/// );
	///
	/// assert_eq!(info.path, "/api/users/{id}/");
	/// assert_eq!(info.params, vec!["id"]);
	/// ```
	pub fn new(
		path: impl Into<String>,
		methods: Vec<Method>,
		name: Option<impl Into<String>>,
	) -> Self {
		let path = path.into();
		let name = name.map(|n| n.into());

		// Convert Methods to strings for serialization
		let methods: Vec<String> = methods.iter().map(|m| m.as_str().to_string()).collect();

		// Extract parameters from path
		let params = super::namespace::extract_param_names(&path);

		// Split name into namespace and route_name
		// Django-style: "api:v1:users:detail" -> namespace = "api:v1:users", route_name = "detail"
		// The last component is the route name, all others form the namespace
		let (namespace, route_name) = if let Some(ref n) = name {
			let parts: Vec<&str> = n.split(':').collect();
			if parts.len() >= 2 {
				// At least 2 parts: last 1 is route_name, all others are namespace
				let namespace_end = parts.len() - 1;
				let ns = parts[..namespace_end].join(":");
				let rn = parts[namespace_end].to_string();
				(Some(ns), Some(rn))
			} else {
				// Single part: no namespace, just route_name
				(None, Some(n.clone()))
			}
		} else {
			(None, None)
		};

		Self {
			path,
			methods,
			name,
			namespace,
			route_name,
			params,
			metadata: HashMap::new(),
		}
	}

	/// Add metadata to this route
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInfo;
	/// use hyper::Method;
	///
	/// let mut info = RouteInfo::new("/users/", vec![Method::GET], None::<String>);
	/// info.add_metadata("description", "List all users");
	/// info.add_metadata("tags", "users,api");
	///
	/// assert_eq!(info.metadata.get("description"), Some(&"List all users".to_string()));
	/// ```
	pub fn add_metadata(&mut self, key: impl Into<String>, value: impl Into<String>) {
		self.metadata.insert(key.into(), value.into());
	}

	/// Check if this route supports a given HTTP method
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInfo;
	/// use hyper::Method;
	///
	/// let info = RouteInfo::new("/users/", vec![Method::GET, Method::POST], None::<String>);
	///
	/// assert!(info.supports_method(&Method::GET));
	/// assert!(info.supports_method(&Method::POST));
	/// assert!(!info.supports_method(&Method::DELETE));
	/// ```
	pub fn supports_method(&self, method: &Method) -> bool {
		self.methods.contains(&method.as_str().to_string())
	}

	/// Get the namespace as a Namespace object
	pub fn namespace_object(&self) -> Option<Namespace> {
		self.namespace.as_ref().map(Namespace::new)
	}
}

/// Route inspector for analyzing registered routes
///
/// # Examples
///
/// ```
/// use reinhardt_urls::routers::introspection::RouteInspector;
/// use hyper::Method;
///
/// let mut inspector = RouteInspector::new();
///
/// inspector.add_route("/api/users/", vec![Method::GET], Some("api:users:list"), None);
/// inspector.add_route("/api/users/{id}/", vec![Method::GET], Some("api:users:detail"), None);
///
/// assert_eq!(inspector.route_count(), 2);
/// ```
pub struct RouteInspector {
	routes: Vec<RouteInfo>,
	path_index: HashMap<String, usize>,
	name_index: HashMap<String, usize>,
}

impl RouteInspector {
	/// Create a new route inspector
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	///
	/// let inspector = RouteInspector::new();
	/// assert_eq!(inspector.route_count(), 0);
	/// ```
	pub fn new() -> Self {
		Self {
			routes: Vec::new(),
			path_index: HashMap::new(),
			name_index: HashMap::new(),
		}
	}

	/// Add a route to the inspector
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route(
	///     "/api/users/",
	///     vec![Method::GET, Method::POST],
	///     Some("api:users:list"),
	///     None,
	/// );
	///
	/// assert_eq!(inspector.route_count(), 1);
	/// ```
	pub fn add_route(
		&mut self,
		path: impl Into<String>,
		methods: Vec<Method>,
		name: Option<impl Into<String>>,
		metadata: Option<HashMap<String, String>>,
	) {
		let path = path.into();
		let mut route = RouteInfo::new(&path, methods, name);

		if let Some(meta) = metadata {
			route.metadata = meta;
		}

		let index = self.routes.len();

		// Index by path
		self.path_index.insert(path.clone(), index);

		// Index by name
		if let Some(ref name) = route.name {
			self.name_index.insert(name.clone(), index);
		}

		self.routes.push(route);
	}

	/// Get all registered routes
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], None::<String>, None);
	/// inspector.add_route("/posts/", vec![Method::GET], None::<String>, None);
	///
	/// assert_eq!(inspector.all_routes().len(), 2);
	/// ```
	pub fn all_routes(&self) -> &[RouteInfo] {
		&self.routes
	}

	/// Find a route by path
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);
	///
	/// let route = inspector.find_by_path("/users/").unwrap();
	/// assert_eq!(route.path, "/users/");
	/// ```
	pub fn find_by_path(&self, path: &str) -> Option<&RouteInfo> {
		self.path_index.get(path).map(|&idx| &self.routes[idx])
	}

	/// Find a route by name
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);
	///
	/// let route = inspector.find_by_name("users:list").unwrap();
	/// assert_eq!(route.path, "/users/");
	/// ```
	pub fn find_by_name(&self, name: &str) -> Option<&RouteInfo> {
		self.name_index.get(name).map(|&idx| &self.routes[idx])
	}

	/// Find routes by path prefix
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/api/v1/users/", vec![Method::GET], None::<String>, None);
	/// inspector.add_route("/api/v1/posts/", vec![Method::GET], None::<String>, None);
	/// inspector.add_route("/api/v2/users/", vec![Method::GET], None::<String>, None);
	///
	/// let routes = inspector.find_by_path_prefix("/api/v1");
	/// assert_eq!(routes.len(), 2);
	/// ```
	pub fn find_by_path_prefix(&self, prefix: &str) -> Vec<&RouteInfo> {
		self.routes
			.iter()
			.filter(|route| route.path.starts_with(prefix))
			.collect()
	}

	/// Find routes by namespace
	///
	/// Finds all routes in the specified namespace or any of its child namespaces.
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/api/users/", vec![Method::GET], Some("api:v1:users:list"), None);
	/// inspector.add_route("/api/posts/", vec![Method::GET], Some("api:v1:posts:list"), None);
	/// inspector.add_route("/api/users/", vec![Method::GET], Some("api:v2:users:list"), None);
	///
	/// let routes = inspector.find_by_namespace("api:v1");
	/// assert_eq!(routes.len(), 2);
	/// ```
	pub fn find_by_namespace(&self, namespace: &str) -> Vec<&RouteInfo> {
		self.routes
			.iter()
			.filter(|route| {
				route
					.namespace
					.as_ref()
					.map(|ns| {
						// Match exact namespace or child namespaces
						ns == namespace || ns.starts_with(&format!("{}:", namespace))
					})
					.unwrap_or(false)
			})
			.collect()
	}

	/// Find routes by HTTP method
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], None::<String>, None);
	/// inspector.add_route("/users/", vec![Method::POST], None::<String>, None);
	/// inspector.add_route("/posts/", vec![Method::GET], None::<String>, None);
	///
	/// let routes = inspector.find_by_method(&Method::GET);
	/// assert_eq!(routes.len(), 2);
	/// ```
	pub fn find_by_method(&self, method: &Method) -> Vec<&RouteInfo> {
		self.routes
			.iter()
			.filter(|route| route.supports_method(method))
			.collect()
	}

	/// Get all unique namespaces at all hierarchy levels
	///
	/// Returns all namespace prefixes found in routes, including parent namespaces.
	/// For example, if routes have namespaces "api:v1:users" and "api:v1:posts",
	/// this will return ["api", "api:v1", "api:v1:posts", "api:v1:users"].
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("api:v1:users:list"), None);
	/// inspector.add_route("/posts/", vec![Method::GET], Some("api:v1:posts:list"), None);
	/// inspector.add_route("/users/", vec![Method::GET], Some("api:v2:users:list"), None);
	///
	/// let namespaces = inspector.all_namespaces();
	/// assert!(namespaces.contains(&"api".to_string()));
	/// assert!(namespaces.contains(&"api:v1".to_string()));
	/// assert!(namespaces.contains(&"api:v2".to_string()));
	/// ```
	pub fn all_namespaces(&self) -> Vec<String> {
		let mut namespaces = HashSet::new();

		for route in &self.routes {
			if let Some(ref ns_str) = route.namespace {
				// Add all levels of the namespace hierarchy
				let parts: Vec<&str> = ns_str.split(':').collect();
				let mut current_path = String::new();
				for part in parts {
					if !current_path.is_empty() {
						current_path.push(':');
					}
					current_path.push_str(part);
					namespaces.insert(current_path.clone());
				}
			}
		}

		let mut result: Vec<String> = namespaces.into_iter().collect();
		result.sort();
		result
	}

	/// Get all unique HTTP methods used
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET, Method::POST], None::<String>, None);
	/// inspector.add_route("/posts/", vec![Method::GET, Method::DELETE], None::<String>, None);
	///
	/// let methods = inspector.all_methods();
	/// assert!(methods.contains(&Method::GET));
	/// assert!(methods.contains(&Method::POST));
	/// assert!(methods.contains(&Method::DELETE));
	/// ```
	pub fn all_methods(&self) -> Vec<Method> {
		let mut methods: HashSet<String> = HashSet::new();
		for route in &self.routes {
			for method in &route.methods {
				methods.insert(method.clone());
			}
		}

		let mut result: Vec<Method> = methods.into_iter().filter_map(|m| m.parse().ok()).collect();
		result.sort_by(|a, b| a.as_str().cmp(b.as_str()));
		result
	}

	/// Get route statistics
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("api:users:list"), None);
	/// inspector.add_route("/posts/", vec![Method::GET], Some("api:posts:list"), None);
	///
	/// let stats = inspector.statistics();
	/// assert_eq!(stats.total_routes, 2);
	/// assert_eq!(stats.total_namespaces, 3);
	/// ```
	pub fn statistics(&self) -> RouteStatistics {
		let total_routes = self.routes.len();
		let total_namespaces = self.all_namespaces().len();
		let total_methods = self.all_methods().len();

		let routes_with_params = self
			.routes
			.iter()
			.filter(|route| !route.params.is_empty())
			.count();

		let routes_with_names = self
			.routes
			.iter()
			.filter(|route| route.name.is_some())
			.count();

		RouteStatistics {
			total_routes,
			total_namespaces,
			total_methods,
			routes_with_params,
			routes_with_names,
		}
	}

	/// Get the number of registered routes
	pub fn route_count(&self) -> usize {
		self.routes.len()
	}

	/// Export routes as JSON
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);
	///
	/// let json = inspector.to_json().unwrap();
	/// assert!(json.contains("users:list"));
	/// ```
	pub fn to_json(&self) -> Result<String, serde_json::Error> {
		serde_json::to_string_pretty(&self.routes)
	}

	/// Export routes as YAML
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_urls::routers::introspection::RouteInspector;
	/// use hyper::Method;
	///
	/// let mut inspector = RouteInspector::new();
	/// inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);
	///
	/// let yaml = inspector.to_yaml().unwrap();
	/// assert!(yaml.contains("users:list"));
	/// ```
	pub fn to_yaml(&self) -> Result<String, serde_yaml::Error> {
		serde_yaml::to_string(&self.routes)
	}
}

impl Default for RouteInspector {
	fn default() -> Self {
		Self::new()
	}
}

/// Statistics about registered routes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteStatistics {
	/// Total number of routes
	pub total_routes: usize,

	/// Total number of unique namespaces
	pub total_namespaces: usize,

	/// Total number of unique HTTP methods
	pub total_methods: usize,

	/// Number of routes with parameters
	pub routes_with_params: usize,

	/// Number of routes with names
	pub routes_with_names: usize,
}

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

	#[test]
	fn test_route_info_creation() {
		let info = RouteInfo::new("/users/{id}/", vec![Method::GET], Some("users:detail"));

		assert_eq!(info.path, "/users/{id}/");
		assert_eq!(info.params, vec!["id"]);
		assert_eq!(info.name, Some("users:detail".to_string()));
		assert_eq!(info.namespace, Some("users".to_string()));
		assert_eq!(info.route_name, Some("detail".to_string()));
	}

	#[test]
	fn test_route_info_supports_method() {
		let info = RouteInfo::new("/users/", vec![Method::GET, Method::POST], None::<String>);

		assert!(info.supports_method(&Method::GET));
		assert!(info.supports_method(&Method::POST));
		assert!(!info.supports_method(&Method::DELETE));
	}

	#[test]
	fn test_route_info_metadata() {
		let mut info = RouteInfo::new("/users/", vec![Method::GET], None::<String>);
		info.add_metadata("description", "List users");

		assert_eq!(
			info.metadata.get("description"),
			Some(&"List users".to_string())
		);
	}

	#[test]
	fn test_route_inspector_add_and_count() {
		let mut inspector = RouteInspector::new();
		inspector.add_route(
			"/users/",
			vec![Method::GET],
			None::<String>,
			None::<std::collections::HashMap<String, String>>,
		);
		inspector.add_route(
			"/posts/",
			vec![Method::GET],
			None::<String>,
			None::<std::collections::HashMap<String, String>>,
		);

		assert_eq!(inspector.route_count(), 2);
	}

	#[test]
	fn test_route_inspector_find_by_path() {
		let mut inspector = RouteInspector::new();
		inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);

		let route = inspector.find_by_path("/users/").unwrap();
		assert_eq!(route.name, Some("users:list".to_string()));
	}

	#[test]
	fn test_route_inspector_find_by_name() {
		let mut inspector = RouteInspector::new();
		inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);

		let route = inspector.find_by_name("users:list").unwrap();
		assert_eq!(route.path, "/users/");
	}

	#[test]
	fn test_route_inspector_find_by_prefix() {
		let mut inspector = RouteInspector::new();
		inspector.add_route(
			"/api/v1/users/",
			vec![Method::GET],
			None::<String>,
			None::<std::collections::HashMap<String, String>>,
		);
		inspector.add_route(
			"/api/v1/posts/",
			vec![Method::GET],
			None::<String>,
			None::<std::collections::HashMap<String, String>>,
		);
		inspector.add_route(
			"/api/v2/users/",
			vec![Method::GET],
			None::<String>,
			None::<std::collections::HashMap<String, String>>,
		);

		let routes = inspector.find_by_path_prefix("/api/v1");
		assert_eq!(routes.len(), 2);
	}

	#[test]
	fn test_route_inspector_find_by_namespace() {
		let mut inspector = RouteInspector::new();
		inspector.add_route(
			"/users/",
			vec![Method::GET],
			Some("api:v1:users:list"),
			None,
		);
		inspector.add_route(
			"/posts/",
			vec![Method::GET],
			Some("api:v1:posts:list"),
			None,
		);
		inspector.add_route(
			"/users/",
			vec![Method::GET],
			Some("api:v2:users:list"),
			None,
		);

		let routes = inspector.find_by_namespace("api:v1");
		assert_eq!(routes.len(), 2);
	}

	#[test]
	fn test_route_inspector_all_namespaces() {
		let mut inspector = RouteInspector::new();
		inspector.add_route(
			"/users/",
			vec![Method::GET],
			Some("api:v1:users:list"),
			None,
		);
		inspector.add_route(
			"/posts/",
			vec![Method::GET],
			Some("api:v2:posts:list"),
			None,
		);

		let namespaces = inspector.all_namespaces();
		// Should return all hierarchy levels: api, api:v1, api:v1:users, api:v2, api:v2:posts
		assert_eq!(namespaces.len(), 5);
		assert!(namespaces.contains(&"api".to_string()));
		assert!(namespaces.contains(&"api:v1".to_string()));
		assert!(namespaces.contains(&"api:v1:users".to_string()));
		assert!(namespaces.contains(&"api:v2".to_string()));
		assert!(namespaces.contains(&"api:v2:posts".to_string()));
	}

	#[test]
	fn test_route_inspector_statistics() {
		let mut inspector = RouteInspector::new();
		inspector.add_route("/users/", vec![Method::GET], Some("api:users:list"), None);
		inspector.add_route(
			"/users/{id}/",
			vec![Method::GET],
			Some("api:users:detail"),
			None,
		);

		let stats = inspector.statistics();
		assert_eq!(stats.total_routes, 2);
		assert_eq!(stats.routes_with_params, 1);
		assert_eq!(stats.routes_with_names, 2);
	}

	#[test]
	fn test_route_inspector_to_json() {
		let mut inspector = RouteInspector::new();
		inspector.add_route("/users/", vec![Method::GET], Some("users:list"), None);

		let json = inspector.to_json().unwrap();
		assert!(json.contains("users:list"));
	}
}