spikard 0.13.0 → 0.15.2

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 (207) hide show
  1. checksums.yaml +4 -4
  2. data/Steepfile +6 -0
  3. data/ext/spikard_rb/extconf.rb +1 -2
  4. data/ext/spikard_rb/{Cargo.lock → native/Cargo.lock} +819 -424
  5. data/ext/spikard_rb/native/Cargo.toml +24 -0
  6. data/ext/spikard_rb/src/lib.rs +5366 -3
  7. data/lib/spikard/native.rb +86 -0
  8. data/lib/spikard/version.rb +6 -1
  9. data/lib/spikard.rb +8 -52
  10. data/lib/spikard_rb.so +0 -0
  11. data/sig/types.rbs +427 -0
  12. metadata +14 -243
  13. data/LICENSE +0 -1
  14. data/README.md +0 -285
  15. data/ext/spikard_rb/Cargo.toml +0 -17
  16. data/lib/spikard/app.rb +0 -458
  17. data/lib/spikard/background.rb +0 -58
  18. data/lib/spikard/config.rb +0 -506
  19. data/lib/spikard/converters.rb +0 -13
  20. data/lib/spikard/grpc.rb +0 -232
  21. data/lib/spikard/handler_wrapper.rb +0 -113
  22. data/lib/spikard/provide.rb +0 -315
  23. data/lib/spikard/response.rb +0 -198
  24. data/lib/spikard/schema.rb +0 -243
  25. data/lib/spikard/sse.rb +0 -111
  26. data/lib/spikard/streaming_response.rb +0 -44
  27. data/lib/spikard/testing.rb +0 -474
  28. data/lib/spikard/upload_file.rb +0 -131
  29. data/lib/spikard/websocket.rb +0 -59
  30. data/sig/spikard.rbs +0 -739
  31. data/vendor/crates/spikard-bindings-shared/Cargo.toml +0 -75
  32. data/vendor/crates/spikard-bindings-shared/examples/config_extraction.rs +0 -132
  33. data/vendor/crates/spikard-bindings-shared/src/config_extractor.rs +0 -905
  34. data/vendor/crates/spikard-bindings-shared/src/conversion_traits.rs +0 -210
  35. data/vendor/crates/spikard-bindings-shared/src/di_traits.rs +0 -252
  36. data/vendor/crates/spikard-bindings-shared/src/error_response.rs +0 -404
  37. data/vendor/crates/spikard-bindings-shared/src/grpc_metadata.rs +0 -199
  38. data/vendor/crates/spikard-bindings-shared/src/handler_base.rs +0 -252
  39. data/vendor/crates/spikard-bindings-shared/src/json_conversion.rs +0 -829
  40. data/vendor/crates/spikard-bindings-shared/src/lazy_cache.rs +0 -587
  41. data/vendor/crates/spikard-bindings-shared/src/lib.rs +0 -33
  42. data/vendor/crates/spikard-bindings-shared/src/lifecycle_base.rs +0 -298
  43. data/vendor/crates/spikard-bindings-shared/src/lifecycle_executor.rs +0 -594
  44. data/vendor/crates/spikard-bindings-shared/src/response_builder.rs +0 -743
  45. data/vendor/crates/spikard-bindings-shared/src/response_interpreter.rs +0 -944
  46. data/vendor/crates/spikard-bindings-shared/src/test_client_base.rs +0 -260
  47. data/vendor/crates/spikard-bindings-shared/src/validation_helpers.rs +0 -369
  48. data/vendor/crates/spikard-bindings-shared/tests/config_extractor_behavior.rs +0 -192
  49. data/vendor/crates/spikard-bindings-shared/tests/error_response_edge_cases.rs +0 -383
  50. data/vendor/crates/spikard-bindings-shared/tests/full_coverage.rs +0 -459
  51. data/vendor/crates/spikard-bindings-shared/tests/handler_base_integration.rs +0 -280
  52. data/vendor/crates/spikard-bindings-shared/tests/integration_tests.rs +0 -669
  53. data/vendor/crates/spikard-core/Cargo.toml +0 -55
  54. data/vendor/crates/spikard-core/src/bindings/mod.rs +0 -3
  55. data/vendor/crates/spikard-core/src/bindings/response.rs +0 -130
  56. data/vendor/crates/spikard-core/src/debug.rs +0 -127
  57. data/vendor/crates/spikard-core/src/di/container.rs +0 -711
  58. data/vendor/crates/spikard-core/src/di/dependency.rs +0 -273
  59. data/vendor/crates/spikard-core/src/di/error.rs +0 -118
  60. data/vendor/crates/spikard-core/src/di/factory.rs +0 -548
  61. data/vendor/crates/spikard-core/src/di/graph.rs +0 -507
  62. data/vendor/crates/spikard-core/src/di/mod.rs +0 -192
  63. data/vendor/crates/spikard-core/src/di/resolved.rs +0 -428
  64. data/vendor/crates/spikard-core/src/di/value.rs +0 -282
  65. data/vendor/crates/spikard-core/src/errors.rs +0 -72
  66. data/vendor/crates/spikard-core/src/http.rs +0 -492
  67. data/vendor/crates/spikard-core/src/lib.rs +0 -29
  68. data/vendor/crates/spikard-core/src/lifecycle.rs +0 -1273
  69. data/vendor/crates/spikard-core/src/metadata.rs +0 -378
  70. data/vendor/crates/spikard-core/src/parameters.rs +0 -2546
  71. data/vendor/crates/spikard-core/src/problem.rs +0 -358
  72. data/vendor/crates/spikard-core/src/request_data.rs +0 -1146
  73. data/vendor/crates/spikard-core/src/router.rs +0 -530
  74. data/vendor/crates/spikard-core/src/schema_registry.rs +0 -197
  75. data/vendor/crates/spikard-core/src/type_hints.rs +0 -311
  76. data/vendor/crates/spikard-core/src/validation/error_mapper.rs +0 -710
  77. data/vendor/crates/spikard-core/src/validation/mod.rs +0 -470
  78. data/vendor/crates/spikard-core/tests/bindings_response_tests.rs +0 -136
  79. data/vendor/crates/spikard-core/tests/di_dependency_defaults.rs +0 -37
  80. data/vendor/crates/spikard-core/tests/error_mapper.rs +0 -761
  81. data/vendor/crates/spikard-core/tests/parameters_edge_cases.rs +0 -106
  82. data/vendor/crates/spikard-core/tests/parameters_full.rs +0 -701
  83. data/vendor/crates/spikard-core/tests/parameters_schema_and_formats.rs +0 -301
  84. data/vendor/crates/spikard-core/tests/request_data_roundtrip.rs +0 -67
  85. data/vendor/crates/spikard-core/tests/validation_coverage.rs +0 -250
  86. data/vendor/crates/spikard-core/tests/validation_error_paths.rs +0 -45
  87. data/vendor/crates/spikard-http/Cargo.toml +0 -82
  88. data/vendor/crates/spikard-http/examples/sse-notifications.rs +0 -148
  89. data/vendor/crates/spikard-http/examples/websocket-chat.rs +0 -92
  90. data/vendor/crates/spikard-http/src/auth.rs +0 -301
  91. data/vendor/crates/spikard-http/src/background.rs +0 -1859
  92. data/vendor/crates/spikard-http/src/bindings/mod.rs +0 -3
  93. data/vendor/crates/spikard-http/src/bindings/response.rs +0 -1
  94. data/vendor/crates/spikard-http/src/body_metadata.rs +0 -8
  95. data/vendor/crates/spikard-http/src/cors.rs +0 -1026
  96. data/vendor/crates/spikard-http/src/debug.rs +0 -128
  97. data/vendor/crates/spikard-http/src/di_handler.rs +0 -1672
  98. data/vendor/crates/spikard-http/src/grpc/framing.rs +0 -653
  99. data/vendor/crates/spikard-http/src/grpc/handler.rs +0 -1211
  100. data/vendor/crates/spikard-http/src/grpc/mod.rs +0 -556
  101. data/vendor/crates/spikard-http/src/grpc/service.rs +0 -706
  102. data/vendor/crates/spikard-http/src/grpc/streaming.rs +0 -319
  103. data/vendor/crates/spikard-http/src/handler_response.rs +0 -901
  104. data/vendor/crates/spikard-http/src/handler_trait.rs +0 -1015
  105. data/vendor/crates/spikard-http/src/handler_trait_tests.rs +0 -290
  106. data/vendor/crates/spikard-http/src/jsonrpc/http_handler.rs +0 -502
  107. data/vendor/crates/spikard-http/src/jsonrpc/method_registry.rs +0 -648
  108. data/vendor/crates/spikard-http/src/jsonrpc/mod.rs +0 -60
  109. data/vendor/crates/spikard-http/src/jsonrpc/openrpc.rs +0 -325
  110. data/vendor/crates/spikard-http/src/jsonrpc/protocol.rs +0 -1207
  111. data/vendor/crates/spikard-http/src/jsonrpc/router.rs +0 -2262
  112. data/vendor/crates/spikard-http/src/lib.rs +0 -566
  113. data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +0 -230
  114. data/vendor/crates/spikard-http/src/lifecycle.rs +0 -1193
  115. data/vendor/crates/spikard-http/src/middleware/mod.rs +0 -560
  116. data/vendor/crates/spikard-http/src/middleware/multipart.rs +0 -912
  117. data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +0 -513
  118. data/vendor/crates/spikard-http/src/middleware/validation.rs +0 -768
  119. data/vendor/crates/spikard-http/src/openapi/mod.rs +0 -309
  120. data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +0 -535
  121. data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +0 -1363
  122. data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +0 -667
  123. data/vendor/crates/spikard-http/src/query_parser.rs +0 -793
  124. data/vendor/crates/spikard-http/src/response.rs +0 -720
  125. data/vendor/crates/spikard-http/src/server/fast_router.rs +0 -186
  126. data/vendor/crates/spikard-http/src/server/grpc_routing.rs +0 -1243
  127. data/vendor/crates/spikard-http/src/server/handler.rs +0 -1661
  128. data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +0 -253
  129. data/vendor/crates/spikard-http/src/server/mod.rs +0 -1717
  130. data/vendor/crates/spikard-http/src/server/request_extraction.rs +0 -871
  131. data/vendor/crates/spikard-http/src/server/routing_factory.rs +0 -618
  132. data/vendor/crates/spikard-http/src/sse.rs +0 -1409
  133. data/vendor/crates/spikard-http/src/testing/form.rs +0 -52
  134. data/vendor/crates/spikard-http/src/testing/multipart.rs +0 -64
  135. data/vendor/crates/spikard-http/src/testing/test_client.rs +0 -825
  136. data/vendor/crates/spikard-http/src/testing.rs +0 -617
  137. data/vendor/crates/spikard-http/src/websocket.rs +0 -1477
  138. data/vendor/crates/spikard-http/tests/auth_integration.rs +0 -645
  139. data/vendor/crates/spikard-http/tests/background_behavior.rs +0 -832
  140. data/vendor/crates/spikard-http/tests/common/grpc_helpers.rs +0 -1012
  141. data/vendor/crates/spikard-http/tests/common/handlers.rs +0 -309
  142. data/vendor/crates/spikard-http/tests/common/mod.rs +0 -33
  143. data/vendor/crates/spikard-http/tests/common/test_builders.rs +0 -628
  144. data/vendor/crates/spikard-http/tests/di_handler_error_responses.rs +0 -162
  145. data/vendor/crates/spikard-http/tests/di_integration.rs +0 -192
  146. data/vendor/crates/spikard-http/tests/doc_snippets.rs +0 -5
  147. data/vendor/crates/spikard-http/tests/grpc_bidirectional_streaming.rs +0 -430
  148. data/vendor/crates/spikard-http/tests/grpc_client_streaming.rs +0 -738
  149. data/vendor/crates/spikard-http/tests/grpc_error_handling_test.rs +0 -652
  150. data/vendor/crates/spikard-http/tests/grpc_integration_test.rs +0 -334
  151. data/vendor/crates/spikard-http/tests/grpc_metadata_test.rs +0 -532
  152. data/vendor/crates/spikard-http/tests/grpc_server_integration.rs +0 -495
  153. data/vendor/crates/spikard-http/tests/grpc_server_streaming.rs +0 -975
  154. data/vendor/crates/spikard-http/tests/lifecycle_execution.rs +0 -1093
  155. data/vendor/crates/spikard-http/tests/middleware_stack_integration.rs +0 -389
  156. data/vendor/crates/spikard-http/tests/multipart_behavior.rs +0 -656
  157. data/vendor/crates/spikard-http/tests/request_extraction_full.rs +0 -513
  158. data/vendor/crates/spikard-http/tests/server_auth_middleware_behavior.rs +0 -328
  159. data/vendor/crates/spikard-http/tests/server_config_builder.rs +0 -335
  160. data/vendor/crates/spikard-http/tests/server_configured_router_behavior.rs +0 -374
  161. data/vendor/crates/spikard-http/tests/server_cors_preflight.rs +0 -83
  162. data/vendor/crates/spikard-http/tests/server_handler_wrappers.rs +0 -464
  163. data/vendor/crates/spikard-http/tests/server_method_router_additional_behavior.rs +0 -286
  164. data/vendor/crates/spikard-http/tests/server_method_router_coverage.rs +0 -118
  165. data/vendor/crates/spikard-http/tests/server_middleware_behavior.rs +0 -99
  166. data/vendor/crates/spikard-http/tests/server_middleware_branches.rs +0 -204
  167. data/vendor/crates/spikard-http/tests/server_openapi_jsonrpc_static.rs +0 -427
  168. data/vendor/crates/spikard-http/tests/server_router_behavior.rs +0 -121
  169. data/vendor/crates/spikard-http/tests/sse_behavior.rs +0 -620
  170. data/vendor/crates/spikard-http/tests/sse_full_behavior.rs +0 -584
  171. data/vendor/crates/spikard-http/tests/sse_handler_behavior.rs +0 -130
  172. data/vendor/crates/spikard-http/tests/test_client_requests.rs +0 -167
  173. data/vendor/crates/spikard-http/tests/testing_helpers.rs +0 -87
  174. data/vendor/crates/spikard-http/tests/testing_module_coverage.rs +0 -155
  175. data/vendor/crates/spikard-http/tests/urlencoded_content_type.rs +0 -82
  176. data/vendor/crates/spikard-http/tests/websocket_behavior.rs +0 -663
  177. data/vendor/crates/spikard-http/tests/websocket_full_behavior.rs +0 -440
  178. data/vendor/crates/spikard-http/tests/websocket_integration.rs +0 -150
  179. data/vendor/crates/spikard-rb/Cargo.toml +0 -63
  180. data/vendor/crates/spikard-rb/build.rs +0 -200
  181. data/vendor/crates/spikard-rb/src/background.rs +0 -63
  182. data/vendor/crates/spikard-rb/src/config/mod.rs +0 -5
  183. data/vendor/crates/spikard-rb/src/config/server_config.rs +0 -401
  184. data/vendor/crates/spikard-rb/src/conversion.rs +0 -688
  185. data/vendor/crates/spikard-rb/src/di/builder.rs +0 -100
  186. data/vendor/crates/spikard-rb/src/di/mod.rs +0 -410
  187. data/vendor/crates/spikard-rb/src/grpc/handler.rs +0 -875
  188. data/vendor/crates/spikard-rb/src/grpc/mod.rs +0 -13
  189. data/vendor/crates/spikard-rb/src/gvl.rs +0 -80
  190. data/vendor/crates/spikard-rb/src/handler.rs +0 -699
  191. data/vendor/crates/spikard-rb/src/integration/mod.rs +0 -3
  192. data/vendor/crates/spikard-rb/src/lib.rs +0 -2268
  193. data/vendor/crates/spikard-rb/src/lifecycle.rs +0 -334
  194. data/vendor/crates/spikard-rb/src/metadata/mod.rs +0 -5
  195. data/vendor/crates/spikard-rb/src/metadata/route_extraction.rs +0 -507
  196. data/vendor/crates/spikard-rb/src/request.rs +0 -439
  197. data/vendor/crates/spikard-rb/src/runtime/mod.rs +0 -5
  198. data/vendor/crates/spikard-rb/src/runtime/server_runner.rs +0 -368
  199. data/vendor/crates/spikard-rb/src/server.rs +0 -304
  200. data/vendor/crates/spikard-rb/src/sse.rs +0 -231
  201. data/vendor/crates/spikard-rb/src/testing/client.rs +0 -698
  202. data/vendor/crates/spikard-rb/src/testing/mod.rs +0 -7
  203. data/vendor/crates/spikard-rb/src/testing/sse.rs +0 -108
  204. data/vendor/crates/spikard-rb/src/testing/websocket.rs +0 -573
  205. data/vendor/crates/spikard-rb/src/websocket.rs +0 -521
  206. data/vendor/crates/spikard-rb-macros/Cargo.toml +0 -20
  207. data/vendor/crates/spikard-rb-macros/src/lib.rs +0 -51
