Skip to content

Commit

Permalink
add: openapi json and frameworks
Browse files Browse the repository at this point in the history
Signed-off-by: Mahdi Baghbani <[email protected]>
  • Loading branch information
MahdiBaghbani committed Dec 10, 2023
1 parent d9a308d commit fd273de
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions api/src/routers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use salvo::Router;

use docs::{setup_openapi, setup_swagger_ui};

use crate::routers::docs::{
setup_open_api, setup_rapidoc, setup_redoc, setup_scalar, setup_swagger,
};
use crate::schemas::AppState;

mod docs;
Expand All @@ -11,16 +12,56 @@ mod v1;

pub fn setup(app_state: &AppState, middlewares: Router) -> Router {
// merge all routers into one router.
let mut router: Router = Router::new()
.path("api")
.push(healthcheck::setup())
.push(v1::setup());
let mut router: Router = Router::new().path("api").push(healthcheck::setup());

router = middlewares.push(router);
// generate openapi.json.
router = setup_openapi(router);
// enable swagger ui.
router = setup_swagger_ui(router);

if app_state.configs.open_api.enabled {
// generate openapi.json.
let open_api_path: String = app_state.configs.open_api.url_path.clone();
router = setup_open_api(
router,
&open_api_path,
"Connect Your Books OpenAPI Document.",
"v0.0.1",
);

if app_state.configs.open_api.swagger.enabled {
// enable swagger ui.
router = setup_swagger(
router,
app_state.configs.open_api.swagger.url_path.clone(),
open_api_path.clone(),
);
}

if app_state.configs.open_api.scalar.enabled {
// enable scalar.
router = setup_scalar(
router,
app_state.configs.open_api.scalar.url_path.clone(),
open_api_path.clone(),
);
}

if app_state.configs.open_api.rapi_doc.enabled {
// enable rapidoc.
router = setup_rapidoc(
router,
app_state.configs.open_api.rapi_doc.url_path.clone(),
open_api_path.clone(),
);
}

if app_state.configs.open_api.re_doc.enabled {
// enable redoc.
router = setup_redoc(
router,
app_state.configs.open_api.re_doc.url_path.clone(),
open_api_path.clone(),
);
}
}

// push static assets into routers.
router = router.push(statics::setup_frontend(app_state.configs.frontend.clone()));
Expand Down

0 comments on commit fd273de

Please sign in to comment.