pinakes-server: add utoipa annotations to all routes; fix tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
This commit is contained in:
parent
67b8322705
commit
9d58927cb4
60 changed files with 3493 additions and 242 deletions
|
|
@ -14,8 +14,10 @@ use tower_http::{
|
|||
set_header::SetResponseHeaderLayer,
|
||||
trace::TraceLayer,
|
||||
};
|
||||
use utoipa::OpenApi as _;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
use crate::{auth, routes, state::AppState};
|
||||
use crate::{api_doc::ApiDoc, auth, routes, state::AppState};
|
||||
|
||||
/// Create the router with optional TLS configuration for HSTS headers
|
||||
pub fn create_router(
|
||||
|
|
@ -51,6 +53,11 @@ pub fn create_router_with_tls(
|
|||
rate_limits: &pinakes_core::config::RateLimitConfig,
|
||||
tls_config: Option<&pinakes_core::config::TlsConfig>,
|
||||
) -> Router {
|
||||
let swagger_ui_enabled = state
|
||||
.config
|
||||
.try_read()
|
||||
.map_or(false, |cfg| cfg.server.swagger_ui);
|
||||
|
||||
let global_governor = build_governor(
|
||||
rate_limits.global_per_second,
|
||||
rate_limits.global_burst_size,
|
||||
|
|
@ -605,7 +612,7 @@ pub fn create_router_with_tls(
|
|||
HeaderValue::from_static("default-src 'none'; frame-ancestors 'none'"),
|
||||
));
|
||||
|
||||
let router = Router::new()
|
||||
let base_router = Router::new()
|
||||
.nest("/api/v1", full_api)
|
||||
.layer(DefaultBodyLimit::max(10 * 1024 * 1024))
|
||||
.layer(GovernorLayer::new(global_governor))
|
||||
|
|
@ -613,6 +620,14 @@ pub fn create_router_with_tls(
|
|||
.layer(cors)
|
||||
.layer(security_headers);
|
||||
|
||||
let router = if swagger_ui_enabled {
|
||||
base_router.merge(
|
||||
SwaggerUi::new("/api/docs").url("/api/openapi.json", ApiDoc::openapi()),
|
||||
)
|
||||
} else {
|
||||
base_router
|
||||
};
|
||||
|
||||
// Add HSTS header when TLS is enabled
|
||||
if let Some(tls) = tls_config {
|
||||
if tls.enabled && tls.hsts_enabled {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue