feat: support parametersJsonSchema on function declarations
Some checks failed
Rust / build (pull_request) Has been cancelled

FunctionDeclaration.parameters becomes Option<Value>, and the new
parameters_json_schema field sends the schema as JSON Schema. Vertex
rejects many JSON Schema keywords in parameters ($schema, $ref/$defs,
const, type arrays) but accepts them in parametersJsonSchema. Both
fields are skipped when None, since Vertex rejects a declaration that
sets both.
This commit is contained in:
2026-10-18 08:34:56 +01:00
parent 69532ad110
commit 43cf7933fc
2 changed files with 38 additions and 3 deletions

View File

@@ -328,7 +328,14 @@ pub struct UsageMetadata {
pub struct FunctionDeclaration {
pub name: String,
pub description: String,
pub parameters: Value,
/// Parameters in Vertex's OpenAPI schema subset. Don't set both this and
/// `parameters_json_schema`: Vertex rejects the request.
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<Value>,
/// Parameters as a JSON Schema, which accepts keywords the OpenAPI subset doesn't
/// (`$schema`, `$ref`/`$defs`, `const`, type arrays, ...).
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters_json_schema: Option<Value>,
}
#[derive(Debug, Serialize, Deserialize)]
@@ -370,7 +377,34 @@ impl GenerateContentResponse {
#[cfg(test)]
mod tests {
use super::{GenerateContentResponse, GenerateContentResponseResult};
use serde_json::json;
use super::{FunctionDeclaration, GenerateContentResponse, GenerateContentResponseResult};
#[test]
fn serializes_function_declaration_with_only_the_set_schema_field() {
let schema = json!({"type": "object", "properties": {"q": {"type": "string"}}});
let json_schema = FunctionDeclaration {
name: "probe".to_string(),
description: "Probe".to_string(),
parameters: None,
parameters_json_schema: Some(schema.clone()),
};
assert_eq!(
serde_json::to_value(&json_schema).unwrap(),
json!({"name": "probe", "description": "Probe", "parametersJsonSchema": schema})
);
let openapi = FunctionDeclaration {
parameters: Some(schema.clone()),
parameters_json_schema: None,
..json_schema
};
assert_eq!(
serde_json::to_value(&openapi).unwrap(),
json!({"name": "probe", "description": "Probe", "parameters": schema})
);
}
#[test]
pub fn parses_empty_metadata_response() {