From 92e589699cc990e692bf2c4d64104a067b546f6b Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 13 Aug 2025 13:39:07 -0300 Subject: [PATCH] fix: resolve utoipa schema generation errors by removing unsupported description attributes and creating specific response types Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) --- src/modes/server/api/item.rs | 14 ++++----- src/modes/server/api/mod.rs | 6 ++++ src/modes/server/api/status.rs | 4 +-- src/modes/server/common.rs | 57 +++++++++++++++++++++++++++------- 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/modes/server/api/item.rs b/src/modes/server/api/item.rs index bc897b6..cde28e1 100644 --- a/src/modes/server/api/item.rs +++ b/src/modes/server/api/item.rs @@ -13,7 +13,7 @@ use anyhow::{Result, anyhow}; use crate::compression_engine::{CompressionType, get_compression_engine}; use crate::db; -use crate::modes::server::common::{AppState, ApiResponse, ItemInfo, ItemContentInfo, TagsQuery, ListItemsQuery, ItemQuery}; +use crate::modes::server::common::{AppState, ApiResponse, ItemInfo, ItemContentInfo, TagsQuery, ListItemsQuery, ItemQuery, ItemInfoListResponse, ItemInfoResponse, ItemContentInfoResponse, MetadataResponse}; use crate::common::is_binary::is_binary; #[utoipa::path( @@ -22,7 +22,7 @@ use crate::common::is_binary::is_binary; summary = "List stored items", description = "Retrieve a paginated list of stored items with their metadata and tags. Items can be filtered by tags and sorted by creation time. Each item includes comprehensive metadata extracted during storage such as file type, encoding, size, and custom tags for organization.", responses( - (status = 200, description = "Successfully retrieved paginated list of items with metadata and tags", body = ApiResponse>), + (status = 200, description = "Successfully retrieved paginated list of items with metadata and tags", body = ItemInfoListResponse), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 500, description = "Internal server error - Failed to retrieve items from database") ), @@ -127,7 +127,7 @@ pub async fn handle_list_items( summary = "Store new item", description = "Create a new item by uploading content. The content will be automatically compressed, analyzed for metadata (file type, encoding, etc.), and stored with a unique identifier. Binary detection is performed automatically, and various metadata plugins extract information like line counts, file types, and system information.", responses( - (status = 201, description = "Successfully created new item with generated metadata and unique ID", body = ApiResponse), + (status = 201, description = "Successfully created new item with generated metadata and unique ID", body = ItemInfoResponse), (status = 400, description = "Bad request - Invalid input data or malformed content"), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 500, description = "Internal server error - Failed to create item due to storage or processing error") @@ -213,7 +213,7 @@ pub async fn handle_delete_item( summary = "Get latest item with content", description = "Retrieve the most recently stored item including its content and metadata. If tags are specified, returns the latest item that matches ALL the given tags. For text content, the actual content is included in the response. For binary content, only metadata is returned unless allow_binary is true.", responses( - (status = 200, description = "Successfully retrieved latest item with content and metadata. Content is included if item is text-based or allow_binary is true.", body = ApiResponse), + (status = 200, description = "Successfully retrieved latest item with content and metadata. Content is included if item is text-based or allow_binary is true.", body = ItemContentInfoResponse), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 404, description = "Item not found - No items exist in the database or no items match the specified tag criteria"), (status = 500, description = "Internal server error - Failed to retrieve item content due to decompression or database error") @@ -279,7 +279,7 @@ pub async fn handle_get_item_latest( summary = "Get item with content", description = "Retrieve a specific item by its ID including both content and metadata. The content is automatically decompressed and returned as a string for text files. Binary files return only metadata unless allow_binary is explicitly set to true.", responses( - (status = 200, description = "Successfully retrieved item with content and metadata. Content is included if item is text-based or allow_binary is true.", body = ApiResponse), + (status = 200, description = "Successfully retrieved item with content and metadata. Content is included if item is text-based or allow_binary is true.", body = ItemContentInfoResponse), (status = 400, description = "Bad request - Invalid item ID (must be a positive integer)"), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 404, description = "Item not found - No item exists with the specified ID"), @@ -559,7 +559,7 @@ async fn get_item_raw_content(item: &db::Item, data_dir: &PathBuf, conn: &mut ru summary = "Get latest item metadata", description = "Retrieve comprehensive metadata for the most recently stored item. Metadata includes automatically extracted information such as file type, MIME type, encoding, line counts, file size, system information (user, hostname, etc.), and cryptographic hashes. If tags are specified, returns metadata for the latest item matching ALL the given tags.", responses( - (status = 200, description = "Successfully retrieved latest item metadata as key-value pairs including file type, encoding, size, and system information", body = ApiResponse>), + (status = 200, description = "Successfully retrieved latest item metadata as key-value pairs including file type, encoding, size, and system information", body = MetadataResponse), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 404, description = "Item not found - No items exist in the database or no items match the specified tag criteria"), (status = 500, description = "Internal server error - Failed to retrieve item metadata from database") @@ -621,7 +621,7 @@ pub async fn handle_get_item_latest_meta( summary = "Get item metadata", description = "Retrieve comprehensive metadata for a specific item by its ID. Metadata includes automatically extracted information such as file type, MIME type, encoding, line counts, file size, system information (user, hostname, process ID, etc.), cryptographic hashes (SHA256, MD5), and performance metrics (read time, read rate).", responses( - (status = 200, description = "Successfully retrieved item metadata as key-value pairs including file type, encoding, size, and system information", body = ApiResponse>), + (status = 200, description = "Successfully retrieved item metadata as key-value pairs including file type, encoding, size, and system information", body = MetadataResponse), (status = 400, description = "Bad request - Invalid item ID (must be a positive integer)"), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 404, description = "Item not found - No item exists with the specified ID"), diff --git a/src/modes/server/api/mod.rs b/src/modes/server/api/mod.rs index 2446d28..6b6712c 100644 --- a/src/modes/server/api/mod.rs +++ b/src/modes/server/api/mod.rs @@ -35,6 +35,12 @@ use utoipa_swagger_ui::SwaggerUi; schemas( crate::modes::server::common::ItemInfo, crate::modes::server::common::ItemContentInfo, + crate::modes::server::common::ItemInfoListResponse, + crate::modes::server::common::ItemInfoResponse, + crate::modes::server::common::ItemContentInfoResponse, + crate::modes::server::common::MetadataResponse, + crate::modes::server::common::StatusInfoResponse, + crate::common::status::StatusInfo, ) ), tags( diff --git a/src/modes/server/api/status.rs b/src/modes/server/api/status.rs index 390847e..5785131 100644 --- a/src/modes/server/api/status.rs +++ b/src/modes/server/api/status.rs @@ -4,7 +4,7 @@ use axum::{ response::Json, }; -use crate::modes::server::common::{AppState, ApiResponse}; +use crate::modes::server::common::{AppState, ApiResponse, StatusInfoResponse}; use crate::common::status::{generate_status_info, StatusInfo}; use crate::meta_plugin::MetaPluginType; @@ -14,7 +14,7 @@ use crate::meta_plugin::MetaPluginType; summary = "Get system status", description = "Retrieve comprehensive system status information including database configuration, data storage paths, supported compression engines, available metadata plugins, and system capabilities. This endpoint is useful for health checks and system diagnostics.", responses( - (status = 200, description = "Successfully retrieved complete system status including database path, data directory, supported plugins, and system information", body = ApiResponse), + (status = 200, description = "Successfully retrieved complete system status including database path, data directory, supported plugins, and system information", body = StatusInfoResponse), (status = 401, description = "Unauthorized - Invalid or missing authentication credentials"), (status = 500, description = "Internal server error - Failed to retrieve status information due to system error") ), diff --git a/src/modes/server/common.rs b/src/modes/server/common.rs index ce109e3..0122255 100644 --- a/src/modes/server/common.rs +++ b/src/modes/server/common.rs @@ -44,28 +44,61 @@ pub struct AppState { #[derive(Serialize, Deserialize, ToSchema)] #[schema(description = "Standard API response wrapper containing success status, data payload, and error information")] pub struct ApiResponse { - #[schema(description = "Indicates whether the API request was successful")] pub success: bool, - #[schema(description = "The response data payload, present when success is true")] pub data: Option, - #[schema(description = "Error message describing what went wrong, present when success is false")] + pub error: Option, +} + +// Specific response types for OpenAPI documentation +#[derive(Serialize, Deserialize, ToSchema)] +pub struct ItemInfoListResponse { + pub success: bool, + pub data: Option>, + pub error: Option, +} + +#[derive(Serialize, Deserialize, ToSchema)] +pub struct ItemInfoResponse { + pub success: bool, + pub data: Option, + pub error: Option, +} + +#[derive(Serialize, Deserialize, ToSchema)] +pub struct ItemContentInfoResponse { + pub success: bool, + pub data: Option, + pub error: Option, +} + +#[derive(Serialize, Deserialize, ToSchema)] +pub struct MetadataResponse { + pub success: bool, + pub data: Option>, + pub error: Option, +} + +#[derive(Serialize, Deserialize, ToSchema)] +pub struct StatusInfoResponse { + pub success: bool, + pub data: Option, pub error: Option, } #[derive(Serialize, Deserialize, ToSchema)] #[schema(description = "Complete information about a stored item including metadata and tags")] pub struct ItemInfo { - #[schema(description = "Unique identifier for the item", example = 42)] + #[schema(example = 42)] pub id: i64, - #[schema(description = "ISO 8601 timestamp when the item was created", example = "2023-12-01T15:30:45Z")] + #[schema(example = "2023-12-01T15:30:45Z")] pub ts: String, - #[schema(description = "Size of the original content in bytes before compression", example = 1024)] + #[schema(example = 1024)] pub size: Option, - #[schema(description = "Compression algorithm used to store the item", example = "gzip")] + #[schema(example = "gzip")] pub compression: String, - #[schema(description = "List of tags associated with this item for categorization", example = json!(["important", "work", "document"]))] + #[schema(example = json!(["important", "work", "document"]))] pub tags: Vec, - #[schema(description = "Key-value pairs of metadata extracted from the content (file type, encoding, etc.)", example = json!({"file.mime": "text/plain", "file.encoding": "utf-8", "line_count": "42"}))] + #[schema(example = json!({"file.mime": "text/plain", "file.encoding": "utf-8", "line_count": "42"}))] pub metadata: HashMap, } @@ -73,11 +106,11 @@ pub struct ItemInfo { #[schema(description = "Item information including content and metadata, with binary detection")] pub struct ItemContentInfo { #[serde(flatten)] - #[schema(description = "Key-value pairs of metadata extracted from the content", example = json!({"file.mime": "text/plain", "file.encoding": "utf-8", "line_count": "42"}))] + #[schema(example = json!({"file.mime": "text/plain", "file.encoding": "utf-8", "line_count": "42"}))] pub metadata: HashMap, - #[schema(description = "The actual content as a string if it's text-based and allow_binary is true for binary content, null otherwise", example = "Hello, world!\nThis is the content of the file.")] + #[schema(example = "Hello, world!\nThis is the content of the file.")] pub content: Option, - #[schema(description = "Whether the content is detected as binary data (images, executables, etc.)", example = false)] + #[schema(example = false)] pub binary: bool, }