Files
schema-tools/docs/ARCHITECTURE.md
T
zemion 0c47ec5105
Verify / verify (push) Canceled after 0s
Release Schema Tools 0.2.0
2026-09-02 08:04:49 +02:00

4.9 KiB

Architecture

Schema Tools is a static React/Vite application inside the shared Toolbox shell. src/schema/model.ts is the bounded trust boundary: it normalizes workspace names, parses JSON/YAML/XML, inventories language structures and references, performs eligible JSON instance validation, generates samples, and produces conservative comparison signals. React renders only text and native controls; no schema content is inserted as HTML.

JSON and YAML values are converted into an acyclic, prototype-safe JSON model with limits on source length, node count, depth, and collection width. JSON Schema instance validation is a CSP-safe interpreter selected for Draft 6, Draft 7, 2019-09, or 2020-12 behavior; it never generates or evaluates code. The focused subset covers boolean schemas, local $ref with JSON Pointer fragments, type, enum, const, numeric bounds and multipleOf, string lengths and patterns, object properties/required/additional properties/property names/pattern properties/dependencies, array items/tuples/contains/uniqueness and size, combiners, negation, and draft-appropriate conditionals. Validation has a 250,000-step and 1,000-diagnostic ceiling.

Every reference is classified before validation. Only fragments and relative filenames supplied in the current workspace are eligible. Root $id/legacy id values are deliberately ignored so relative references remain anchored to workspace filenames; nested identifier scopes, named anchors, dynamic/recursive references, and unevaluated keywords are outside the subset and cause a visible refusal. All participating JSON Schema files must use one declared draft. Formats and unknown extension keywords are annotations. pattern and patternProperties expressions and candidate strings are deduplicated and sent as one bounded batch to a fresh module worker; the caller terminates that worker after one second, including while one pathological RegExp.test is stalled. No partial result is accepted. Decimal arithmetic uses JavaScript numbers, so multipleOf applies a small floating-point tolerance.

OpenAPI JSON/YAML receives focused document, operation, response, reference, sample, and comparison logic. It does not run requests and does not claim full OpenAPI conformance. XML uses the browser's inert DOMParser only after rejecting DTD and entity declarations. Element counting and depth inspection use a linear sibling-pointer walk, avoiding repeated conversion of live DOM child collections. XSD, Relax NG XML syntax, and Schematron are checked for well-formedness and structurally inventoried. Schematron XPath and extensions are retained as text and never executed. XSD and Relax NG sample generation deliberately follows a bounded first branch and is labelled heuristic. XSD named-type shapes are inspected once and cached within one generation; Relax NG grammars and direct-root element patterns use the same renderer, and pattern-only wrappers do not consume generated nesting depth.

All sample paths share one budget implementation. It admits at most 50,000 monotonic generator work steps and 2,000 generated JSON values or XML elements across exactly 20 generated levels (the root is level one), accounts for at most 512 KiB of aggregate derived keys, names, attribute values, and content, caps each copied literal at 1,024 UTF-16 code units without splitting a surrogate pair, and rejects serialized output above 2 MiB. References and schema/pattern combiners do not consume generated depth, but every build, copy, reference, alternative, XML type inspection, and XML pattern visit consumes work before expansion. Per-generation caches ensure repeated JSON references, wide property collections, XML child collections, inline types, text, and name normalization are not rescanned without bound. The work counter is deliberately not restored when a failed heuristic alternative rolls back its node/text checkpoint, and generation is refused rather than returning an ambiguously partial result when a 50,001st work step is attempted. Node, depth, and text ceilings can instead omit bounded material with a visible notice. Repeated references consume node and text counters for every emitted occurrence. Duplicate or fallback-colliding derived XML attribute names are omitted with a notice to preserve well-formed output. A false JSON Schema reached through a selected local reference or mandatory allOf branch aborts generation; anyOf and oneOf skip definitely impossible boolean branches and use the first viable heuristic branch only while the complete attempt remains within budget.

The PWA uses only relative URLs, so the same build works standalone or below a nested portal route. Its service worker caches same-origin files from its own scope. The regex worker receives only the already-local expressions and candidate strings for one validation request and is then terminated. No storage database, server API, telemetry path, or remote schema resolver is used.