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