Crates.io | google-ai-schema-derive |
lib.rs | google-ai-schema-derive |
version | |
source | src |
created_at | 2025-05-07 20:16:18.127125+00 |
updated_at | 2025-05-07 20:16:18.127125+00 |
description | Type-safe schema generation for Google AI API interactions |
homepage | |
repository | https://github.com/veecore/google-ai-rs |
max_upload_size | |
id | 1664425 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Type-Safe Schema Generation for Gemini API Interactions
#[derive(AsSchema, Deserialize)]
#[schema(description = "Chemical element analysis")]
struct ElementAnalysis {
#[schema(description = "Element symbol")]
symbol: String,
#[schema(description = "Atomic mass with units")]
#[serde(rename = "atomicMass")]
mass: String,
}
Generates JSON schemas that exactly match Gemini's API requirements:
Automatic description
propagation
Google-specific type validations
Required field enforcement
#[derive(AsSchema, Serialize)]
#[schema(rename_all = "kebab-case")]
struct AnalysisRequest {
#[serde(rename = "inputData")] // Mirrored in schema
input_data: String,
}
Automatic alignment with Serde's rename
/skip
description
required
format
rename
ignore_serde
rename_all
nullable
type
as_schema
required
skip
#[derive(AsSchema, Deserialize)]
#[schema(rename_all = "camelCase")]
#[schema(description = "API response structure")]
struct GeminiResponse {
#[schema(description = "Confidence score 0-1")]
confidence: f64,
#[schema(
description = "MIME type validated content",
)]
content_type: String,
}
// Automatically generates compatible schema:
/*
{
"type": "object",
"title": "GeminiResponse",
"description": "API response structure",
"properties": {
"confidence": {
"type": "number",
"format": "float"
"description": "Confidence score 0-1"
},
"contentType": {
"type": "string",
"description": "MIME type validated content",
}
},
"required": ["confidence", "contentType"]
}
*/
#[derive(AsSchema)]
struct Invalid {
#[schema(description = "")] // Error: Empty description
field: String,
}
#[derive(AsSchema)]
struct Node {
children: Vec<Node>, // Error: Stack overflow
}
Part of the Google AI Rust Toolkit
"Finally makes Gemini schema authoring feel like native Rust" - Library Author