diff options
| author | rtkay123 <dev@kanjala.com> | 2026-03-30 12:09:10 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-03-30 12:09:10 +0200 |
| commit | 1b5622e14ca3deaf2a25ee785af656779ded7a41 (patch) | |
| tree | 9c26ce03ed2f13ccffb144714b62904e25ff6fbe | |
| parent | 562d4855e957bebf8d98b56e40cdd50beea54d84 (diff) | |
| download | warden-1b5622e14ca3deaf2a25ee785af656779ded7a41.tar.bz2 warden-1b5622e14ca3deaf2a25ee785af656779ded7a41.zip | |
feat(api): examples
| -rw-r--r-- | lib/api-config/src/schema/create.rs | 31 | ||||
| -rw-r--r-- | lib/api-config/src/schema/mod.rs | 31 | ||||
| -rw-r--r-- | warden/src/server/routes/config/logs.rs | 8 | ||||
| -rw-r--r-- | warden/src/server/routes/config/schema/create.rs | 2 | ||||
| -rw-r--r-- | warden/src/server/routes/config/schema/delete.rs | 8 | ||||
| -rw-r--r-- | warden/src/server/routes/config/schema/read.rs | 2 |
6 files changed, 77 insertions, 5 deletions
diff --git a/lib/api-config/src/schema/create.rs b/lib/api-config/src/schema/create.rs index 5c91f64..eef11f8 100644 --- a/lib/api-config/src/schema/create.rs +++ b/lib/api-config/src/schema/create.rs @@ -3,13 +3,42 @@ use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] /// Transaction to monitor +#[cfg_attr(feature = "utoipa", schema(example = json!({ + "type": "custom.schema", + "version": "1.0.0", + "json_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "FinancialTransaction", + "type": "object", + "required": ["transaction_id", "amount", "currency", "timestamp"], + "properties": { + "transaction_id": { + "type": "string", + "format": "uuid" + }, + "amount": { + "type": "number", + "exclusiveMinimum": 0 + }, + "currency": { + "type": "string", + "pattern": "^[A-Z]{3}$", + "description": "ISO 4217 Alpha-3 code (e.g., USD, EUR)" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + } + } +})))] pub struct CreateSchema { #[serde(rename = "type")] /// Transaction schema type pub kind: String, /// The schema's version pub version: String, - /// Transaction data + /// The json schema to validate for each transaction of this type and version #[serde(rename = "json_schema")] pub schema: serde_json::Value, } diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs index 1fdbcef..d1ef5f4 100644 --- a/lib/api-config/src/schema/mod.rs +++ b/lib/api-config/src/schema/mod.rs @@ -11,6 +11,37 @@ use crate::ConfigurationError; /// Transaction to monitor #[derive(Deserialize, Serialize)] #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] +#[cfg_attr(feature = "utoipa", schema(example = json!({ + "type": "custom.schema", + "version": "1.0.0", + "json_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "FinancialTransaction", + "type": "object", + "required": ["transaction_id", "amount", "currency", "timestamp"], + "properties": { + "transaction_id": { + "type": "string", + "format": "uuid" + }, + "amount": { + "type": "number", + "exclusiveMinimum": 0 + }, + "currency": { + "type": "string", + "pattern": "^[A-Z]{3}$", + "description": "ISO 4217 Alpha-3 code (e.g., USD, EUR)" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + } + }, + "created_at": time::OffsetDateTime::now_utc().format(&time::format_description::well_known::Rfc3339).unwrap(), + "updated_at": time::OffsetDateTime::now_utc().format(&time::format_description::well_known::Rfc3339).unwrap(), +})))] pub struct TransactionSchema { #[serde(rename = "type")] /// Transaction schema type diff --git a/warden/src/server/routes/config/logs.rs b/warden/src/server/routes/config/logs.rs index 6ed2736..45959c2 100644 --- a/warden/src/server/routes/config/logs.rs +++ b/warden/src/server/routes/config/logs.rs @@ -8,7 +8,15 @@ use warden_core::state::AppState; use crate::server::{api::SafeJson, routes::config::CONFIG}; #[derive(Deserialize, Debug, Clone, ToSchema)] +/// Log level pub struct LogLevel { + #[schema( + examples( + "info", + "trace", + "warden=debug,tower_http=debug,axum::rejection=trace" + ) + )] log_level: String, } diff --git a/warden/src/server/routes/config/schema/create.rs b/warden/src/server/routes/config/schema/create.rs index 91674fe..b9a3b22 100644 --- a/warden/src/server/routes/config/schema/create.rs +++ b/warden/src/server/routes/config/schema/create.rs @@ -22,7 +22,7 @@ use crate::server::{api::version::{Version, VersionPath}, error::AppError, route headers( ("x-request-id" = Uuid, description = "Request identifier") ), - body = TransactionSchema + body = TransactionSchema, ), ( status = 400, diff --git a/warden/src/server/routes/config/schema/delete.rs b/warden/src/server/routes/config/schema/delete.rs index 5d1459f..cfafb68 100644 --- a/warden/src/server/routes/config/schema/delete.rs +++ b/warden/src/server/routes/config/schema/delete.rs @@ -18,8 +18,10 @@ use crate::server::{api::version::{Version, VersionPath}, error::AppError, route pub struct SchemaDeleteQuery { /// Schema type #[serde(rename = "type")] + #[param(example = "custom.schema")] kind: String, /// Schema version + #[param(example = "1.0.0")] version: String, } @@ -28,7 +30,7 @@ pub struct SchemaDeleteQuery { delete, responses( ( - status = 200, + status = 204, description = "The schema has been deleted", headers( ("x-request-id" = Uuid, description = "Request identifier") @@ -59,7 +61,7 @@ pub struct SchemaDeleteQuery { operation_id = "delete_schema", // https://github.com/juhaku/utoipa/issues/1170 tag = CONFIG, path = "/{version}/config/schema", - params(VersionPath), + params(VersionPath, SchemaDeleteQuery), )] #[tracing::instrument( name = "delete_schema", @@ -81,5 +83,5 @@ pub async fn delete_schema( state .delete_schema(&body.kind, &body.version) .await?; - Ok(StatusCode::OK) + Ok(StatusCode::NO_CONTENT) } diff --git a/warden/src/server/routes/config/schema/read.rs b/warden/src/server/routes/config/schema/read.rs index 45b5006..17fc3e2 100644 --- a/warden/src/server/routes/config/schema/read.rs +++ b/warden/src/server/routes/config/schema/read.rs @@ -19,8 +19,10 @@ use crate::server::{api::version::{Version, VersionPath}, error::AppError, route pub struct SchemaSearchQuery { /// Schema type #[serde(rename = "type")] + #[param(example = "custom.schema")] kind: String, /// Schema version + #[param(example = "1.0.0")] version: String, } |
