class Schematrix::Visitor
Visits a single schema subtree rooted at the given locator. When it finds a $ref it resolves the reference through the document store to decide how to represent it, and records edges to object schemas so their classes get generated. It never visits ref targets itself: the caller (see Compiler) decides when and whether to do that.
Nodes are consumed as instances of the metaschema model (Schematrix::Meta::Schema): compile converts raw store documents at its boundary, so reads are typed throughout. The $ref rewrite algebra (except/merge in resolve_reference) stays on raw String-keyed hashes: to_h dumps a node, the algebra merges, and from_h loads the result back (see present_slots).
Positions inside the document are threaded down as explicit path segments (leading empty segment for the document root, e.g. [“”, “properties”, “tags”]); every locator the visitor derives is a pure function of that path.
Constants
- IGNORED_KEYWORDS
-
Keywords without a codegen representation. They are ignored and logged once per document at debug level; the shapes stay open. Extend the list when the official metaschemas reveal more keywords without a rendering as Ruby types.
- MODEL_DEFAULTS
-
The model materializes the metaschema’s constructor defaults for keys a document left absent (properties: {}, required: [], …). to_h of a fresh instance is exactly that default set.
- SHAPE_SIBLINGS
-
Sibling keywords beside a $ref that change the compiled shape. When any of these appears next to a $ref the node applies both (2020-12), so it rewrites into its allOf-equivalent; everything else beside a $ref (annotations, scalar constraints without codegen) leaves the reference on the pure-ref path.
Attributes
Public Class Methods
Source
# File lib/schematrix/visitor.rb, line 236 def initialize( locator, store, closed_shapes: false, enums_classes: false, budget: CompilationBudget.new ) @budget = budget @locator = locator @store = store @closed_shapes = closed_shapes @enums_classes = enums_classes @objects = {} @edges = [] @branch_targets = Set.new @inline_targets = Set.new @ref_base = nil end
locator is the URI this visitor’s subtree is rooted at, and store the shared DocumentStore. closed_shapes treats an absent additionalProperties as false (closed classes) instead of the spec’s open default.
Public Instance Methods
Source
# File lib/schematrix/visitor.rb, line 258 def compile(node) # Seed the path from the locator's fragment: a visitor may start # at the document root ("/" seeds the nameless [""] site) or at # an interior locator the compiler discovered through an edge. # The store hands out raw parsed documents; the model boundary # conversion happens here. node = schema_model(node) if node.is_a?(Hash) fragment = @locator.fragment path = fragment == "/" ? [] : fragment.split("/", -1) path = path.map { |part| Pointer.unescape(part) } name = path.pop || "" # document root is nameless visit_schema(path, name, node, required: false) self end
Compiles the subtree rooted at this visitor’s locator. node is the raw parsed document node there: a Hash or a boolean. Returns self; read objects and edges afterwards.