11. JSON Schema

The format is published as a JSON Schema, draft 2020-12 (PLT-4):

Esta página está em inglês; a tradução está a caminho.

The format is published as a JSON Schema, draft 2020-12 (PLT-4):

text
https://raw.githubusercontent.com/arthurafarias/vscode-extension-ui-designer/master/schemas/design-1.0.schema.json

It lives in the repository as schemas/design-1.0.schema.json, is generated from the same TypeScript definitions as the core’s types, and is tested against every fixture in CI (NFR-5). Every member has a description taken from this document. The $schema member of a design file points to it, so VS Code offers completion and validation when the file is opened as text.

The schema validates what is known and allows what is not: objects have additionalProperties: true, because unknown members are kept (PLT-4); wal entries with an unknown op match event.unknown.

$defs entry Describes
designFile The top-level object (the schema’s root refers to it)
tree, document, page 4.1, 4.2
fractionalIndex, nodeId, pageId, qualifiedId, timestamp, assetHash, treeHash, epochId Shared string formats (4.3, 5.5, 5.6, 8.2, 6.9, 5.4)
node Any node: type plus the shared properties (4.4), with if/then per type for the type-specific ones (4.6)
nodeInput A node in a node.create event: node plus required id
nodePatch A set of node.update or an override: every property optional and nullable
color, rgb, paint, effect, layoutGrid, exportSetting, reaction, variableAlias 4.7, 4.4
styledRun, vectorNetwork, componentPropertyDefinition 4.6.6, 4.6.4, 4.8
style, variableCollection, variable, library, flow, comment, version, asset, deletedComponent 4.9 – 4.16 (library.acceptedHash and version.treeHash are treeHash strings)
envelope seq, at, by, op, group, note (5.1). seq is a positive integer with no uniqueness constraint.
walBase The marker (5.4): seq, at, op, epoch, treeHash. The schema cannot check that there is only one or that the hash matches; readers do (9.4).
one entry per operation, named after it (event.node.create, event.node.update, …) 5.11
walEntry walBase, one of the known events by op, or event.unknown
event.unknown Any object with an op that is not a known operation

Merge semantics are marked with the annotation "x-merge": "merge" or "x-merge": "replace" on each object property (5.9).

Validating a file. With Python:

bash
python3 -m pip install jsonschema requests
python3 - login.design <<'EOF'
import json, sys, requests, jsonschema
doc = json.load(open(sys.argv[1], encoding="utf-8"))
schema = requests.get(doc["$schema"]).json()
jsonschema.Draft202012Validator(schema).validate(doc)
print("valid")
EOF

With Node and Ajv:

bash
npm install ajv ajv-formats
node -e '
const Ajv2020 = require("ajv/dist/2020").default, fs = require("fs");
const ajv = new Ajv2020({strict: false, allErrors: true}); require("ajv-formats")(ajv);
const validate = ajv.compile(JSON.parse(fs.readFileSync("schemas/design-1.0.schema.json", "utf8")));
const ok = validate(JSON.parse(fs.readFileSync("login.design", "utf8")));
console.log(ok ? "valid" : validate.errors);'

ud validate login.design runs the schema, then reads the file as the editor does and prints every warning of sections 6 and 9 and every missing asset. It exits with 0 when there is nothing to report, 1 when there are warnings, and 2 when the file cannot be read.