mockforge_core/
openapi.rs1pub mod response;
12pub mod route;
13pub mod schema;
14pub mod spec;
15pub mod validation;
16
17pub use response::*;
19pub use route::*;
20pub use schema::*;
21pub use spec::*;
22pub use validation::*;
23
24#[derive(Debug, Clone)]
26pub struct OpenApiOperation {
27 pub method: String,
28 pub path: String,
29 pub operation: openapiv3::Operation,
30 pub security: Option<Vec<openapiv3::SecurityRequirement>>,
31}
32
33impl OpenApiOperation {
34 pub fn new(method: String, path: String, operation: openapiv3::Operation) -> Self {
35 Self {
36 method,
37 path,
38 operation: operation.clone(),
39 security: operation.security.clone(),
40 }
41 }
42
43 pub fn from_operation(
44 method: &str,
45 path: String,
46 operation: &openapiv3::Operation,
47 _spec: &OpenApiSpec,
48 ) -> Self {
49 Self::new(method.to_string(), path, operation.clone())
50 }
51}
52
53pub type OpenApiSecurityRequirement = openapiv3::SecurityRequirement;
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_openapi_operation_new() {
62 let operation = openapiv3::Operation::default();
63 let op = OpenApiOperation::new("GET".to_string(), "/test".to_string(), operation);
64
65 assert_eq!(op.method, "GET");
66 assert_eq!(op.path, "/test");
67 assert!(op.security.is_none());
68 }
69
70 #[test]
71 fn test_openapi_operation_with_security() {
72 let operation = openapiv3::Operation {
73 security: Some(vec![]),
74 ..Default::default()
75 };
76
77 let op = OpenApiOperation::new("POST".to_string(), "/secure".to_string(), operation);
78
79 assert_eq!(op.method, "POST");
80 assert_eq!(op.path, "/secure");
81 assert!(op.security.is_some());
82 }
83
84 #[test]
85 fn test_openapi_operation_from_operation() {
86 let operation = openapiv3::Operation::default();
87 let spec = OpenApiSpec::from_json(serde_json::json!({
88 "openapi": "3.0.0",
89 "info": {"title": "Test", "version": "1.0.0"},
90 "paths": {}
91 }))
92 .unwrap();
93
94 let op =
95 OpenApiOperation::from_operation("PUT", "/resource".to_string(), &operation, &spec);
96
97 assert_eq!(op.method, "PUT");
98 assert_eq!(op.path, "/resource");
99 }
100
101 #[test]
102 fn test_openapi_operation_clone() {
103 let operation = openapiv3::Operation::default();
104 let op1 = OpenApiOperation::new("GET".to_string(), "/test".to_string(), operation);
105 let op2 = op1.clone();
106
107 assert_eq!(op1.method, op2.method);
108 assert_eq!(op1.path, op2.path);
109 }
110}