diff --git a/src/api/http/docs.rs b/src/api/http/docs.rs index 2c3a4af3..b794ef68 100644 --- a/src/api/http/docs.rs +++ b/src/api/http/docs.rs @@ -1,18 +1,16 @@ use crate::api::http::build_path; use crate::app::context::AppContext; -use aide::axum::routing::get_with; use aide::axum::{ApiRouter, IntoApiResponse}; use aide::openapi::OpenApi; use aide::redoc::Redoc; use aide::scalar::Scalar; use axum::extract::FromRef; use axum::response::IntoResponse; +use axum::routing::get; use axum::{Extension, Json}; use std::ops::Deref; use std::sync::Arc; -const TAG: &str = "Docs"; - /// This API is only available when using Aide. pub fn routes(parent: &str, state: &S) -> ApiRouter where @@ -27,36 +25,25 @@ where return router; } - let router = router.api_route( - &open_api_schema_path, - get_with(docs_get, |op| op.description("OpenAPI schema").tag(TAG)), - ); + let router = router.route(&open_api_schema_path, get(docs_get)); let router = if scalar_enabled(&context) { - router.api_route_with( + router.route( &build_path(parent, scalar_route(&context)), - get_with( - Scalar::new(&open_api_schema_path) - .with_title(&context.config().app.name) - .axum_handler(), - |op| op.description("Documentation page.").tag(TAG), - ), - |p| p.security_requirement("ApiKey"), + get(Scalar::new(&open_api_schema_path) + .with_title(&context.config().app.name) + .axum_handler()), ) } else { router }; let router = if redoc_enabled(&context) { - router.api_route_with( + router.route( &build_path(parent, redoc_route(&context)), - get_with( - Redoc::new(&open_api_schema_path) - .with_title(&context.config().app.name) - .axum_handler(), - |op| op.description("Redoc documentation page.").tag(TAG), - ), - |p| p.security_requirement("ApiKey"), + get(Redoc::new(&open_api_schema_path) + .with_title(&context.config().app.name) + .axum_handler()), ) } else { router diff --git a/src/service/http/builder.rs b/src/service/http/builder.rs index a5494727..f0bf5d7c 100644 --- a/src/service/http/builder.rs +++ b/src/service/http/builder.rs @@ -59,7 +59,8 @@ where let router = Router::::new(); #[cfg(feature = "open-api")] - let app_name = AppContext::from_ref(state).config().app.name.clone(); + let context = AppContext::from_ref(state); + Self { state: state.clone(), router, @@ -67,7 +68,15 @@ where api_router: default_api_routes(path_root.unwrap_or_default(), state), #[cfg(feature = "open-api")] api_docs: Box::new(move |api| { - api.title(&app_name).description(&format!("# {}", app_name)) + let api = api + .title(&context.config().app.name) + .description(&format!("# {}", context.config().app.name)); + let api = if let Some(version) = context.metadata().version.as_ref() { + api.version(version) + } else { + api + }; + api }), middleware: default_middleware(state), initializers: default_initializers(state),