Expand description
Checking attribute values against a file’s schemas.
The rules follow upstream’s Validate in
src/ifcx-core/schema/schema-validation.ts of the ifcx_alpha draft, with
two differences: every failure is collected into a ValidationReport
instead of stopping at the first, and a few cases upstream leaves open are
decided here.
§Rules
Every attribute id on a node must name a schema; ids starting with
__internal are skipped, as upstream does. The value is then checked
against the schema’s IfcxValueDescription:
dataType | Accepted value |
|---|---|
Boolean | JSON true or false |
String, Reference | any JSON string; a reference is not resolved |
DateTime | any JSON string; the ISO 8601 format is not checked, as upstream |
Enum | a string equal to one of enumRestrictions.options |
Real | any JSON number |
Integer | a JSON number without a fractional part (3 and 3.0, not 3.5) |
Object | a JSON object with every non-optional key of objectRestrictions.values, each checked recursively; other keys are allowed |
Array | a JSON array whose length is within arrayRestrictions.min and max, each element checked against arrayRestrictions.value |
Blob | any value, unchecked |
| anything else | nothing; reported as FailureKind::UnknownDataType |
A value description with inherits is first checked against the value
description of every inherited schema, then against its own dataType.
A schema reached through several inherits paths (a diamond) is checked
once per value, so its failures are reported once. Inheritance is walked
without recursion, so chains of any length are checked.
optional only lets an object key be absent; a JSON null is never
accepted where a value is present. quantityKind is not checked.
§Where this is stricter or more defined than upstream
Integerrejects numbers with a fractional part; upstream accepts any number for bothIntegerandReal.Arraychecksminandmax; upstream ignores them.Objectrequires a JSON object; upstream’stypeof value === "object"also lets arrays andnullthrough.Blobaccepts any value. The draft does not say how a blob is encoded, and upstream rejects every blob as an unexpected data type.- An
EnumwithoutenumRestrictionsand an inheritance cycle are reported; upstream crashes or recurses without end. quantityKindis an annotation for numbers. Neither upstream nor this module checks it against the value or against the list of known kinds.
§Flattened and raw nodes
Upstream validates flattened nodes, after all opinions on a path have been
merged. validate_flat checks the output of flatten
or flatten_owned. IfcxFile::validate merges
the attributes of nodes sharing a path, later opinions winning, as
flattening does, before validating them; it does not copy any value.
validate_attributes takes any (path, attributes) pairs, and
validate_nodes raw nodes as they are.
§Imports
A file’s own schemas often do not describe its attributes: most
upstream examples take them from imported files.
LayerStack::validate checks a
layer stack built with its imports: the schemas of every layer, merged as
federate does, against the attributes of every layer, merged per path as
flattening does.
Structs§
- Validation
Failure - One attribute value that does not match its schema.
- Validation
Report - Every failure found in one validation run, in node and attribute order.
Enums§
- Failure
Kind - What is wrong with one attribute value.
- Json
Type - The JSON type of a value, for failure messages.
Constants§
- INTERNAL_
ATTRIBUTE_ PREFIX - Attribute ids with this prefix are not validated, as upstream.
Functions§
- validate_
attributes - Checks the attributes of
nodes, given as(path, attributes)pairs, againstschemasand collects every failure. - validate_
flat - Checks flattened nodes, as
flattenorflatten_ownedreturn them, againstschemas. This is what upstream validates: one merged node per path, in the flattened order. - validate_
nodes - Checks the attributes of each node as it is, without merging nodes that share a path. Nodes without attributes are skipped.