@@ -23,17 +23,16 @@ pub mod utils;
2323type RouterList = Option < Vec < OpenApiRouter < AppContext > > > ;
2424type InitialSpec = dyn Fn ( & AppContext ) -> OpenApi + Send + Sync + ' static ;
2525
26- /// Loco initializer for OpenAPI with custom initial spec setup
26+ /// Loco initializer for ` OpenAPI` with custom initial spec setup
2727#[ derive( Default ) ]
2828pub struct OpenapiInitializerWithSetup {
29- /// Custom setup for the initial OpenAPI spec, if any
29+ /// Custom setup for the initial ` OpenAPI` spec, if any
3030 initial_spec : Option < Box < InitialSpec > > ,
31- /// Routes to add to the OpenAPI spec
31+ /// Routes to add to the ` OpenAPI` spec
3232 routes_setup : RouterList ,
3333}
3434
3535impl OpenapiInitializerWithSetup {
36- #[ inline( always) ]
3736 #[ must_use]
3837 pub fn new < F > ( initial_spec : F , routes_setup : RouterList ) -> Self
3938 where
@@ -55,12 +54,12 @@ impl Initializer for OpenapiInitializerWithSetup {
5554 async fn after_routes ( & self , mut router : AxumRouter , ctx : & AppContext ) -> Result < AxumRouter > {
5655 set_openapi_config ( ctx) ?;
5756
58- let mut api_router: OpenApiRouter < AppContext > =
59- if let Some ( ref custom_spec_fn) = self . initial_spec {
57+ let mut api_router: OpenApiRouter < AppContext > = self
58+ . initial_spec
59+ . as_ref ( )
60+ . map_or_else ( OpenApiRouter :: new, |custom_spec_fn| {
6061 OpenApiRouter :: with_openapi ( custom_spec_fn ( ctx) )
61- } else {
62- OpenApiRouter :: new ( )
63- } ;
62+ } ) ;
6463
6564 // Merge all manually collected routes
6665 if let Some ( ref routes_setup) = self . routes_setup {
@@ -72,17 +71,15 @@ impl Initializer for OpenapiInitializerWithSetup {
7271 // Merge all automatically collected routes
7372 api_router = api_router. merge ( get_merged_router ( ) ) ;
7473
75- // Collect the OpenAPI spec
74+ // Collect the ` OpenAPI` spec
7675 let ( _, open_api_spec) = api_router. split_for_parts ( ) ;
7776 set_openapi_spec ( open_api_spec) ;
7877
79- let open_api_config = if let Some ( open_api_config) = get_openapi_config ( ) {
80- open_api_config
81- } else {
78+ let Some ( open_api_config) = get_openapi_config ( ) else {
8279 return Ok ( router) ;
8380 } ;
8481
85- // Serve the OpenAPI spec using the enabled OpenAPI visualizers
82+ // Serve the ` OpenAPI` spec using the enabled ` OpenAPI` visualizers
8683 #[ cfg( feature = "redoc" ) ]
8784 if let Some ( OpenAPIType :: Redoc {
8885 url,
0 commit comments