MCPcopy Create free account
hub / github.com/PowerShell/DSC / validate_json

Function validate_json

lib/dsc-lib/src/dscresources/dscresource.rs:767–783  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

765///
766/// * `DscError` - The JSON is invalid
767pub 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
786fn is_same_array(expected: &Vec<Value>, actual: &Vec<Value>) -> bool {

Callers 2

validate_propertiesFunction · 0.85
validate_configFunction · 0.85

Calls 2

newFunction · 0.50
validateMethod · 0.45

Tested by

no test coverage detected