spikard 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +674 -674
  4. data/ext/spikard_rb/Cargo.toml +17 -17
  5. data/ext/spikard_rb/extconf.rb +13 -10
  6. data/ext/spikard_rb/src/lib.rs +6 -6
  7. data/lib/spikard/app.rb +405 -405
  8. data/lib/spikard/background.rb +27 -27
  9. data/lib/spikard/config.rb +396 -396
  10. data/lib/spikard/converters.rb +13 -13
  11. data/lib/spikard/handler_wrapper.rb +113 -113
  12. data/lib/spikard/provide.rb +214 -214
  13. data/lib/spikard/response.rb +173 -173
  14. data/lib/spikard/schema.rb +243 -243
  15. data/lib/spikard/sse.rb +111 -111
  16. data/lib/spikard/streaming_response.rb +44 -44
  17. data/lib/spikard/testing.rb +256 -256
  18. data/lib/spikard/upload_file.rb +131 -131
  19. data/lib/spikard/version.rb +5 -5
  20. data/lib/spikard/websocket.rb +59 -59
  21. data/lib/spikard.rb +43 -43
  22. data/sig/spikard.rbs +366 -366
  23. data/vendor/crates/spikard-bindings-shared/Cargo.toml +63 -63
  24. data/vendor/crates/spikard-bindings-shared/examples/config_extraction.rs +132 -132
  25. data/vendor/crates/spikard-bindings-shared/src/config_extractor.rs +752 -752
  26. data/vendor/crates/spikard-bindings-shared/src/conversion_traits.rs +194 -194
  27. data/vendor/crates/spikard-bindings-shared/src/di_traits.rs +246 -246
  28. data/vendor/crates/spikard-bindings-shared/src/error_response.rs +401 -401
  29. data/vendor/crates/spikard-bindings-shared/src/handler_base.rs +238 -238
  30. data/vendor/crates/spikard-bindings-shared/src/lib.rs +24 -24
  31. data/vendor/crates/spikard-bindings-shared/src/lifecycle_base.rs +292 -292
  32. data/vendor/crates/spikard-bindings-shared/src/lifecycle_executor.rs +616 -616
  33. data/vendor/crates/spikard-bindings-shared/src/response_builder.rs +305 -305
  34. data/vendor/crates/spikard-bindings-shared/src/test_client_base.rs +248 -248
  35. data/vendor/crates/spikard-bindings-shared/src/validation_helpers.rs +351 -351
  36. data/vendor/crates/spikard-bindings-shared/tests/comprehensive_coverage.rs +454 -454
  37. data/vendor/crates/spikard-bindings-shared/tests/error_response_edge_cases.rs +383 -383
  38. data/vendor/crates/spikard-bindings-shared/tests/handler_base_integration.rs +280 -280
  39. data/vendor/crates/spikard-core/Cargo.toml +40 -40
  40. data/vendor/crates/spikard-core/src/bindings/mod.rs +3 -3
  41. data/vendor/crates/spikard-core/src/bindings/response.rs +133 -133
  42. data/vendor/crates/spikard-core/src/debug.rs +127 -127
  43. data/vendor/crates/spikard-core/src/di/container.rs +702 -702
  44. data/vendor/crates/spikard-core/src/di/dependency.rs +273 -273
  45. data/vendor/crates/spikard-core/src/di/error.rs +118 -118
  46. data/vendor/crates/spikard-core/src/di/factory.rs +534 -534
  47. data/vendor/crates/spikard-core/src/di/graph.rs +506 -506
  48. data/vendor/crates/spikard-core/src/di/mod.rs +192 -192
  49. data/vendor/crates/spikard-core/src/di/resolved.rs +405 -405
  50. data/vendor/crates/spikard-core/src/di/value.rs +281 -281
  51. data/vendor/crates/spikard-core/src/errors.rs +69 -69
  52. data/vendor/crates/spikard-core/src/http.rs +415 -415
  53. data/vendor/crates/spikard-core/src/lib.rs +29 -29
  54. data/vendor/crates/spikard-core/src/lifecycle.rs +1186 -1186
  55. data/vendor/crates/spikard-core/src/metadata.rs +389 -389
  56. data/vendor/crates/spikard-core/src/parameters.rs +2525 -2525
  57. data/vendor/crates/spikard-core/src/problem.rs +344 -344
  58. data/vendor/crates/spikard-core/src/request_data.rs +1154 -1154
  59. data/vendor/crates/spikard-core/src/router.rs +510 -510
  60. data/vendor/crates/spikard-core/src/schema_registry.rs +183 -183
  61. data/vendor/crates/spikard-core/src/type_hints.rs +304 -304
  62. data/vendor/crates/spikard-core/src/validation/error_mapper.rs +696 -688
  63. data/vendor/crates/spikard-core/src/validation/mod.rs +457 -457
  64. data/vendor/crates/spikard-http/Cargo.toml +62 -64
  65. data/vendor/crates/spikard-http/examples/sse-notifications.rs +148 -148
  66. data/vendor/crates/spikard-http/examples/websocket-chat.rs +92 -92
  67. data/vendor/crates/spikard-http/src/auth.rs +296 -296
  68. data/vendor/crates/spikard-http/src/background.rs +1860 -1860
  69. data/vendor/crates/spikard-http/src/bindings/mod.rs +3 -3
  70. data/vendor/crates/spikard-http/src/bindings/response.rs +1 -1
  71. data/vendor/crates/spikard-http/src/body_metadata.rs +8 -8
  72. data/vendor/crates/spikard-http/src/cors.rs +1005 -1005
  73. data/vendor/crates/spikard-http/src/debug.rs +128 -128
  74. data/vendor/crates/spikard-http/src/di_handler.rs +1668 -1668
  75. data/vendor/crates/spikard-http/src/handler_response.rs +901 -901
  76. data/vendor/crates/spikard-http/src/handler_trait.rs +838 -830
  77. data/vendor/crates/spikard-http/src/handler_trait_tests.rs +290 -290
  78. data/vendor/crates/spikard-http/src/lib.rs +534 -534
  79. data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +230 -230
  80. data/vendor/crates/spikard-http/src/lifecycle.rs +1193 -1193
  81. data/vendor/crates/spikard-http/src/middleware/mod.rs +560 -540
  82. data/vendor/crates/spikard-http/src/middleware/multipart.rs +912 -912
  83. data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +513 -513
  84. data/vendor/crates/spikard-http/src/middleware/validation.rs +768 -735
  85. data/vendor/crates/spikard-http/src/openapi/mod.rs +309 -309
  86. data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +535 -535
  87. data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +1363 -1363
  88. data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +665 -665
  89. data/vendor/crates/spikard-http/src/query_parser.rs +793 -793
  90. data/vendor/crates/spikard-http/src/response.rs +720 -720
  91. data/vendor/crates/spikard-http/src/server/handler.rs +1650 -1650
  92. data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +234 -234
  93. data/vendor/crates/spikard-http/src/server/mod.rs +1593 -1502
  94. data/vendor/crates/spikard-http/src/server/request_extraction.rs +789 -770
  95. data/vendor/crates/spikard-http/src/server/routing_factory.rs +629 -599
  96. data/vendor/crates/spikard-http/src/sse.rs +1409 -1409
  97. data/vendor/crates/spikard-http/src/testing/form.rs +52 -52
  98. data/vendor/crates/spikard-http/src/testing/multipart.rs +64 -60
  99. data/vendor/crates/spikard-http/src/testing/test_client.rs +311 -283
  100. data/vendor/crates/spikard-http/src/testing.rs +406 -377
  101. data/vendor/crates/spikard-http/src/websocket.rs +1404 -1375
  102. data/vendor/crates/spikard-http/tests/background_behavior.rs +832 -832
  103. data/vendor/crates/spikard-http/tests/common/handlers.rs +309 -309
  104. data/vendor/crates/spikard-http/tests/common/mod.rs +26 -26
  105. data/vendor/crates/spikard-http/tests/di_integration.rs +192 -192
  106. data/vendor/crates/spikard-http/tests/doc_snippets.rs +5 -5
  107. data/vendor/crates/spikard-http/tests/lifecycle_execution.rs +1093 -1093
  108. data/vendor/crates/spikard-http/tests/multipart_behavior.rs +656 -656
  109. data/vendor/crates/spikard-http/tests/server_config_builder.rs +314 -314
  110. data/vendor/crates/spikard-http/tests/sse_behavior.rs +620 -620
  111. data/vendor/crates/spikard-http/tests/websocket_behavior.rs +663 -663
  112. data/vendor/crates/spikard-rb/Cargo.toml +48 -48
  113. data/vendor/crates/spikard-rb/build.rs +199 -199
  114. data/vendor/crates/spikard-rb/src/background.rs +63 -63
  115. data/vendor/crates/spikard-rb/src/config/mod.rs +5 -5
  116. data/vendor/crates/spikard-rb/src/config/server_config.rs +285 -285
  117. data/vendor/crates/spikard-rb/src/conversion.rs +554 -554
  118. data/vendor/crates/spikard-rb/src/di/builder.rs +100 -100
  119. data/vendor/crates/spikard-rb/src/di/mod.rs +375 -375
  120. data/vendor/crates/spikard-rb/src/handler.rs +618 -618
  121. data/vendor/crates/spikard-rb/src/integration/mod.rs +3 -3
  122. data/vendor/crates/spikard-rb/src/lib.rs +1806 -1810
  123. data/vendor/crates/spikard-rb/src/lifecycle.rs +275 -275
  124. data/vendor/crates/spikard-rb/src/metadata/mod.rs +5 -5
  125. data/vendor/crates/spikard-rb/src/metadata/route_extraction.rs +442 -447
  126. data/vendor/crates/spikard-rb/src/runtime/mod.rs +5 -5
  127. data/vendor/crates/spikard-rb/src/runtime/server_runner.rs +324 -324
  128. data/vendor/crates/spikard-rb/src/server.rs +305 -308
  129. data/vendor/crates/spikard-rb/src/sse.rs +231 -231
  130. data/vendor/crates/spikard-rb/src/testing/client.rs +538 -551
  131. data/vendor/crates/spikard-rb/src/testing/mod.rs +7 -7
  132. data/vendor/crates/spikard-rb/src/testing/sse.rs +143 -143
  133. data/vendor/crates/spikard-rb/src/testing/websocket.rs +608 -635
  134. data/vendor/crates/spikard-rb/src/websocket.rs +377 -374
  135. metadata +15 -1
