Vex::Document
Inherits JSON::Serializable < Reference < Object
Constructors
Reads a VEX document from disk. Strips a leading UTF-8 BOM if present — Windows-emitted JSON often carries one, and Crystal's JSON parser is strict about leading whitespace/markers.
Combines multiple documents into one, preserving each statement's
source order across the inputs. Value-equal statements are deduplicated
— useful when feeds overlap on identical assertions. Per the spec,
statements are not collapsed by (product, vuln): the resulting document
carries the full history, and effective_statement selects the most
recent ruling at lookup time.
The result inherits no metadata from the inputs by default; pass
id:, author:, etc. to set them explicitly. When id: is empty,
an @id is generated canonically from the merged statements.
Class methods
Generates a deterministic IRI for a set of statements. The output is
stable across statement order so two callers assembling the same data
in different order receive the same @id — the property that lets
consumers de-duplicate documents.
The hash covers each statement's vulnerability name (and id+aliases if
present), status, justification, action_statement, and the recursive
set of product/subcomponent identifiers. Mutable metadata like
last_updated, status_notes, and statement-level timestamps is
excluded so equivalent updates don't churn the document ID.
Instance methods
Returns true if this reference is the same as other. Invokes same?.
Returns the effective products for a statement. Standalone OpenVEX has
no encapsulating document, so this is just the statement's own
products field — exposed as a helper for symmetry with
effective_timestamp_for and so callers don't have to remember the
inheritance semantics when wiring documents together.
Returns the most recent statement for the given product/vuln identifier pair. Compares timestamps with the document timestamp as fallback. Ties resolve to the last statement in source order — matching go-vex, which stable-sorts ascending then iterates from the end. This honors the conceptual model that newer statements (those appended later) override older ones when their timestamps cannot.
Returns the effective timestamp for a statement, following the spec's inheritance flow: a statement-level timestamp wins, otherwise the document-level timestamp is inherited.
Returns all statements that mention the given (product, vuln) pair, in
source order. Useful for audit trails — "show me the full history of
how this product was assessed against this CVE." For the single most
recent ruling, use effective_statement.
See Object#hash(hasher)
Convenience: merge another document into a new document, keeping this
one's identity (id, author, role, tooling). The receiver's statements
come first so source order reflects "I had these, then I learned
those." last_updated is bumped to now to signal the change.
Recomputes and sets @id from the current statements. Useful after
building a document via add_statement if you didn't supply an @id.
The new value is returned for chaining.
Returns validation errors for the document. The document is valid if every statement is valid and required document-level fields are present.
version defaults to 0 as an "unset" sentinel so we can permissively
parse documents that omit it. The spec requires version >= 1, so a
sentinel 0 is never serialized — emitting "version": 0 would produce
output the spec (and our own validate) rejects. The gap is still
surfaced through validate.
version defaults to 0 as an "unset" sentinel so we can permissively
parse documents that omit it. The spec requires version >= 1, so a
sentinel 0 is never serialized — emitting "version": 0 would produce
output the spec (and our own validate) rejects. The gap is still
surfaced through validate.
Returns non-fatal spec advisories — issues the spec marks as SHOULD rather than MUST. Currently covers:
@contextURLs that don't match the openvex.dev namespace- hash algorithms outside Appendix A
- identifier types outside Appendix B
A document with warnings is still
valid?true; tools that want a stricter posture can fail onwarnings.any?as their own policy.