Validation¶
validate_document() checks a document against the epJSON schema: required
fields, value types, numeric ranges, enum choices, and reference integrity.
On-demand validation system for IDF documents.
Provides validation against EpJSON schema without requiring eager validation during parsing.
Severity
¶
ValidationError
dataclass
¶
Represents a validation issue.
Attributes:
| Name | Type | Description |
|---|---|---|
severity |
Severity
|
Issue severity (ERROR, WARNING, INFO) |
obj_type |
str
|
Object type where issue was found |
obj_name |
str
|
Object name where issue was found |
field |
str | None
|
Field name where issue was found (if applicable) |
message |
str
|
Human-readable description |
code |
str
|
Machine-readable error code |
Source code in src/idfkit/validation.py
ValidationResult
dataclass
¶
Result of document validation.
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
list[ValidationError]
|
List of validation errors |
warnings |
list[ValidationError]
|
List of validation warnings |
info |
list[ValidationError]
|
List of informational messages |
Source code in src/idfkit/validation.py
validate_document(doc, schema=None, check_references=True, check_required=True, check_types=True, check_ranges=True, object_types=None)
¶
Validate an IDF document against schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
IDFDocument
|
The document to validate |
required |
schema
|
EpJSONSchema | None
|
Schema to validate against (uses doc's schema if not provided) |
None
|
check_references
|
bool
|
Check reference integrity |
True
|
check_required
|
bool
|
Check required fields |
True
|
check_types
|
bool
|
Check field types |
True
|
check_ranges
|
bool
|
Check numeric ranges |
True
|
object_types
|
list[str] | None
|
Only validate these types (None = all) |
None
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with all issues found |
Examples:
Validate a model before running a simulation:
>>> from idfkit import new_document, validate_document
>>> model = new_document()
>>> model.add("Zone", "Perimeter_ZN_1")
Zone('Perimeter_ZN_1')
>>> result = validate_document(model)
>>> result.is_valid
True
>>> result.total_issues
0
Validate only material and construction definitions:
>>> result = validate_document(model, object_types=["Material", "Construction"])
>>> result.is_valid
True
Source code in src/idfkit/validation.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
validate_object(obj, schema, *, check_required=True, check_types=True, check_ranges=True, check_unknown=True)
¶
Validate a single object against schema.
This is a public API for validating individual objects, useful for checking objects at creation time with the validate=True option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
IDFObject
|
The IDFObject to validate |
required |
schema
|
EpJSONSchema
|
The EpJSON schema to validate against |
required |
check_required
|
bool
|
Check that required fields are present |
True
|
check_types
|
bool
|
Check that field values match expected types |
True
|
check_ranges
|
bool
|
Check that numeric values are within bounds |
True
|
check_unknown
|
bool
|
Check for unknown fields (not in schema) |
True
|
Returns:
| Type | Description |
|---|---|
list[ValidationError]
|
List of ValidationError objects describing any issues found |
Examples:
Check a newly created zone for schema violations:
>>> from idfkit import new_document, validate_object, get_schema, LATEST_VERSION
>>> model = new_document()
>>> zone = model.add("Zone", "Perimeter_ZN_1")
>>> errors = validate_object(zone, get_schema(LATEST_VERSION))
>>> len(errors)
0