Validate a JSON value against a JSON Schema. Returns Ok(()) on success, or a list of human-readable error strings.
(value: &Value, schema: &Value)
| 592 | /// Validate a JSON value against a JSON Schema. |
| 593 | /// Returns Ok(()) on success, or a list of human-readable error strings. |
| 594 | fn validate_against_schema(value: &Value, schema: &Value) -> Result<(), Vec<String>> { |
| 595 | // We do a basic recursive validation here. For production, consider using |
| 596 | // the `jsonschema` crate, but to avoid adding a heavy dependency we implement |
| 597 | // the subset of JSON Schema that matters for structured output. |
| 598 | let errors = basic_schema_validate(value, schema, ""); |
| 599 | if errors.is_empty() { |
| 600 | Ok(()) |
| 601 | } else { |
| 602 | Err(errors) |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /// Basic JSON Schema validator covering the most common constraints. |
| 607 | fn basic_schema_validate(value: &Value, schema: &Value, path: &str) -> Vec<String> { |