Skip to main content

validate_document

Function validate_document 

Source
pub fn validate_document(
    doc: &Document,
    form: &FormDefinition,
) -> Result<(), Vec<DocumentValidationError>>
Expand description

Validates a Document against its FormDefinition.

This function performs a comprehensive check, ensuring:

  1. The Document’s form_id matches the FormDefinition’s ID.
  2. All required fields as defined in the FormDefinition are present and not null in the Document.
  3. Data types for each field in the Document match the FieldType specified in the FormDefinition.
  4. Specific constraints (e.g., min/max for numbers, options for selects, ISO 8601 for dates) are met.

§Arguments

  • doc - A reference to the Document to be validated.
  • form - A reference to the FormDefinition to validate against.

§Returns

A Result which is Ok(()) if the document is valid, or Err(Vec<DocumentValidationError>) containing a list of all validation errors found.