@@ -1,280 +1,280 @@
1
- //! Integration tests for handler_base module
2
- //!
3
- //! These tests cover the validation paths and error handling that aren't
4
- //! covered by unit tests in the module itself.
5
-
6
- use axum::body::Body;
7
- use axum::http::Request;
8
- use serde_json::json;
9
- use spikard_bindings_shared::handler_base::{HandlerError, HandlerExecutor, LanguageHandler};
10
- use spikard_core::validation::{SchemaValidator, ValidationError, ValidationErrorDetail};
11
- use spikard_http::handler_trait::{Handler, RequestData};
12
- use std::collections::HashMap;
13
- use std::future::Future;
14
- use std::pin::Pin;
15
- use std::sync::Arc;
16
-
17
- struct MockHandler {
18
- should_fail_prepare: bool,
19
- should_fail_invoke: bool,
20
- should_fail_interpret: bool,
21
- }
22
-
23
- impl LanguageHandler for MockHandler {
24
- type Input = String;
25
- type Output = String;
26
-
27
- fn prepare_request(&self, _data: &RequestData) -> Result<Self::Input, HandlerError> {
28
- if self.should_fail_prepare {
29
- Err(HandlerError::Internal("Prepare failed".to_string()))
30
- } else {
31
- Ok("prepared".to_string())
32
- }
33
- }
34
-
35
- fn invoke_handler(
36
- &self,
37
- input: Self::Input,
38
- ) -> Pin<Box<dyn Future<Output = Result<Self::Output, HandlerError>> + Send + '_>> {
39
- let should_fail = self.should_fail_invoke;
40
- Box::pin(async move {
41
- if should_fail {
42
- Err(HandlerError::Execution("Handler failed".to_string()))
43
- } else {
44
- Ok(format!("output:{}", input))
45
- }
46
- })
47
- }
48
-
49
- fn interpret_response(&self, output: Self::Output) -> Result<axum::http::Response<Body>, HandlerError> {
50
- if self.should_fail_interpret {
51
- Err(HandlerError::ResponseConversion("Interpret failed".to_string()))
52
- } else {
53
- Ok(axum::http::Response::builder()
54
- .status(200)
55
- .body(Body::from(output))
56
- .unwrap())
57
- }
58
- }
59
- }
60
-
61
- #[tokio::test]
62
- async fn test_handler_executor_with_validation_error() {
63
- let schema = json!({
64
- "type": "object",
65
- "properties": {
66
- "username": {"type": "string"},
67
- "age": {"type": "number"}
68
- },
69
- "required": ["username", "age"]
70
- });
71
- let validator = Arc::new(SchemaValidator::new(schema).unwrap());
72
-
73
- let handler = Arc::new(MockHandler {
74
- should_fail_prepare: false,
75
- should_fail_invoke: false,
76
- should_fail_interpret: false,
77
- });
78
-
79
- let executor = HandlerExecutor::new(handler, Some(validator));
80
-
81
- let request = Request::builder().body(Body::empty()).unwrap();
82
- let request_data = RequestData {
83
- path_params: Arc::new(HashMap::new()),
84
- query_params: json!({}),
85
- validated_params: None,
86
- raw_query_params: Arc::new(HashMap::new()),
87
- body: json!({"username": "john"}),
88
- raw_body: None,
89
- headers: Arc::new(HashMap::new()),
90
- cookies: Arc::new(HashMap::new()),
91
- method: "POST".to_string(),
92
- path: "/test".to_string(),
93
- dependencies: None,
94
- };
95
-
96
- let result = executor.call(request, request_data).await;
97
- assert!(result.is_err());
98
- }
99
-
100
- #[tokio::test]
101
- async fn test_handler_executor_prepare_failure() {
102
- let handler = Arc::new(MockHandler {
103
- should_fail_prepare: true,
104
- should_fail_invoke: false,
105
- should_fail_interpret: false,
106
- });
107
-
108
- let executor = HandlerExecutor::with_handler(handler);
109
-
110
- let request = Request::builder().body(Body::empty()).unwrap();
111
- let request_data = RequestData {
112
- path_params: Arc::new(HashMap::new()),
113
- query_params: json!({}),
114
- validated_params: None,
115
- raw_query_params: Arc::new(HashMap::new()),
116
- body: json!({}),
117
- raw_body: None,
118
- headers: Arc::new(HashMap::new()),
119
- cookies: Arc::new(HashMap::new()),
120
- method: "GET".to_string(),
121
- path: "/test".to_string(),
122
- dependencies: None,
123
- };
124
-
125
- let result = executor.call(request, request_data).await;
126
- assert!(result.is_err());
127
- }
128
-
129
- #[tokio::test]
130
- async fn test_handler_executor_invoke_failure() {
131
- let handler = Arc::new(MockHandler {
132
- should_fail_prepare: false,
133
- should_fail_invoke: true,
134
- should_fail_interpret: false,
135
- });
136
-
137
- let executor = HandlerExecutor::with_handler(handler);
138
-
139
- let request = Request::builder().body(Body::empty()).unwrap();
140
- let request_data = RequestData {
141
- path_params: Arc::new(HashMap::new()),
142
- query_params: json!({}),
143
- validated_params: None,
144
- raw_query_params: Arc::new(HashMap::new()),
145
- body: json!({}),
146
- raw_body: None,
147
- headers: Arc::new(HashMap::new()),
148
- cookies: Arc::new(HashMap::new()),
149
- method: "GET".to_string(),
150
- path: "/test".to_string(),
151
- dependencies: None,
152
- };
153
-
154
- let result = executor.call(request, request_data).await;
155
- assert!(result.is_err());
156
- }
157
-
158
- #[tokio::test]
159
- async fn test_handler_executor_interpret_failure() {
160
- let handler = Arc::new(MockHandler {
161
- should_fail_prepare: false,
162
- should_fail_invoke: false,
163
- should_fail_interpret: true,
164
- });
165
-
166
- let executor = HandlerExecutor::with_handler(handler);
167
-
168
- let request = Request::builder().body(Body::empty()).unwrap();
169
- let request_data = RequestData {
170
- path_params: Arc::new(HashMap::new()),
171
- query_params: json!({}),
172
- validated_params: None,
173
- raw_query_params: Arc::new(HashMap::new()),
174
- body: json!({}),
175
- raw_body: None,
176
- headers: Arc::new(HashMap::new()),
177
- cookies: Arc::new(HashMap::new()),
178
- method: "GET".to_string(),
179
- path: "/test".to_string(),
180
- dependencies: None,
181
- };
182
-
183
- let result = executor.call(request, request_data).await;
184
- assert!(result.is_err());
185
- }
186
-
187
- #[tokio::test]
188
- async fn test_handler_executor_with_request_validator() {
189
- let schema = json!({
190
- "type": "object",
191
- "properties": {
192
- "name": {"type": "string"}
193
- },
194
- "required": ["name"]
195
- });
196
- let request_validator = Arc::new(SchemaValidator::new(schema).unwrap());
197
-
198
- let handler = Arc::new(MockHandler {
199
- should_fail_prepare: false,
200
- should_fail_invoke: false,
201
- should_fail_interpret: false,
202
- });
203
-
204
- let executor = HandlerExecutor::new(handler, Some(request_validator));
205
-
206
- let request = Request::builder().body(Body::empty()).unwrap();
207
-
208
- let mut headers = HashMap::new();
209
- headers.insert("x-api-key".to_string(), "test-key".to_string());
210
-
211
- let request_data = RequestData {
212
- path_params: Arc::new(HashMap::new()),
213
- query_params: json!({}),
214
- validated_params: None,
215
- raw_query_params: Arc::new(HashMap::new()),
216
- body: json!({"name": "test"}),
217
- raw_body: None,
218
- headers: Arc::new(headers),
219
- cookies: Arc::new(HashMap::new()),
220
- method: "POST".to_string(),
221
- path: "/test".to_string(),
222
- dependencies: None,
223
- };
224
-
225
- let result = executor.call(request, request_data).await;
226
- assert!(result.is_ok());
227
- }
228
-
229
- #[test]
230
- fn test_handler_error_from_validation_error() {
231
- let validation_error = ValidationError {
232
- errors: vec![ValidationErrorDetail {
233
- error_type: "missing".to_string(),
234
- loc: vec!["body".to_string(), "field".to_string()],
235
- msg: "Field required".to_string(),
236
- input: json!(null),
237
- ctx: None,
238
- }],
239
- };
240
-
241
- let handler_error: HandlerError = validation_error.into();
242
- assert!(matches!(handler_error, HandlerError::Validation(_)));
243
- }
244
-
245
- #[tokio::test]
246
- async fn test_handler_executor_builder_pattern() {
247
- let schema = json!({
248
- "type": "object",
249
- "properties": {
250
- "email": {"type": "string", "format": "email"}
251
- }
252
- });
253
- let request_validator = Arc::new(SchemaValidator::new(schema).unwrap());
254
-
255
- let handler = Arc::new(MockHandler {
256
- should_fail_prepare: false,
257
- should_fail_invoke: false,
258
- should_fail_interpret: false,
259
- });
260
-
261
- let executor = HandlerExecutor::with_handler(handler).with_request_validator(request_validator);
262
-
263
- let request = Request::builder().body(Body::empty()).unwrap();
264
- let request_data = RequestData {
265
- path_params: Arc::new(HashMap::new()),
266
- query_params: json!({}),
267
- validated_params: None,
268
- raw_query_params: Arc::new(HashMap::new()),
269
- body: json!({"email": "test@example.com"}),
270
- raw_body: None,
271
- headers: Arc::new(HashMap::new()),
272
- cookies: Arc::new(HashMap::new()),
273
- method: "POST".to_string(),
274
- path: "/test".to_string(),
275
- dependencies: None,
276
- };
277
-
278
- let result = executor.call(request, request_data).await;
279
- assert!(result.is_ok());
280
- }
1
+ //! Integration tests for handler_base module
2
+ //!
3
+ //! These tests cover the validation paths and error handling that aren't
4
+ //! covered by unit tests in the module itself.
5
+
6
+ use axum::body::Body;
7
+ use axum::http::Request;
8
+ use serde_json::json;
9
+ use spikard_bindings_shared::handler_base::{HandlerError, HandlerExecutor, LanguageHandler};
10
+ use spikard_core::validation::{SchemaValidator, ValidationError, ValidationErrorDetail};
11
+ use spikard_http::handler_trait::{Handler, RequestData};
12
+ use std::collections::HashMap;
13
+ use std::future::Future;
14
+ use std::pin::Pin;
15
+ use std::sync::Arc;
16
+
17
+ struct MockHandler {
18
+ should_fail_prepare: bool,
19
+ should_fail_invoke: bool,
20
+ should_fail_interpret: bool,
21
+ }
22
+
23
+ impl LanguageHandler for MockHandler {
24
+ type Input = String;
25
+ type Output = String;
26
+
27
+ fn prepare_request(&self, _data: &RequestData) -> Result<Self::Input, HandlerError> {
28
+ if self.should_fail_prepare {
29
+ Err(HandlerError::Internal("Prepare failed".to_string()))
30
+ } else {
31
+ Ok("prepared".to_string())
32
+ }
33
+ }
34
+
35
+ fn invoke_handler(
36
+ &self,
37
+ input: Self::Input,
38
+ ) -> Pin<Box<dyn Future<Output = Result<Self::Output, HandlerError>> + Send + '_>> {
39
+ let should_fail = self.should_fail_invoke;
40
+ Box::pin(async move {
41
+ if should_fail {
42
+ Err(HandlerError::Execution("Handler failed".to_string()))
43
+ } else {
44
+ Ok(format!("output:{}", input))
45
+ }
46
+ })
47
+ }
48
+
49
+ fn interpret_response(&self, output: Self::Output) -> Result<axum::http::Response<Body>, HandlerError> {
50
+ if self.should_fail_interpret {
51
+ Err(HandlerError::ResponseConversion("Interpret failed".to_string()))
52
+ } else {
53
+ Ok(axum::http::Response::builder()
54
+ .status(200)
55
+ .body(Body::from(output))
56
+ .unwrap())
57
+ }
58
+ }
59
+ }
60
+
61
+ #[tokio::test]
62
+ async fn test_handler_executor_with_validation_error() {
63
+ let schema = json!({
64
+ "type": "object",
65
+ "properties": {
66
+ "username": {"type": "string"},
67
+ "age": {"type": "number"}
68
+ },
69
+ "required": ["username", "age"]
70
+ });
71
+ let validator = Arc::new(SchemaValidator::new(schema).unwrap());
72
+
73
+ let handler = Arc::new(MockHandler {
74
+ should_fail_prepare: false,
75
+ should_fail_invoke: false,
76
+ should_fail_interpret: false,
77
+ });
78
+
79
+ let executor = HandlerExecutor::new(handler, Some(validator));
80
+
81
+ let request = Request::builder().body(Body::empty()).unwrap();
82
+ let request_data = RequestData {
83
+ path_params: Arc::new(HashMap::new()),
84
+ query_params: json!({}),
85
+ validated_params: None,
86
+ raw_query_params: Arc::new(HashMap::new()),
87
+ body: json!({"username": "john"}),
88
+ raw_body: None,
89
+ headers: Arc::new(HashMap::new()),
90
+ cookies: Arc::new(HashMap::new()),
91
+ method: "POST".to_string(),
92
+ path: "/test".to_string(),
93
+ dependencies: None,
94
+ };
95
+
96
+ let result = executor.call(request, request_data).await;
97
+ assert!(result.is_err());
98
+ }
99
+
100
+ #[tokio::test]
101
+ async fn test_handler_executor_prepare_failure() {
102
+ let handler = Arc::new(MockHandler {
103
+ should_fail_prepare: true,
104
+ should_fail_invoke: false,
105
+ should_fail_interpret: false,
106
+ });
107
+
108
+ let executor = HandlerExecutor::with_handler(handler);
109
+
110
+ let request = Request::builder().body(Body::empty()).unwrap();
111
+ let request_data = RequestData {
112
+ path_params: Arc::new(HashMap::new()),
113
+ query_params: json!({}),
114
+ validated_params: None,
115
+ raw_query_params: Arc::new(HashMap::new()),
116
+ body: json!({}),
117
+ raw_body: None,
118
+ headers: Arc::new(HashMap::new()),
119
+ cookies: Arc::new(HashMap::new()),
120
+ method: "GET".to_string(),
121
+ path: "/test".to_string(),
122
+ dependencies: None,
123
+ };
124
+
125
+ let result = executor.call(request, request_data).await;
126
+ assert!(result.is_err());
127
+ }
128
+
129
+ #[tokio::test]
130
+ async fn test_handler_executor_invoke_failure() {
131
+ let handler = Arc::new(MockHandler {
132
+ should_fail_prepare: false,
133
+ should_fail_invoke: true,
134
+ should_fail_interpret: false,
135
+ });
136
+
137
+ let executor = HandlerExecutor::with_handler(handler);
138
+
139
+ let request = Request::builder().body(Body::empty()).unwrap();
140
+ let request_data = RequestData {
141
+ path_params: Arc::new(HashMap::new()),
142
+ query_params: json!({}),
143
+ validated_params: None,
144
+ raw_query_params: Arc::new(HashMap::new()),
145
+ body: json!({}),
146
+ raw_body: None,
147
+ headers: Arc::new(HashMap::new()),
148
+ cookies: Arc::new(HashMap::new()),
149
+ method: "GET".to_string(),
150
+ path: "/test".to_string(),
151
+ dependencies: None,
152
+ };
153
+
154
+ let result = executor.call(request, request_data).await;
155
+ assert!(result.is_err());
156
+ }
157
+
158
+ #[tokio::test]
159
+ async fn test_handler_executor_interpret_failure() {
160
+ let handler = Arc::new(MockHandler {
161
+ should_fail_prepare: false,
162
+ should_fail_invoke: false,
163
+ should_fail_interpret: true,
164
+ });
165
+
166
+ let executor = HandlerExecutor::with_handler(handler);
167
+
168
+ let request = Request::builder().body(Body::empty()).unwrap();
169
+ let request_data = RequestData {
170
+ path_params: Arc::new(HashMap::new()),
171
+ query_params: json!({}),
172
+ validated_params: None,
173
+ raw_query_params: Arc::new(HashMap::new()),
174
+ body: json!({}),
175
+ raw_body: None,
176
+ headers: Arc::new(HashMap::new()),
177
+ cookies: Arc::new(HashMap::new()),
178
+ method: "GET".to_string(),
179
+ path: "/test".to_string(),
180
+ dependencies: None,
181
+ };
182
+
183
+ let result = executor.call(request, request_data).await;
184
+ assert!(result.is_err());
185
+ }
186
+
187
+ #[tokio::test]
188
+ async fn test_handler_executor_with_request_validator() {
189
+ let schema = json!({
190
+ "type": "object",
191
+ "properties": {
192
+ "name": {"type": "string"}
193
+ },
194
+ "required": ["name"]
195
+ });
196
+ let request_validator = Arc::new(SchemaValidator::new(schema).unwrap());
197
+
198
+ let handler = Arc::new(MockHandler {
199
+ should_fail_prepare: false,
200
+ should_fail_invoke: false,
201
+ should_fail_interpret: false,
202
+ });
203
+
204
+ let executor = HandlerExecutor::new(handler, Some(request_validator));
205
+
206
+ let request = Request::builder().body(Body::empty()).unwrap();
207
+
208
+ let mut headers = HashMap::new();
209
+ headers.insert("x-api-key".to_string(), "test-key".to_string());
210
+
211
+ let request_data = RequestData {
212
+ path_params: Arc::new(HashMap::new()),
213
+ query_params: json!({}),
214
+ validated_params: None,
215
+ raw_query_params: Arc::new(HashMap::new()),
216
+ body: json!({"name": "test"}),
217
+ raw_body: None,
218
+ headers: Arc::new(headers),
219
+ cookies: Arc::new(HashMap::new()),
220
+ method: "POST".to_string(),
221
+ path: "/test".to_string(),
222
+ dependencies: None,
223
+ };
224
+
225
+ let result = executor.call(request, request_data).await;
226
+ assert!(result.is_ok());
227
+ }
228
+
229
+ #[test]
230
+ fn test_handler_error_from_validation_error() {
231
+ let validation_error = ValidationError {
232
+ errors: vec![ValidationErrorDetail {
233
+ error_type: "missing".to_string(),
234
+ loc: vec!["body".to_string(), "field".to_string()],
235
+ msg: "Field required".to_string(),
236
+ input: json!(null),
237
+ ctx: None,
238
+ }],
239
+ };
240
+
241
+ let handler_error: HandlerError = validation_error.into();
242
+ assert!(matches!(handler_error, HandlerError::Validation(_)));
243
+ }
244
+
245
+ #[tokio::test]
246
+ async fn test_handler_executor_builder_pattern() {
247
+ let schema = json!({
248
+ "type": "object",
249
+ "properties": {
250
+ "email": {"type": "string", "format": "email"}
251
+ }
252
+ });
253
+ let request_validator = Arc::new(SchemaValidator::new(schema).unwrap());
254
+
255
+ let handler = Arc::new(MockHandler {
256
+ should_fail_prepare: false,
257
+ should_fail_invoke: false,
258
+ should_fail_interpret: false,
259
+ });
260
+
261
+ let executor = HandlerExecutor::with_handler(handler).with_request_validator(request_validator);
262
+
263
+ let request = Request::builder().body(Body::empty()).unwrap();
264
+ let request_data = RequestData {
265
+ path_params: Arc::new(HashMap::new()),
266
+ query_params: json!({}),
267
+ validated_params: None,
268
+ raw_query_params: Arc::new(HashMap::new()),
269
+ body: json!({"email": "test@example.com"}),
270
+ raw_body: None,
271
+ headers: Arc::new(HashMap::new()),
272
+ cookies: Arc::new(HashMap::new()),
273
+ method: "POST".to_string(),
274
+ path: "/test".to_string(),
275
+ dependencies: None,
276
+ };
277
+
278
+ let result = executor.call(request, request_data).await;
279
+ assert!(result.is_ok());
280
+ }
@@ -1,40 +1,40 @@
1
- [package]
2
- name = "spikard-core"
3
- version = "0.5.0"
4
- edition = "2024"
5
- authors = ["Na'aman Hirschfeld <nhirschfeld@gmail.com>"]
6
- license = "MIT"
7
- repository = "https://github.com/Goldziher/spikard"
8
- homepage = "https://github.com/Goldziher/spikard"
9
- description = "Shared transport-agnostic primitives for Spikard runtimes"
10
- keywords = ["http", "web", "framework", "validation", "middleware"]
11
- categories = ["web-programming::http-server", "web-programming", "development-tools"]
12
- documentation = "https://docs.rs/spikard-core"
13
- readme = "README.md"
14
-
15
- [dependencies]
16
- serde = { version = "1.0", features = ["derive"] }
17
- serde_json = "1.0"
18
- tracing = "0.1"
19
- anyhow = "1.0"
20
- jsonschema = { version = "0.37", default-features = false }
21
- regex = "1"
22
- flate2 = { version = "=1.1.5", default-features = false, features = ["rust_backend"] }
23
- brotli = "8.0"
24
- http = "1.4"
25
- base64 = "0.22"
26
- serde_qs = "0.15"
27
- url = "2.5"
28
- jiff = "0.2"
29
- uuid = "1.19"
30
- indexmap = "2.12"
31
- tokio = { version = "1", optional = true, default-features = false, features = ["rt", "macros", "sync", "time"] }
32
- bytes = { version = "1.11", optional = true }
33
- thiserror = { version = "2.0", optional = true }
34
-
35
- [features]
36
- default = []
37
- di = ["dep:tokio", "dep:bytes", "dep:thiserror"]
38
-
39
- [dev-dependencies]
40
- tokio-test = "0.4"
1
+ [package]
2
+ name = "spikard-core"
3
+ version = "0.6.1"
4
+ edition = "2024"
5
+ authors = ["Na'aman Hirschfeld <nhirschfeld@gmail.com>"]
6
+ license = "MIT"
7
+ repository = "https://github.com/Goldziher/spikard"
8
+ homepage = "https://github.com/Goldziher/spikard"
9
+ description = "Shared transport-agnostic primitives for Spikard runtimes"
10
+ keywords = ["http", "web", "framework", "validation", "middleware"]
11
+ categories = ["web-programming::http-server", "web-programming", "development-tools"]
12
+ documentation = "https://docs.rs/spikard-core"
13
+ readme = "README.md"
14
+
15
+ [dependencies]
16
+ serde = { version = "1.0", features = ["derive"] }
17
+ serde_json = "1.0"
18
+ tracing = "0.1"
19
+ anyhow = "1.0"
20
+ jsonschema = { version = "0.37", default-features = false }
21
+ regex = "1"
22
+ flate2 = { version = "=1.1.5", default-features = false, features = ["rust_backend"] }
23
+ brotli = "8.0"
24
+ http = "1.4"
25
+ base64 = "0.22"
26
+ serde_qs = "0.15"
27
+ url = "2.5"
28
+ jiff = "0.2"
29
+ uuid = "1.19"
30
+ indexmap = "2.12"
31
+ tokio = { version = "1", optional = true, default-features = false, features = ["rt", "macros", "sync", "time"] }
32
+ bytes = { version = "1.11", optional = true }
33
+ thiserror = "2.0"
34
+
35
+ [features]
36
+ default = []
37
+ di = ["dep:tokio", "dep:bytes", "dep:thiserror"]
38
+
39
+ [dev-dependencies]
40
+ tokio-test = "0.4"
@@ -1,3 +1,3 @@
1
- pub mod response;
2
-
3
- pub use response::{RawResponse, StaticAsset};
1
+ pub mod response;
2
+
3
+ pub use response::{RawResponse, StaticAsset};