Skip to main content

validate

Function validate 

Source
pub fn validate(schema: &Value, value: &Value) -> ValidationResult
Expand description

Validates a JSON value against a JSON Schema.

§Arguments

  • schema - The JSON Schema to validate against
  • value - The value to validate

§Returns

Ok(()) if the value is valid, or Err(Vec<ValidationError>) with all validation errors found.

§Example

use fastmcp_protocol::schema::validate;
use serde_json::json;

let schema = json!({
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "age": { "type": "integer" }
    },
    "required": ["name"]
});

let valid = json!({ "name": "Alice", "age": 30 });
assert!(validate(&schema, &valid).is_ok());

let invalid = json!({ "age": 30 });
assert!(validate(&schema, &invalid).is_err());