Validate the JSON against the schema. # Arguments `source` - The source of the JSON `schema` - The schema to validate against `json` - The JSON to validate # Returns Nothing on success. # Errors `DscError` - The JSON is invalid
(source: &str, schema: &Value, json: &Value)
| 765 | /// |
| 766 | /// * `DscError` - The JSON is invalid |
| 767 | pub fn validate_json(source: &str, schema: &Value, json: &Value) -> Result<(), DscError> { |
| 768 | debug!("{}: {source}", t!("dscresources.dscresource.validatingSchema")); |
| 769 | trace!("JSON: {json}"); |
| 770 | trace!("Schema: {schema}"); |
| 771 | let compiled_schema = match Validator::new(schema) { |
| 772 | Ok(compiled_schema) => compiled_schema, |
| 773 | Err(err) => { |
| 774 | return Err(DscError::Validation(format!("{}: {err}", t!("dscresources.dscresource.failedToCompileSchema")))); |
| 775 | } |
| 776 | }; |
| 777 | |
| 778 | if let Err(err) = compiled_schema.validate(json) { |
| 779 | return Err(DscError::Validation(format!("{}: '{source}' {err}", t!("dscresources.dscresource.validationFailed")))); |
| 780 | } |
| 781 | |
| 782 | Ok(()) |
| 783 | } |
| 784 | |
| 785 | /// Compares two arrays independent of order |
| 786 | fn is_same_array(expected: &Vec<Value>, actual: &Vec<Value>) -> bool { |
no test coverage detected