@@ -32,15 +32,19 @@ impl RustApi {
3232 pub fn new ( ) -> Self {
3333 // Initialize tracing if not already done
3434 let _ = tracing_subscriber:: registry ( )
35- . with ( EnvFilter :: try_from_default_env ( ) . unwrap_or_else ( |_| {
36- EnvFilter :: new ( "info,rustapi=debug" )
37- } ) )
35+ . with (
36+ EnvFilter :: try_from_default_env ( )
37+ . unwrap_or_else ( |_| EnvFilter :: new ( "info,rustapi=debug" ) ) ,
38+ )
3839 . with ( tracing_subscriber:: fmt:: layer ( ) )
3940 . try_init ( ) ;
4041
4142 Self {
4243 router : Router :: new ( ) ,
43- openapi_spec : rustapi_openapi:: OpenApiSpec :: new ( "RustAPI Application" , "1.0.0" ) ,
44+ openapi_spec : rustapi_openapi:: OpenApiSpec :: new ( "RustAPI Application" , "1.0.0" )
45+ . register :: < rustapi_openapi:: ErrorSchema > ( )
46+ . register :: < rustapi_openapi:: ValidationErrorSchema > ( )
47+ . register :: < rustapi_openapi:: FieldErrorSchema > ( ) ,
4448 }
4549 }
4650
@@ -59,17 +63,17 @@ impl RustApi {
5963 /// RustApi::new()
6064 /// .state(AppState::new())
6165 /// ```
62- pub fn state < S > ( self , state : S ) -> Self
66+ pub fn state < S > ( self , _state : S ) -> Self
6367 where
6468 S : Clone + Send + Sync + ' static ,
6569 {
66- // For now, state is handled by the router/handlers directly capturing it
67- // or through a middleware. The current router (matchit) implementation
70+ // For now, state is handled by the router/handlers directly capturing it
71+ // or through a middleware. The current router (matchit) implementation
6872 // doesn't support state injection directly in the same way axum does.
6973 // This is a placeholder for future state management.
7074 self
7175 }
72-
76+
7377 /// Register an OpenAPI schema
7478 ///
7579 /// # Example
@@ -85,7 +89,7 @@ impl RustApi {
8589 self . openapi_spec = self . openapi_spec . register :: < T > ( ) ;
8690 self
8791 }
88-
92+
8993 /// Configure OpenAPI info (title, version, description)
9094 pub fn openapi_info ( mut self , title : & str , version : & str , description : Option < & str > ) -> Self {
9195 self . openapi_spec = rustapi_openapi:: OpenApiSpec :: new ( title, version) ;
@@ -151,39 +155,46 @@ impl RustApi {
151155 } ;
152156
153157 // Register operation in OpenAPI spec
154- self . openapi_spec = self . openapi_spec . path ( route. path , route. method , route. operation ) ;
155-
158+ self . openapi_spec = self
159+ . openapi_spec
160+ . path ( route. path , route. method , route. operation ) ;
161+
156162 self . route_with_method ( route. path , method_enum, route. handler )
157163 }
158164
159165 /// Helper to mount a single method handler
160- fn route_with_method ( mut self , path : & str , method : http:: Method , handler : crate :: handler:: BoxedHandler ) -> Self {
166+ fn route_with_method (
167+ self ,
168+ path : & str ,
169+ method : http:: Method ,
170+ handler : crate :: handler:: BoxedHandler ,
171+ ) -> Self {
161172 use crate :: router:: MethodRouter ;
162173 // use http::Method; // Removed
163-
174+
164175 // This is simplified. In a real implementation we'd merge with existing router at this path
165- // For now we assume one handler per path or we simply allow overwriting for this MVP step
176+ // For now we assume one handler per path or we simply allow overwriting for this MVP step
166177 // (matchit router doesn't allow easy merging/updating existing entries without rebuilding)
167- //
178+ //
168179 // TOOD: Enhance Router to support method merging
169-
180+
170181 let path = if !path. starts_with ( '/' ) {
171182 format ! ( "/{}" , path)
172183 } else {
173184 path. to_string ( )
174185 } ;
175-
176- // Check if we already have this path?
186+
187+ // Check if we already have this path?
177188 // For MVP, valid assumption: user calls .route() or .mount() once per path-method-combo
178189 // But we need to handle multiple methods on same path.
179- // Our Router wrapper currently just inserts.
180-
190+ // Our Router wrapper currently just inserts.
191+
181192 // Since we can't easily query matchit, we'll just insert.
182193 // Limitations: strictly sequential mounting for now.
183-
194+
184195 let mut handlers = std:: collections:: HashMap :: new ( ) ;
185196 handlers. insert ( method, handler) ;
186-
197+
187198 let method_router = MethodRouter :: from_boxed ( handlers) ;
188199 self . route ( & path, method_router)
189200 }
@@ -223,7 +234,7 @@ impl RustApi {
223234 let title = self . openapi_spec . info . title . clone ( ) ;
224235 let version = self . openapi_spec . info . version . clone ( ) ;
225236 let description = self . openapi_spec . info . description . clone ( ) ;
226-
237+
227238 self . docs_with_info ( path, & title, & version, description. as_deref ( ) )
228239 }
229240
@@ -249,14 +260,15 @@ impl RustApi {
249260 if let Some ( desc) = description {
250261 self . openapi_spec . info . description = Some ( desc. to_string ( ) ) ;
251262 }
252-
263+
253264 let path = path. trim_end_matches ( '/' ) ;
254265 let openapi_path = format ! ( "{}/openapi.json" , path) ;
255-
266+
256267 // Clone values for closures
257- let spec_json = serde_json:: to_string_pretty ( & self . openapi_spec . to_json ( ) ) . unwrap_or_default ( ) ;
268+ let spec_json =
269+ serde_json:: to_string_pretty ( & self . openapi_spec . to_json ( ) ) . unwrap_or_default ( ) ;
258270 let openapi_url = openapi_path. clone ( ) ;
259-
271+
260272 // Add OpenAPI JSON endpoint
261273 let spec_handler = move || {
262274 let json = spec_json. clone ( ) ;
@@ -268,7 +280,7 @@ impl RustApi {
268280 . unwrap ( )
269281 }
270282 } ;
271-
283+
272284 // Add Swagger UI endpoint
273285 let docs_handler = move || {
274286 let url = openapi_url. clone ( ) ;
@@ -277,7 +289,7 @@ impl RustApi {
277289 html
278290 }
279291 } ;
280-
292+
281293 self . route ( & openapi_path, get ( spec_handler) )
282294 . route ( path, get ( docs_handler) )
283295 }
0 commit comments