@@ -300,3 +300,55 @@ async fn run_server(
300300 }
301301 }
302302}
303+
304+ fn generate_openapi_json ( routes : & [ ast:: Route ] ) -> serde_json:: Value {
305+ let mut openapi = serde_json:: json!( {
306+ "openapi" : "3.0.0" ,
307+ "info" : {
308+ "title" : "AIScript API" ,
309+ "version" : "1.0.0" ,
310+ "description" : "API documentation for AIScript"
311+ } ,
312+ "paths" : { } ,
313+ } ) ;
314+
315+ //Add paths from routes
316+ let paths = openapi[ "paths" ] . as_object_mut ( ) . unwrap ( ) ;
317+
318+ for route in routes {
319+ for endpoint in & route. endpoints {
320+ for path_spec in & endpoint. path_specs {
321+ let path = if route. prefix == "/" {
322+ path_spec. path . clone ( )
323+ } else {
324+ format ! ( "{}{}" , route. prefix, path_spec. path)
325+ } ;
326+
327+ let method = match path_spec. method {
328+ ast:: HttpMethod :: Get => "get" ,
329+ ast:: HttpMethod :: Post => "post" ,
330+ ast:: HttpMethod :: Put => "put" ,
331+ ast:: HttpMethod :: Delete => "delete" ,
332+ } ;
333+
334+ //For each method, add the path and method to the paths object
335+ if !paths. contains_key ( & path) {
336+ paths. insert ( path. clone ( ) , serde_json:: json!( { } ) ) ;
337+ }
338+
339+ //Add the method to the path
340+ let path_obj = paths. get_mut ( & path) . unwrap ( ) ;
341+ path_obj[ method] = serde_json:: json!( {
342+ "summary" : format!( "{} {}" , method. to_uppercase( ) , path) ,
343+ "responses" : {
344+ "200" : {
345+ "description" : "Successful response"
346+ }
347+ }
348+ } ) ;
349+ }
350+ }
351+ }
352+
353+ openapi
354+ }
0 commit comments