Skip to main content

convert_const_to_enum

Function convert_const_to_enum 

Source
pub fn convert_const_to_enum(schema: &mut Value)
Expand description

Converts const values to single-element enum arrays.

Providers that do not support the const keyword can still enforce fixed values via a single-element enum.

ยงExample

use serde_json::json;
use adk_core::schema_utils::convert_const_to_enum;

let mut schema = json!({
    "type": "string",
    "const": "fixed_value"
});

convert_const_to_enum(&mut schema);
assert!(schema.get("const").is_none());
assert_eq!(schema["enum"], json!(["fixed_value"]));