refactor: Conditionalize utoipa and flate2 based on features

Conditionalize `utoipa::ToSchema` derives and `#[schema]` attributes on the `server` feature, and `flate2` usage on the `gzip` feature, allowing compilation when these features are disabled.

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 17:21:48 -03:00
parent 8848227837
commit 6a4936d8d4
4 changed files with 39 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
use std::path::PathBuf;
use strum::IntoEnumIterator;
#[cfg(feature = "server")]
use utoipa::ToSchema;
use crate::compression_engine;
@@ -10,14 +11,14 @@ use crate::meta_plugin::MetaPluginType;
use crate::filter_plugin::FilterOption;
#[derive(serde::Serialize, serde::Deserialize, ToSchema, Clone)]
#[derive(serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] ToSchema, Clone)]
pub struct FilterPluginInfo {
pub name: String,
pub options: Vec<FilterOption>,
pub description: String,
}
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] ToSchema)]
pub struct StatusInfo {
pub paths: PathInfo,
pub compression: Vec<CompressionInfo>,
@@ -27,13 +28,13 @@ pub struct StatusInfo {
pub configured_meta_plugins: Option<Vec<crate::config::MetaPluginConfig>>,
}
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] ToSchema)]
pub struct PathInfo {
pub data: String,
pub database: String,
}
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] ToSchema)]
pub struct CompressionInfo {
#[serde(rename = "type")]
pub compression_type: String,
@@ -44,7 +45,7 @@ pub struct CompressionInfo {
pub decompress: String,
}
#[derive(serde::Serialize, serde::Deserialize, ToSchema, Clone)]
#[derive(serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] ToSchema, Clone)]
pub struct MetaPluginInfo {
pub meta_name: String,
pub outputs: std::collections::HashMap<String, serde_yaml::Value>,

View File

@@ -1,3 +1,4 @@
#[cfg(feature = "gzip")]
/// GZip compression engine module.
///
/// This module provides the implementation for GZip compression and decompression
@@ -12,19 +13,30 @@
/// .expect("GZip engine creation failed");
/// let reader = engine.open("/path/to/file.gz".into()).expect("Open failed");
/// ```
#[cfg(feature = "gzip")]
use anyhow::Result;
#[cfg(feature = "gzip")]
use log::*;
#[cfg(feature = "gzip")]
use std::fs::File;
#[cfg(feature = "gzip")]
use std::io;
#[cfg(feature = "gzip")]
use std::io::{Read, Write};
#[cfg(feature = "gzip")]
use std::path::PathBuf;
#[cfg(feature = "gzip")]
use flate2::Compression;
#[cfg(feature = "gzip")]
use flate2::read::GzDecoder;
#[cfg(feature = "gzip")]
use flate2::write::GzEncoder;
#[cfg(feature = "gzip")]
use crate::compression_engine::CompressionEngine;
#[cfg(feature = "gzip")]
#[derive(Debug, Eq, PartialEq, Clone, Default)]
/// GZip compression engine implementation.
///
@@ -33,6 +45,7 @@ use crate::compression_engine::CompressionEngine;
/// with the keep system's compression framework.
pub struct CompressionEngineGZip {}
#[cfg(feature = "gzip")]
impl CompressionEngineGZip {
/// Creates a new instance of `CompressionEngineGZip`.
///
@@ -50,6 +63,7 @@ impl CompressionEngineGZip {
}
}
#[cfg(feature = "gzip")]
impl CompressionEngine for CompressionEngineGZip {
/// Checks if GZip compression is supported.
///
@@ -132,6 +146,7 @@ impl CompressionEngine for CompressionEngineGZip {
}
}
#[cfg(feature = "gzip")]
#[derive(Debug)]
/// Wrapper around `GzEncoder` that automatically finishes the compression stream on drop.
///
@@ -141,6 +156,7 @@ pub struct AutoFinishGzEncoder<W: Write> {
encoder: Option<GzEncoder<W>>,
}
#[cfg(feature = "gzip")]
impl<W: Write> AutoFinishGzEncoder<W> {
/// Creates a new `AutoFinishGzEncoder` wrapping the given GZip encoder.
///
@@ -166,6 +182,7 @@ impl<W: Write> AutoFinishGzEncoder<W> {
}
}
#[cfg(feature = "gzip")]
impl<W: Write> Drop for AutoFinishGzEncoder<W> {
/// Automatically finishes the GZip encoding when the writer is dropped.
///
@@ -183,6 +200,7 @@ impl<W: Write> Drop for AutoFinishGzEncoder<W> {
}
}
#[cfg(feature = "gzip")]
impl<W: Write> Write for AutoFinishGzEncoder<W> {
/// Writes data to the underlying GZip encoder.
///

View File

@@ -153,15 +153,24 @@ pub struct CompressionPluginConfig {
pub name: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Debug, Clone, Deserialize, Serialize, #[cfg(feature = "server")] utoipa::ToSchema)]
#[cfg_attr(not(feature = "server"), derive(Debug, Clone, Deserialize, Serialize))]
pub struct MetaPluginConfig {
pub name: String,
#[cfg(feature = "server")]
#[schema(value_type = Object)]
#[serde(default)]
pub options: std::collections::HashMap<String, serde_yaml::Value>,
#[cfg(not(feature = "server"))]
#[serde(default)]
pub options: std::collections::HashMap<String, serde_yaml::Value>,
#[cfg(feature = "server")]
#[schema(value_type = Object)]
#[serde(default)]
pub outputs: std::collections::HashMap<String, String>,
#[cfg(not(feature = "server"))]
#[serde(default)]
pub outputs: std::collections::HashMap<String, String>,
}
/// Unified settings that merges config file and CLI arguments

View File

@@ -40,11 +40,15 @@ pub use strip_ansi::StripAnsiFilter;
/// * `name` - Option name.
/// * `default` - Optional default value.
/// * `required` - If true, must be provided.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, #[cfg(feature = "server")] utoipa::ToSchema)]
#[cfg_attr(not(feature = "server"), derive(Debug, Clone, serde::Serialize, serde::Deserialize))]
pub struct FilterOption {
pub name: String,
#[cfg(feature = "server")]
#[schema(value_type = Option<Object>)]
pub default: Option<serde_json::Value>,
#[cfg(not(feature = "server"))]
pub default: Option<serde_json::Value>,
pub required: bool,
}