|
1 | 1 | use async_trait::async_trait; |
2 | 2 | use loco_openapi::prelude::*; |
3 | 3 | use loco_rs::{ |
4 | | - Result, |
5 | 4 | app::{AppContext, Hooks, Initializer}, |
6 | 5 | bgworker::{BackgroundWorker, Queue}, |
7 | | - boot::{BootResult, StartMode, create_app}, |
| 6 | + boot::{create_app, BootResult, StartMode}, |
8 | 7 | config::Config, |
9 | 8 | controller::AppRoutes, |
10 | 9 | db::{self, truncate_table}, |
11 | 10 | environment::Environment, |
12 | 11 | task::Tasks, |
| 12 | + Result, |
13 | 13 | }; |
14 | 14 | use migration::Migrator; |
15 | 15 | use std::path::Path; |
@@ -42,26 +42,34 @@ impl Hooks for App { |
42 | 42 | create_app::<Self, Migrator>(mode, environment, config).await |
43 | 43 | } |
44 | 44 |
|
45 | | - async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> { |
46 | | - Ok(vec![Box::new( |
47 | | - loco_openapi::OpenapiInitializerWithSetup::new( |
48 | | - |ctx| { |
49 | | - #[derive(OpenApi)] |
50 | | - #[openapi( |
51 | | - modifiers(&SecurityAddon), |
52 | | - info( |
53 | | - title = "Loco Demo", |
54 | | - description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project." |
55 | | - ) |
56 | | - )] |
57 | | - struct ApiDoc; |
58 | | - set_jwt_location_ctx(ctx); |
| 45 | + async fn initializers(ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> { |
| 46 | + let mut initializers: Vec<Box<dyn Initializer>> = vec![]; |
| 47 | + |
| 48 | + if ctx.environment != Environment::Test { |
| 49 | + initializers.push( |
| 50 | + Box::new( |
| 51 | + loco_openapi::OpenapiInitializerWithSetup::new( |
| 52 | + |ctx| { |
| 53 | + #[derive(OpenApi)] |
| 54 | + #[openapi( |
| 55 | + modifiers(&SecurityAddon), |
| 56 | + info( |
| 57 | + title = "Loco Demo", |
| 58 | + description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project." |
| 59 | + ) |
| 60 | + )] |
| 61 | + struct ApiDoc; |
| 62 | + set_jwt_location_ctx(ctx); |
| 63 | + |
| 64 | + ApiDoc::openapi() |
| 65 | + }, |
| 66 | + None, |
| 67 | + ), |
| 68 | + ) as Box<dyn Initializer> |
| 69 | + ); |
| 70 | + } |
59 | 71 |
|
60 | | - ApiDoc::openapi() |
61 | | - }, |
62 | | - None, |
63 | | - ), |
64 | | - )]) |
| 72 | + Ok(initializers) |
65 | 73 | } |
66 | 74 |
|
67 | 75 | fn routes(_ctx: &AppContext) -> AppRoutes { |
|
0 commit comments