@@ -1,905 +0,0 @@
1
- //! Configuration extraction trait and implementation for language bindings
2
- //!
3
- //! This module provides a trait-based abstraction for extracting `ServerConfig` and related
4
- //! configuration structs from language-specific objects (Python dicts, JavaScript objects, etc.)
5
- //! without duplicating extraction logic across bindings.
6
- //!
7
- //! The `ConfigSource` trait allows language bindings to implement a unified interface for
8
- //! reading configuration, while `ConfigExtractor` provides the actual extraction logic that
9
- //! works with any `ConfigSource` implementation.
10
-
11
- use spikard_http::{
12
- ApiKeyConfig, CompressionConfig, ContactInfo, JsonRpcConfig, JwtConfig, LicenseInfo, OpenApiConfig,
13
- RateLimitConfig, SecuritySchemeInfo, ServerConfig, ServerInfo, StaticFilesConfig,
14
- };
15
- use std::collections::HashMap;
16
-
17
- /// Trait for reading configuration from language-specific objects
18
- ///
19
- /// Bindings implement this trait to provide unified access to configuration values
20
- /// regardless of the language-specific representation (`PyDict`, JavaScript Object, etc.).
21
- pub trait ConfigSource {
22
- /// Get a boolean value from the source
23
- fn get_bool(&self, key: &str) -> Option<bool>;
24
-
25
- /// Get a u64 value from the source
26
- fn get_u64(&self, key: &str) -> Option<u64>;
27
-
28
- /// Get a u16 value from the source
29
- fn get_u16(&self, key: &str) -> Option<u16>;
30
-
31
- /// Get a string value from the source
32
- fn get_string(&self, key: &str) -> Option<String>;
33
-
34
- /// Get a vector of strings from the source
35
- fn get_vec_string(&self, key: &str) -> Option<Vec<String>>;
36
-
37
- /// Get a nested `ConfigSource` for nested objects
38
- fn get_nested(&self, key: &str) -> Option<Box<dyn ConfigSource + '_>>;
39
-
40
- /// Check if a key exists in the source
41
- fn has_key(&self, key: &str) -> bool;
42
-
43
- /// Get array length (for collection iteration)
44
- fn get_array_length(&self, _key: &str) -> Option<usize> {
45
- None
46
- }
47
-
48
- /// Get element at index from array
49
- fn get_array_element(&self, _key: &str, _index: usize) -> Option<Box<dyn ConfigSource + '_>> {
50
- None
51
- }
52
-
53
- /// Get keys from a map/object field
54
- fn get_map_keys(&self, _key: &str) -> Option<Vec<String>> {
55
- None
56
- }
57
-
58
- /// Get map/object entry as nested `ConfigSource`
59
- fn get_map_entry(&self, _key: &str, _entry_key: &str) -> Option<Box<dyn ConfigSource + '_>> {
60
- None
61
- }
62
-
63
- /// Get u32 value from the source (helper for common case)
64
- fn get_u32(&self, key: &str) -> Option<u32> {
65
- self.get_u64(key).and_then(|v| u32::try_from(v).ok())
66
- }
67
-
68
- /// Get usize value from the source (helper)
69
- fn get_usize(&self, key: &str) -> Option<usize> {
70
- self.get_u64(key).and_then(|v| usize::try_from(v).ok())
71
- }
72
- }
73
-
74
- /// Configuration extractor that works with any `ConfigSource`
75
- pub struct ConfigExtractor;
76
-
77
- impl ConfigExtractor {
78
- /// Extract a complete `ServerConfig` from a `ConfigSource`
79
- ///
80
- /// # Errors
81
- ///
82
- /// Returns an error if required configuration fields are invalid or missing.
83
- pub fn extract_server_config(source: &dyn ConfigSource) -> Result<ServerConfig, String> {
84
- let mut config = ServerConfig::default();
85
-
86
- if let Some(host) = source.get_string("host").or_else(|| source.get_string("Host")) {
87
- config.host = host;
88
- }
89
-
90
- if let Some(port) = source.get_u16("port").or_else(|| {
91
- source.get_u32("port").map(|p| {
92
- #[allow(clippy::cast_possible_truncation)]
93
- {
94
- p as u16
95
- }
96
- })
97
- }) {
98
- config.port = port;
99
- }
100
-
101
- if let Some(workers) = source
102
- .get_usize("workers")
103
- .or_else(|| source.get_u32("workers").map(|w| w as usize))
104
- {
105
- config.workers = workers;
106
- }
107
-
108
- if let Some(enable_request_id) = source.get_bool("enable_request_id") {
109
- config.enable_request_id = enable_request_id;
110
- }
111
-
112
- // `max_body_size = 0` is treated as unlimited.
113
- if let Some(max_body_size) = source
114
- .get_usize("max_body_size")
115
- .or_else(|| source.get_u32("max_body_size").map(|v| v as usize))
116
- {
117
- config.max_body_size = if max_body_size == 0 { None } else { Some(max_body_size) };
118
- }
119
-
120
- if let Some(request_timeout) = source.get_u64("request_timeout") {
121
- config.request_timeout = Some(request_timeout);
122
- }
123
-
124
- if let Some(graceful_shutdown) = source.get_bool("graceful_shutdown") {
125
- config.graceful_shutdown = graceful_shutdown;
126
- }
127
-
128
- if let Some(shutdown_timeout) = source.get_u64("shutdown_timeout") {
129
- config.shutdown_timeout = shutdown_timeout;
130
- }
131
-
132
- config.compression = source
133
- .get_nested("compression")
134
- .and_then(|cfg| Self::extract_compression_config(cfg.as_ref()).ok());
135
-
136
- config.rate_limit = source
137
- .get_nested("rate_limit")
138
- .and_then(|cfg| Self::extract_rate_limit_config(cfg.as_ref()).ok());
139
-
140
- config.jwt_auth = source
141
- .get_nested("jwt_auth")
142
- .and_then(|cfg| Self::extract_jwt_config(cfg.as_ref()).ok());
143
-
144
- config.api_key_auth = source
145
- .get_nested("api_key_auth")
146
- .and_then(|cfg| Self::extract_api_key_config(cfg.as_ref()).ok());
147
-
148
- config.static_files = Self::extract_static_files_config(source)?;
149
-
150
- config.openapi = source
151
- .get_nested("openapi")
152
- .and_then(|cfg| Self::extract_openapi_config(cfg.as_ref()).ok());
153
-
154
- config.jsonrpc = source
155
- .get_nested("jsonrpc")
156
- .and_then(|cfg| Self::extract_jsonrpc_config(cfg.as_ref()).ok());
157
-
158
- if let Some(enable_http_trace) = source.get_bool("enable_http_trace") {
159
- config.enable_http_trace = enable_http_trace;
160
- }
161
-
162
- Ok(config)
163
- }
164
-
165
- /// Extract `CompressionConfig` from a `ConfigSource`
166
- ///
167
- /// # Errors
168
- ///
169
- /// Returns an error if required configuration fields are invalid.
170
- pub fn extract_compression_config(source: &dyn ConfigSource) -> Result<CompressionConfig, String> {
171
- let gzip = source.get_bool("gzip").unwrap_or(true);
172
- let brotli = source.get_bool("brotli").unwrap_or(true);
173
- let min_size = source
174
- .get_usize("min_size")
175
- .or_else(|| source.get_u32("min_size").map(|s| s as usize))
176
- .unwrap_or(1024);
177
- let quality = source.get_u32("quality").unwrap_or(6);
178
-
179
- Ok(CompressionConfig {
180
- gzip,
181
- brotli,
182
- min_size,
183
- quality,
184
- })
185
- }
186
-
187
- /// Extract `RateLimitConfig` from a `ConfigSource`
188
- ///
189
- /// # Errors
190
- ///
191
- /// Returns an error if required fields `per_second` or `burst` are missing.
192
- pub fn extract_rate_limit_config(source: &dyn ConfigSource) -> Result<RateLimitConfig, String> {
193
- let per_second = source.get_u64("per_second").ok_or("Rate limit requires 'per_second'")?;
194
-
195
- let burst = source.get_u32("burst").ok_or("Rate limit requires 'burst' as u32")?;
196
-
197
- let ip_based = source.get_bool("ip_based").unwrap_or(true);
198
-
199
- Ok(RateLimitConfig {
200
- per_second,
201
- burst,
202
- ip_based,
203
- })
204
- }
205
-
206
- /// Extract `JwtConfig` from a `ConfigSource`
207
- ///
208
- /// # Errors
209
- ///
210
- /// Returns an error if the required `secret` field is missing.
211
- pub fn extract_jwt_config(source: &dyn ConfigSource) -> Result<JwtConfig, String> {
212
- let secret = source.get_string("secret").ok_or("JWT auth requires 'secret'")?;
213
-
214
- let algorithm = source.get_string("algorithm").unwrap_or_else(|| "HS256".to_string());
215
-
216
- let audience = source.get_vec_string("audience");
217
-
218
- let issuer = source.get_string("issuer");
219
-
220
- let leeway = source.get_u64("leeway").unwrap_or(0);
221
-
222
- Ok(JwtConfig {
223
- secret,
224
- algorithm,
225
- audience,
226
- issuer,
227
- leeway,
228
- })
229
- }
230
-
231
- /// Extract `ApiKeyConfig` from a `ConfigSource`
232
- ///
233
- /// # Errors
234
- ///
235
- /// Returns an error if the required `keys` field is missing.
236
- pub fn extract_api_key_config(source: &dyn ConfigSource) -> Result<ApiKeyConfig, String> {
237
- let keys = source
238
- .get_vec_string("keys")
239
- .ok_or("API Key auth requires 'keys' as Vec<String>)")?;
240
-
241
- let header_name = source
242
- .get_string("header_name")
243
- .unwrap_or_else(|| "X-API-Key".to_string());
244
-
245
- Ok(ApiKeyConfig { keys, header_name })
246
- }
247
-
248
- /// Extract static files configuration list from a `ConfigSource`
249
- ///
250
- /// # Errors
251
- ///
252
- /// Returns an error if array elements are invalid or missing required fields.
253
- pub fn extract_static_files_config(source: &dyn ConfigSource) -> Result<Vec<StaticFilesConfig>, String> {
254
- let length = source.get_array_length("static_files").unwrap_or(0);
255
- if length == 0 {
256
- return Ok(Vec::new());
257
- }
258
-
259
- let mut configs = Vec::new();
260
- for i in 0..length {
261
- let sf_source = source
262
- .get_array_element("static_files", i)
263
- .ok_or("Failed to get static files array element")?;
264
-
265
- let directory = sf_source
266
- .get_string("directory")
267
- .ok_or("Static files requires 'directory'")?;
268
-
269
- let route_prefix = sf_source
270
- .get_string("route_prefix")
271
- .ok_or("Static files requires 'route_prefix'")?;
272
-
273
- let index_file = sf_source.get_bool("index_file").unwrap_or(true);
274
-
275
- let cache_control = sf_source.get_string("cache_control");
276
-
277
- configs.push(StaticFilesConfig {
278
- directory,
279
- route_prefix,
280
- index_file,
281
- cache_control,
282
- });
283
- }
284
-
285
- Ok(configs)
286
- }
287
-
288
- /// Extract `OpenApiConfig` from a `ConfigSource`
289
- ///
290
- /// # Errors
291
- ///
292
- /// Returns an error if required configuration fields are invalid.
293
- pub fn extract_openapi_config(source: &dyn ConfigSource) -> Result<OpenApiConfig, String> {
294
- let enabled = source.get_bool("enabled").unwrap_or(false);
295
- let title = source.get_string("title").unwrap_or_else(|| "API".to_string());
296
- let version = source.get_string("version").unwrap_or_else(|| "1.0.0".to_string());
297
- let description = source.get_string("description");
298
- let swagger_ui_path = source
299
- .get_string("swagger_ui_path")
300
- .unwrap_or_else(|| "/docs".to_string());
301
- let redoc_path = source.get_string("redoc_path").unwrap_or_else(|| "/redoc".to_string());
302
- let openapi_json_path = source
303
- .get_string("openapi_json_path")
304
- .unwrap_or_else(|| "/openapi.json".to_string());
305
-
306
- let contact = source
307
- .get_nested("contact")
308
- .map(|cfg| {
309
- let name = cfg.get_string("name");
310
- let email = cfg.get_string("email");
311
- let url = cfg.get_string("url");
312
- ContactInfo { name, email, url }
313
- })
314
- .filter(|c| c.name.is_some() || c.email.is_some() || c.url.is_some());
315
-
316
- let license = source.get_nested("license").and_then(|cfg| {
317
- let name = cfg.get_string("name")?;
318
- let url = cfg.get_string("url");
319
- Some(LicenseInfo { name, url })
320
- });
321
-
322
- let servers = Self::extract_servers_config(source)?;
323
-
324
- let security_schemes = Self::extract_security_schemes_config(source);
325
-
326
- Ok(OpenApiConfig {
327
- enabled,
328
- title,
329
- version,
330
- description,
331
- swagger_ui_path,
332
- redoc_path,
333
- openapi_json_path,
334
- contact,
335
- license,
336
- servers,
337
- security_schemes,
338
- })
339
- }
340
-
341
- /// Extract servers list from `OpenAPI` config
342
- ///
343
- /// # Errors
344
- ///
345
- /// Returns an error if array elements are invalid or missing.
346
- fn extract_servers_config(source: &dyn ConfigSource) -> Result<Vec<ServerInfo>, String> {
347
- let length = source.get_array_length("servers").unwrap_or(0);
348
- if length == 0 {
349
- return Ok(Vec::new());
350
- }
351
-
352
- let mut servers = Vec::new();
353
- for i in 0..length {
354
- let server_source = source
355
- .get_array_element("servers", i)
356
- .ok_or("Failed to get servers array element")?;
357
-
358
- let url = server_source.get_string("url").ok_or("Server requires 'url'")?;
359
-
360
- let description = server_source.get_string("description");
361
-
362
- servers.push(ServerInfo { url, description });
363
- }
364
-
365
- Ok(servers)
366
- }
367
-
368
- /// Extract security schemes from `OpenAPI` config
369
- fn extract_security_schemes_config(source: &dyn ConfigSource) -> HashMap<String, SecuritySchemeInfo> {
370
- let key = if source.has_key("security_schemes") {
371
- "security_schemes"
372
- } else if source.has_key("securitySchemes") {
373
- "securitySchemes"
374
- } else {
375
- return HashMap::new();
376
- };
377
-
378
- let mut schemes = HashMap::new();
379
- let scheme_names = source.get_map_keys(key).unwrap_or_default();
380
-
381
- for name in scheme_names {
382
- let Some(scheme) = source.get_map_entry(key, &name) else {
383
- continue;
384
- };
385
-
386
- let Some(scheme_type) = scheme.get_string("type") else {
387
- continue;
388
- };
389
-
390
- match scheme_type.as_str() {
391
- "http" => {
392
- let Some(http_scheme) = scheme.get_string("scheme") else {
393
- continue;
394
- };
395
- let bearer_format = scheme
396
- .get_string("bearer_format")
397
- .or_else(|| scheme.get_string("bearerFormat"));
398
- schemes.insert(
399
- name,
400
- SecuritySchemeInfo::Http {
401
- scheme: http_scheme,
402
- bearer_format,
403
- },
404
- );
405
- }
406
- "apiKey" => {
407
- let Some(location) = scheme.get_string("location") else {
408
- continue;
409
- };
410
- let Some(param_name) = scheme.get_string("name") else {
411
- continue;
412
- };
413
- schemes.insert(
414
- name,
415
- SecuritySchemeInfo::ApiKey {
416
- location,
417
- name: param_name,
418
- },
419
- );
420
- }
421
- _ => {}
422
- }
423
- }
424
-
425
- schemes
426
- }
427
-
428
- /// Extract `JsonRpcConfig` from a `ConfigSource`
429
- ///
430
- /// # Errors
431
- ///
432
- /// Returns an error if required configuration fields are invalid.
433
- pub fn extract_jsonrpc_config(source: &dyn ConfigSource) -> Result<JsonRpcConfig, String> {
434
- let enabled = source.get_bool("enabled").unwrap_or(true);
435
- let endpoint_path = source.get_string("endpoint_path").unwrap_or_else(|| "/rpc".to_string());
436
- let enable_batch = source.get_bool("enable_batch").unwrap_or(true);
437
- let max_batch_size = source
438
- .get_usize("max_batch_size")
439
- .or_else(|| source.get_u32("max_batch_size").map(|s| s as usize))
440
- .unwrap_or(100);
441
-
442
- Ok(JsonRpcConfig {
443
- enabled,
444
- endpoint_path,
445
- enable_batch,
446
- max_batch_size,
447
- })
448
- }
449
- }
450
-
451
- #[cfg(test)]
452
- mod tests {
453
- use super::*;
454
- use serde_json::Value;
455
-
456
- struct MockConfigSource {
457
- data: HashMap<String, String>,
458
- }
459
-
460
- impl MockConfigSource {
461
- fn new() -> Self {
462
- Self { data: HashMap::new() }
463
- }
464
-
465
- fn with(mut self, key: &str, value: String) -> Self {
466
- self.data.insert(key.to_string(), value);
467
- self
468
- }
469
- }
470
-
471
- impl ConfigSource for MockConfigSource {
472
- fn get_bool(&self, key: &str) -> Option<bool> {
473
- self.data.get(key).and_then(|v| match v.as_str() {
474
- "true" => Some(true),
475
- "false" => Some(false),
476
- _ => v.parse().ok(),
477
- })
478
- }
479
-
480
- fn get_u64(&self, key: &str) -> Option<u64> {
481
- self.data.get(key).and_then(|v| v.parse().ok())
482
- }
483
-
484
- fn get_u16(&self, key: &str) -> Option<u16> {
485
- self.data.get(key).and_then(|v| v.parse().ok())
486
- }
487
-
488
- fn get_string(&self, key: &str) -> Option<String> {
489
- self.data.get(key).cloned()
490
- }
491
-
492
- fn get_vec_string(&self, key: &str) -> Option<Vec<String>> {
493
- self.data
494
- .get(key)
495
- .map(|s| s.split(',').map(|t| t.trim().to_string()).collect())
496
- }
497
-
498
- fn get_nested(&self, _key: &str) -> Option<Box<dyn ConfigSource + '_>> {
499
- None
500
- }
501
-
502
- fn has_key(&self, key: &str) -> bool {
503
- self.data.contains_key(key)
504
- }
505
- }
506
-
507
- #[test]
508
- fn test_compression_config_extraction() {
509
- let source = MockConfigSource::new()
510
- .with("gzip", "true".to_string())
511
- .with("brotli", "false".to_string())
512
- .with("min_size", "2048".to_string())
513
- .with("quality", "9".to_string());
514
-
515
- let config = ConfigExtractor::extract_compression_config(&source).unwrap();
516
- assert!(config.gzip);
517
- assert!(!config.brotli);
518
- assert_eq!(config.min_size, 2048);
519
- assert_eq!(config.quality, 9);
520
- }
521
-
522
- #[test]
523
- fn test_compression_config_defaults() {
524
- let source = MockConfigSource::new();
525
-
526
- let config = ConfigExtractor::extract_compression_config(&source).unwrap();
527
- assert!(config.gzip);
528
- assert!(config.brotli);
529
- assert_eq!(config.min_size, 1024);
530
- assert_eq!(config.quality, 6);
531
- }
532
-
533
- #[test]
534
- fn test_jwt_config_extraction() {
535
- let source = MockConfigSource::new()
536
- .with("secret", "my-secret".to_string())
537
- .with("algorithm", "HS512".to_string())
538
- .with("leeway", "30".to_string());
539
-
540
- let config = ConfigExtractor::extract_jwt_config(&source).unwrap();
541
- assert_eq!(config.secret, "my-secret");
542
- assert_eq!(config.algorithm, "HS512");
543
- assert_eq!(config.leeway, 30);
544
- }
545
-
546
- #[test]
547
- fn test_jwt_config_missing_secret() {
548
- let source = MockConfigSource::new();
549
- let result = ConfigExtractor::extract_jwt_config(&source);
550
- assert!(result.is_err());
551
- }
552
-
553
- #[test]
554
- fn test_api_key_config_extraction() {
555
- let source = MockConfigSource::new()
556
- .with("keys", "key1,key2,key3".to_string())
557
- .with("header_name", "Authorization".to_string());
558
-
559
- let config = ConfigExtractor::extract_api_key_config(&source).unwrap();
560
- assert_eq!(config.keys, vec!["key1", "key2", "key3"]);
561
- assert_eq!(config.header_name, "Authorization");
562
- }
563
-
564
- #[test]
565
- fn test_api_key_config_defaults() {
566
- let source = MockConfigSource::new().with("keys", "only-key".to_string());
567
-
568
- let config = ConfigExtractor::extract_api_key_config(&source).unwrap();
569
- assert_eq!(config.keys, vec!["only-key"]);
570
- assert_eq!(config.header_name, "X-API-Key");
571
- }
572
-
573
- #[test]
574
- fn test_rate_limit_config_extraction() {
575
- let source = MockConfigSource::new()
576
- .with("per_second", "100".to_string())
577
- .with("burst", "50".to_string())
578
- .with("ip_based", "false".to_string());
579
-
580
- let config = ConfigExtractor::extract_rate_limit_config(&source).unwrap();
581
- assert_eq!(config.per_second, 100);
582
- assert_eq!(config.burst, 50);
583
- assert!(!config.ip_based);
584
- }
585
-
586
- #[test]
587
- fn test_rate_limit_config_missing_required() {
588
- let source = MockConfigSource::new().with("per_second", "100".to_string());
589
-
590
- let result = ConfigExtractor::extract_rate_limit_config(&source);
591
- assert!(result.is_err());
592
- }
593
-
594
- #[test]
595
- fn test_openapi_config_extraction() {
596
- let source = MockConfigSource::new()
597
- .with("enabled", "true".to_string())
598
- .with("title", "Test API".to_string())
599
- .with("version", "2.0.0".to_string())
600
- .with("description", "A test API".to_string())
601
- .with("swagger_ui_path", "/api-docs".to_string())
602
- .with("redoc_path", "/api-redoc".to_string())
603
- .with("openapi_json_path", "/api.json".to_string());
604
-
605
- let config = ConfigExtractor::extract_openapi_config(&source).unwrap();
606
- assert!(config.enabled);
607
- assert_eq!(config.title, "Test API");
608
- assert_eq!(config.version, "2.0.0");
609
- assert_eq!(config.description, Some("A test API".to_string()));
610
- assert_eq!(config.swagger_ui_path, "/api-docs");
611
- assert_eq!(config.redoc_path, "/api-redoc");
612
- assert_eq!(config.openapi_json_path, "/api.json");
613
- }
614
-
615
- #[test]
616
- fn test_openapi_config_defaults() {
617
- let source = MockConfigSource::new();
618
-
619
- let config = ConfigExtractor::extract_openapi_config(&source).unwrap();
620
- assert!(!config.enabled);
621
- assert_eq!(config.title, "API");
622
- assert_eq!(config.version, "1.0.0");
623
- assert_eq!(config.description, None);
624
- assert_eq!(config.swagger_ui_path, "/docs");
625
- assert_eq!(config.redoc_path, "/redoc");
626
- assert_eq!(config.openapi_json_path, "/openapi.json");
627
- }
628
-
629
- #[test]
630
- fn test_static_files_config_empty() {
631
- let source = MockConfigSource::new();
632
-
633
- let configs = ConfigExtractor::extract_static_files_config(&source).unwrap();
634
- assert_eq!(configs.len(), 0);
635
- }
636
-
637
- #[test]
638
- fn test_server_config_extraction() {
639
- let source = MockConfigSource::new()
640
- .with("host", "0.0.0.0".to_string())
641
- .with("port", "3000".to_string())
642
- .with("workers", "4".to_string())
643
- .with("enable_request_id", "false".to_string())
644
- .with("max_body_size", "5242880".to_string())
645
- .with("request_timeout", "60".to_string())
646
- .with("graceful_shutdown", "false".to_string())
647
- .with("shutdown_timeout", "10".to_string());
648
-
649
- let config = ConfigExtractor::extract_server_config(&source).unwrap();
650
- assert_eq!(config.host, "0.0.0.0");
651
- assert_eq!(config.port, 3000);
652
- assert_eq!(config.workers, 4);
653
- assert!(!config.enable_request_id);
654
- assert_eq!(config.max_body_size, Some(5_242_880));
655
- assert_eq!(config.request_timeout, Some(60));
656
- assert!(!config.graceful_shutdown);
657
- assert_eq!(config.shutdown_timeout, 10);
658
- }
659
-
660
- #[test]
661
- fn test_server_config_defaults() {
662
- let source = MockConfigSource::new();
663
-
664
- let config = ConfigExtractor::extract_server_config(&source).unwrap();
665
- assert_eq!(config.host, "127.0.0.1");
666
- assert_eq!(config.port, 8000);
667
- assert_eq!(config.workers, 1);
668
- assert!(!config.enable_request_id);
669
- assert_eq!(config.max_body_size, Some(10 * 1024 * 1024));
670
- assert_eq!(config.request_timeout, None);
671
- assert!(config.graceful_shutdown);
672
- assert_eq!(config.shutdown_timeout, 30);
673
- }
674
-
675
- #[test]
676
- fn test_servers_config_empty() {
677
- let source = MockConfigSource::new();
678
-
679
- let servers = ConfigExtractor::extract_servers_config(&source).unwrap();
680
- assert_eq!(servers.len(), 0);
681
- }
682
-
683
- #[test]
684
- fn test_security_schemes_config_empty() {
685
- let source = MockConfigSource::new();
686
-
687
- let schemes = ConfigExtractor::extract_security_schemes_config(&source);
688
- assert_eq!(schemes.len(), 0);
689
- }
690
-
691
- struct JsonConfigSource<'a> {
692
- value: &'a Value,
693
- }
694
-
695
- impl<'a> JsonConfigSource<'a> {
696
- fn new(value: &'a Value) -> Self {
697
- Self { value }
698
- }
699
- }
700
-
701
- impl ConfigSource for JsonConfigSource<'_> {
702
- fn get_bool(&self, key: &str) -> Option<bool> {
703
- self.value.get(key)?.as_bool()
704
- }
705
-
706
- fn get_u64(&self, key: &str) -> Option<u64> {
707
- self.value.get(key)?.as_u64()
708
- }
709
-
710
- fn get_u16(&self, key: &str) -> Option<u16> {
711
- u16::try_from(self.get_u64(key)?).ok()
712
- }
713
-
714
- fn get_string(&self, key: &str) -> Option<String> {
715
- self.value.get(key)?.as_str().map(str::to_string)
716
- }
717
-
718
- fn get_vec_string(&self, key: &str) -> Option<Vec<String>> {
719
- self.value
720
- .get(key)?
721
- .as_array()
722
- .map(|arr| arr.iter().filter_map(|v| v.as_str().map(str::to_string)).collect())
723
- }
724
-
725
- fn get_nested(&self, key: &str) -> Option<Box<dyn ConfigSource + '_>> {
726
- let nested = self.value.get(key)?;
727
- nested
728
- .is_object()
729
- .then(|| Box::new(JsonConfigSource::new(nested)) as Box<dyn ConfigSource>)
730
- }
731
-
732
- fn has_key(&self, key: &str) -> bool {
733
- self.value.get(key).is_some()
734
- }
735
-
736
- fn get_array_length(&self, key: &str) -> Option<usize> {
737
- self.value.get(key)?.as_array().map(Vec::len)
738
- }
739
-
740
- fn get_array_element(&self, key: &str, index: usize) -> Option<Box<dyn ConfigSource + '_>> {
741
- let arr = self.value.get(key)?.as_array()?;
742
- let elem = arr.get(index)?;
743
- elem.is_object()
744
- .then(|| Box::new(JsonConfigSource::new(elem)) as Box<dyn ConfigSource>)
745
- }
746
-
747
- fn get_map_keys(&self, key: &str) -> Option<Vec<String>> {
748
- let map = self.value.get(key)?.as_object()?;
749
- Some(map.keys().cloned().collect())
750
- }
751
-
752
- fn get_map_entry(&self, key: &str, entry_key: &str) -> Option<Box<dyn ConfigSource + '_>> {
753
- let map = self.value.get(key)?.as_object()?;
754
- let entry = map.get(entry_key)?;
755
- entry
756
- .is_object()
757
- .then(|| Box::new(JsonConfigSource::new(entry)) as Box<dyn ConfigSource>)
758
- }
759
- }
760
-
761
- #[test]
762
- fn test_static_files_extraction_supports_arrays() {
763
- let value = serde_json::json!({
764
- "static_files": [
765
- {
766
- "directory": "public",
767
- "route_prefix": "/assets",
768
- "index_file": true,
769
- "cache_control": "public, max-age=3600"
770
- }
771
- ]
772
- });
773
- let source = JsonConfigSource::new(&value);
774
- let configs = ConfigExtractor::extract_static_files_config(&source).expect("extract");
775
- assert_eq!(configs.len(), 1);
776
- assert_eq!(configs[0].directory, "public");
777
- assert_eq!(configs[0].route_prefix, "/assets");
778
- assert!(configs[0].index_file);
779
- assert_eq!(configs[0].cache_control.as_deref(), Some("public, max-age=3600"));
780
- }
781
-
782
- #[test]
783
- fn test_security_schemes_config_extracts_http_and_api_key() {
784
- let value = serde_json::json!({
785
- "security_schemes": {
786
- "bearerAuth": {
787
- "type": "http",
788
- "scheme": "bearer",
789
- "bearer_format": "JWT"
790
- },
791
- "apiKeyAuth": {
792
- "type": "apiKey",
793
- "location": "header",
794
- "name": "X-API-Key"
795
- }
796
- }
797
- });
798
- let source = JsonConfigSource::new(&value);
799
-
800
- let schemes = ConfigExtractor::extract_security_schemes_config(&source);
801
- assert_eq!(schemes.len(), 2);
802
-
803
- match schemes.get("bearerAuth") {
804
- Some(SecuritySchemeInfo::Http { scheme, bearer_format }) => {
805
- assert_eq!(scheme, "bearer");
806
- assert_eq!(bearer_format.as_deref(), Some("JWT"));
807
- }
808
- _ => panic!("expected bearerAuth HTTP security scheme"),
809
- }
810
-
811
- match schemes.get("apiKeyAuth") {
812
- Some(SecuritySchemeInfo::ApiKey { location, name }) => {
813
- assert_eq!(location, "header");
814
- assert_eq!(name, "X-API-Key");
815
- }
816
- _ => panic!("expected apiKeyAuth API key security scheme"),
817
- }
818
- }
819
-
820
- #[test]
821
- fn test_static_files_extraction_missing_required_fields_errors() {
822
- let value = serde_json::json!({
823
- "static_files": [
824
- {
825
- "route_prefix": "/assets"
826
- }
827
- ]
828
- });
829
- let source = JsonConfigSource::new(&value);
830
- let err = ConfigExtractor::extract_static_files_config(&source).expect_err("missing directory should error");
831
- assert!(
832
- err.contains("Static files requires 'directory'"),
833
- "unexpected error: {err}"
834
- );
835
- }
836
-
837
- #[test]
838
- fn test_static_files_extraction_array_element_missing_errors() {
839
- struct BrokenArraySource;
840
-
841
- impl ConfigSource for BrokenArraySource {
842
- fn get_bool(&self, _key: &str) -> Option<bool> {
843
- None
844
- }
845
-
846
- fn get_u64(&self, _key: &str) -> Option<u64> {
847
- None
848
- }
849
-
850
- fn get_u16(&self, _key: &str) -> Option<u16> {
851
- None
852
- }
853
-
854
- fn get_string(&self, _key: &str) -> Option<String> {
855
- None
856
- }
857
-
858
- fn get_vec_string(&self, _key: &str) -> Option<Vec<String>> {
859
- None
860
- }
861
-
862
- fn get_nested(&self, _key: &str) -> Option<Box<dyn ConfigSource + '_>> {
863
- None
864
- }
865
-
866
- fn has_key(&self, _key: &str) -> bool {
867
- false
868
- }
869
-
870
- fn get_array_length(&self, key: &str) -> Option<usize> {
871
- (key == "static_files").then_some(1)
872
- }
873
-
874
- fn get_array_element(&self, _key: &str, _index: usize) -> Option<Box<dyn ConfigSource + '_>> {
875
- None
876
- }
877
- }
878
-
879
- let err = ConfigExtractor::extract_static_files_config(&BrokenArraySource)
880
- .expect_err("missing array element should error");
881
- assert!(
882
- err.contains("Failed to get static files array element"),
883
- "unexpected error: {err}"
884
- );
885
- }
886
-
887
- #[test]
888
- fn test_server_config_prefers_host_key_variants() {
889
- let value = serde_json::json!({
890
- "Host": "0.0.0.0",
891
- "port": 9000,
892
- "workers": 2,
893
- "enable_request_id": false,
894
- "graceful_shutdown": true,
895
- "shutdown_timeout": 1,
896
- "static_files": []
897
- });
898
- let source = JsonConfigSource::new(&value);
899
- let cfg = ConfigExtractor::extract_server_config(&source).expect("extract");
900
- assert_eq!(cfg.host, "0.0.0.0");
901
- assert_eq!(cfg.port, 9000);
902
- assert_eq!(cfg.workers, 2);
903
- assert!(!cfg.enable_request_id);
904
- }
905
- }