This repository was archived by the owner on Feb 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ itertools = { workspace = true }
1919libmath = { workspace = true }
2020stopwatch = { workspace = true }
2121utoipa = { workspace = true }
22+ lazy_static = " 1.4.0"
2223
2324app = { path = " ./src/lib/app" }
2425utils = { path = " ./src/lib/utils" }
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ pub async fn docs(_request: ParsedRequest) -> APIResponse {
4747 } ) )
4848}
4949
50- pub async fn openapi_spec ( openapi : OpenApi ) -> APIResponse {
50+ pub async fn openapi_spec ( openapi : & OpenApi ) -> APIResponse {
5151 let json_spec_orig_serialized = openapi. to_json ( ) . expect ( "Failed to parse openapi spec" ) ;
5252
5353 // Inject the app specific securitySchemas to the spec as a workaround for utoipa::OpenApi zeroing the parse_meta output of derived OpenApi structs when using the security attribute
Original file line number Diff line number Diff line change 1+ use futures:: { future:: BoxFuture , FutureExt } ;
2+ use lazy_static:: lazy_static;
3+ use utoipa:: OpenApi ;
4+
15use app:: {
26 responses:: APIResponse ,
37 router:: { OpenApiRouter , ParsedRequest } ,
48} ;
5- use futures:: { future:: BoxFuture , FutureExt } ;
6- use utoipa:: OpenApi ;
79
810pub mod application;
911pub mod jmf;
@@ -54,12 +56,18 @@ pub mod testbed;
5456) ]
5557struct Api ;
5658
59+ // Create a singleton instance of the router components
60+ lazy_static ! {
61+ static ref OPENAPI_INSTANCE : utoipa:: openapi:: OpenApi = Api :: openapi( ) ;
62+ static ref ROUTER_INSTANCE : Api = Api ;
63+ }
64+
5765/**
5866 * API router
5967 */
6068pub async fn get_router_response ( parsed_request : ParsedRequest ) -> APIResponse {
61- let openapi = Api :: openapi ( ) ; // @TODO: ensure as singelton
62- let router = Api ;
69+ let openapi = & * OPENAPI_INSTANCE ;
70+ let router = & * ROUTER_INSTANCE ;
6371
6472 match ( parsed_request. method . as_str ( ) , parsed_request. path . as_str ( ) ) {
6573 // System routes
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ pub trait OpenApiRouter {
2727 closure ( )
2828 }
2929
30- fn handle ( & self , openapi : OpenApi , parsed_request : ParsedRequest ) -> Self :: FutureType {
30+ fn handle ( & self , openapi : & OpenApi , parsed_request : ParsedRequest ) -> Self :: FutureType {
3131 // Resolve the operation id
3232 let operation_id = get_openapi_operation_id (
3333 openapi,
@@ -77,7 +77,7 @@ pub fn parse_router_request(request: Request) -> ParsedRequest {
7777pub mod openapi {
7878 use utoipa:: openapi:: { OpenApi , PathItem , PathItemType } ;
7979
80- pub fn get_openapi_operation_id ( openapi : OpenApi , method : & str , path : & str ) -> String {
80+ pub fn get_openapi_operation_id ( openapi : & OpenApi , method : & str , path : & str ) -> String {
8181 let path = openapi. paths . get_path_item ( path) ;
8282 match path {
8383 Some ( path) => resolve_operation_id ( path, method) ,
You can’t perform that action at this time.
0 commit comments