1pub mod custom_fixture;
31pub mod multi_spec;
32pub mod openapi_routes;
33pub mod request_fingerprint;
34pub mod response;
35pub mod response_rewriter;
36pub mod response_trace;
37pub mod route;
38pub mod schema;
39pub mod schema_ref_resolver;
40pub mod spec;
41pub mod spec_parser;
42pub mod swagger_convert;
43pub mod validation;
44
45pub use custom_fixture::CustomFixtureLoader;
46pub use request_fingerprint::RequestFingerprint;
47pub use response_rewriter::ResponseRewriter;
48
49pub use mockforge_foundation::response_selection;
54
55pub use response::*;
58pub use response_selection::*;
59pub use route::*;
60pub use schema::*;
61pub use spec::*;
62pub use validation::*;
63
64pub use spec_parser::{GraphQLValidator, OpenApiValidator, SpecFormat};
66
67#[derive(Debug, Clone)]
69pub struct OpenApiOperation {
70 pub method: String,
72 pub path: String,
74 pub operation: openapiv3::Operation,
76 pub security: Option<Vec<openapiv3::SecurityRequirement>>,
78}
79
80impl OpenApiOperation {
81 pub fn new(method: String, path: String, operation: openapiv3::Operation) -> Self {
83 Self {
84 method,
85 path,
86 operation: operation.clone(),
87 security: operation.security.clone(),
88 }
89 }
90
91 pub fn from_operation(
93 method: &str,
94 path: String,
95 operation: &openapiv3::Operation,
96 _spec: &OpenApiSpec,
97 ) -> Self {
98 Self::new(method.to_string(), path, operation.clone())
99 }
100}
101
102pub type OpenApiSecurityRequirement = openapiv3::SecurityRequirement;
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn test_openapi_operation_new() {
111 let operation = openapiv3::Operation::default();
112 let op = OpenApiOperation::new("GET".to_string(), "/test".to_string(), operation);
113
114 assert_eq!(op.method, "GET");
115 assert_eq!(op.path, "/test");
116 assert!(op.security.is_none());
117 }
118
119 #[test]
120 fn test_openapi_operation_with_security() {
121 let operation = openapiv3::Operation {
122 security: Some(vec![]),
123 ..Default::default()
124 };
125
126 let op = OpenApiOperation::new("POST".to_string(), "/secure".to_string(), operation);
127
128 assert_eq!(op.method, "POST");
129 assert_eq!(op.path, "/secure");
130 assert!(op.security.is_some());
131 }
132
133 #[test]
134 fn test_openapi_operation_from_operation() {
135 let operation = openapiv3::Operation::default();
136 let spec = OpenApiSpec::from_json(serde_json::json!({
137 "openapi": "3.0.0",
138 "info": {"title": "Test", "version": "1.0.0"},
139 "paths": {}
140 }))
141 .unwrap();
142
143 let op =
144 OpenApiOperation::from_operation("PUT", "/resource".to_string(), &operation, &spec);
145
146 assert_eq!(op.method, "PUT");
147 assert_eq!(op.path, "/resource");
148 }
149
150 #[test]
151 fn test_openapi_operation_clone() {
152 let operation = openapiv3::Operation::default();
153 let op1 = OpenApiOperation::new("GET".to_string(), "/test".to_string(), operation);
154 let op2 = op1.clone();
155
156 assert_eq!(op1.method, op2.method);
157 assert_eq!(op1.path, op2.path);
158 }
159}